next/models/band.ts

35 lines
721 B
TypeScript
Raw Normal View History

2023-12-29 20:11:07 -05:00
import mongoose, { 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,
},
],
});
2023-12-29 20:11:07 -05:00
hasMigrated && !mongoose.models.Band && BandSchema.plugin(AutoIncrement, { id: "band" });
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>("Band", BandSchema, "bands");