next/models/band.ts

39 lines
740 B
TypeScript
Raw Normal View History

2023-10-03 01:22:43 -04:00
import mongoose, { connect, PopulatedDoc, Document, Model } from "mongoose";
const { Schema, model } = mongoose;
import SequenceFactory from "mongoose-sequence";
2023-10-03 01:22:43 -04:00
import { hasMigrated } from "~/lib/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-10-03 01:22:43 -04:00
hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" });
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>(
"Band",
BandSchema,
"bands",
);