next/models/band.ts

39 lines
721 B
TypeScript
Raw Normal View History

import mongoose, { connect, Document, Model } from "mongoose";
2023-10-03 01:22:43 -04:00
const { Schema, model } = mongoose;
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "@dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IBand {
_id: number;
name: string;
locked: boolean;
2023-10-03 01:22:43 -04:00
characters: string[];
}
const BandSchema = new mongoose.Schema<IBand>({
_id: {
2023-10-03 01:22:43 -04:00
type: Number,
},
name: {
2023-10-03 01:22:43 -04:00
type: String,
},
locked: {
type: Boolean,
2023-10-03 01:22:43 -04:00
default: false,
},
2023-10-03 01:22:43 -04:00
characters: [
{
type: String,
},
],
});
hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" });
2023-10-03 01:22:43 -04:00
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>(
"Band",
BandSchema,
"bands",
);