next/models/challenges/biffno.ts

72 lines
1.2 KiB
TypeScript

import mongoose, { PopulatedDoc, 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>;
}
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 && !mongoose.models.Biffno && biffnoschema.plugin(AutoIncrement, { start_seq: 1, id: "bif_id" });
export const Biffno: Model<IBiffno> = mongoose.models.Biffno || mongoose.model("Biffno", biffnoschema, "biffno");