41 lines
767 B
TypeScript
41 lines
767 B
TypeScript
import mongoose, { connect, PopulatedDoc, Document, Model } from "mongoose";
|
|
const { Schema, model } = mongoose;
|
|
import SequenceFactory from "mongoose-sequence";
|
|
import { hasMigrated } from "~/lib/dbconfig";
|
|
|
|
const AutoIncrement = SequenceFactory(mongoose);
|
|
|
|
export interface IBand {
|
|
_id: number;
|
|
name: string;
|
|
locked: boolean;
|
|
characters: string[];
|
|
}
|
|
|
|
const BandSchema = new mongoose.Schema<IBand>({
|
|
_id: {
|
|
type: Number,
|
|
},
|
|
name: {
|
|
type: String,
|
|
},
|
|
locked: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
characters: [
|
|
{
|
|
type: String,
|
|
},
|
|
],
|
|
});
|
|
|
|
hasMigrated &&
|
|
!mongoose.models.Band &&
|
|
BandSchema.plugin(AutoIncrement, { id: "band" });
|
|
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>(
|
|
"Band",
|
|
BandSchema,
|
|
"bands",
|
|
);
|