next/models/challenges/biffno.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ a8e113e969
refactor(db/models): remove model existence guards
this way, plugins are registered if `hasMigrated` is true. we've already enabled automatically overwriting models, therefore, the guard's condition will always be false
2023-12-29 16:36:26 -05:00

74 lines
1.2 KiB
TypeScript

import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
import { IUser } from "@models/user";
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "@dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IBiffno {
_id: number;
title: string;
description: string;
excerpt: string;
bands: number[];
tags: string[];
words: number;
genre: string;
cover: string;
year: number;
author: PopulatedDoc<IUser & Document>;
}
const biffnoschema = new mongoose.Schema<IBiffno>({
_id: {
type: Number,
},
title: {
type: String,
default: "",
},
description: {
type: String,
default: "",
},
excerpt: {
type: String,
default: "",
},
bands: [
{
type: Number,
ref: "Band",
},
],
tags: [
{
type: String,
},
],
words: {
type: Number,
default: 0,
},
genre: {
type: String,
},
cover: {
type: String,
default: "",
},
year: {
type: Number,
default: 0,
},
author: {
type: Number,
ref: "User",
},
});
hasMigrated &&
biffnoschema.plugin(AutoIncrement, { start_seq: 1, id: "bif_id" });
export const Biffno: Model<IBiffno> =
mongoose.models.Biffno || mongoose.model("Biffno", biffnoschema, "biffno");