2023-10-03 01:15:29 -04:00
|
|
|
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
|
|
|
|
import { IUser } from "~/models/user";
|
2023-09-25 19:26:13 -04:00
|
|
|
import SequenceFactory from "mongoose-sequence";
|
2023-10-03 01:15:29 -04:00
|
|
|
import { hasMigrated } from "~/lib/dbconfig";
|
2023-09-25 19:26:13 -04:00
|
|
|
|
|
|
|
const AutoIncrement = SequenceFactory(mongoose);
|
|
|
|
|
|
|
|
export interface IBiffno {
|
|
|
|
_id: number;
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
excerpt: string;
|
|
|
|
bands: number[];
|
|
|
|
tags: string[];
|
2023-10-03 01:15:29 -04:00
|
|
|
words: number;
|
2023-09-25 19:26:13 -04:00
|
|
|
genre: string;
|
|
|
|
cover: string;
|
|
|
|
year: number;
|
2023-10-03 01:15:29 -04:00
|
|
|
author: PopulatedDoc<IUser & Document>;
|
2023-09-25 19:26:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const biffnoschema = new mongoose.Schema<IBiffno>({
|
|
|
|
_id: {
|
2023-10-03 01:15:29 -04:00
|
|
|
type: Number,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: "",
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: "",
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
excerpt: {
|
|
|
|
type: String,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: "",
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
2023-10-03 01:15:29 -04:00
|
|
|
bands: [
|
|
|
|
{
|
|
|
|
type: Number,
|
|
|
|
ref: "Band",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
words: {
|
2023-09-25 19:26:13 -04:00
|
|
|
type: Number,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: 0,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
genre: {
|
2023-10-03 01:15:29 -04:00
|
|
|
type: String,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
cover: {
|
|
|
|
type: String,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: "",
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
year: {
|
|
|
|
type: Number,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: 0,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
author: {
|
|
|
|
type: Number,
|
2023-10-03 01:15:29 -04:00
|
|
|
ref: "User",
|
|
|
|
},
|
2023-09-25 19:26:13 -04:00
|
|
|
});
|
|
|
|
|
2023-12-06 21:28:51 -05:00
|
|
|
hasMigrated &&
|
|
|
|
!mongoose.models.Biffno &&
|
|
|
|
biffnoschema.plugin(AutoIncrement, { start_seq: 1, id: "bif_id" });
|
2023-10-03 01:15:29 -04:00
|
|
|
export const Biffno: Model<IBiffno> =
|
|
|
|
mongoose.models.Biffno || mongoose.model("Biffno", biffnoschema, "biffno");
|