refactor(db/models): change draft type to story type with omitted fields

This commit is contained in:
parent 9fe4d0c979
commit ad8be9d7fa
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -1,96 +1,42 @@
import { hasMigrated } from "../../lib/dbconfig"; import { IStory } from ".";
import { IBand } from "../../models/band"; import { hasMigrated } from "~/lib/dbconfig";
import { IFicmas } from "../../models/challenges/ficmas"; import { IBand } from "~/models/band";
import { IChallenge } from "../../models/challenges/gen"; import { IFicmas } from "~/models/challenges/ficmas";
import { IUser } from "../../models/user"; import { IChallenge } from "~/models/challenges/gen";
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose"; import { IUser } from "~/models/user";
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
import SequenceFactory from "mongoose-sequence"; import SequenceFactory from "mongoose-sequence";
import { Chapter } from "./chapter";
const AutoIncrement = SequenceFactory(mongoose); const AutoIncrement = SequenceFactory(mongoose);
export interface IDraft { export type IDraft = Omit<
_id?: number, IStory,
title: string; "recs" | "favs" | "reviews" | "views" | "downloads" | "posted"
chaptertitle: string; >;
updatedAt: Date;
author: PopulatedDoc<IUser & Document>; // const Cha
notes: string;
genre: string[];
bands: PopulatedDoc<IBand & Document>[];
characters: string[];
relationships: string[];
summary: string;
nsfw: boolean;
hidden: boolean;
loggedInOnly: boolean;
oneshot: boolean;
challenge: PopulatedDoc<IChallenge & Document>;
ficmas: PopulatedDoc<IFicmas & Document>;
}
const DraftSchema = new Schema<IDraft>({ const DraftSchema = new Schema<IDraft>({
title: { title: {
type: String
},
_id: {
type: Number
},
chaptertitle: {
type: String, type: String,
}, },
updatedAt: { _id: {
type: Date, type: Number,
default: new Date() },
coAuthor: {
type: Number,
ref: "User",
default: null,
}, },
author: { author: {
type: Number, type: Number,
ref: "User" ref: "User",
}, },
notes: { chapters: [Chapter],
type: String });
},
genre: [{
type: String
}],
bands: [{
type: Number,
ref: "Band"
}],
characters: [{
type: String
}],
relationships: [{
type: String
}],
nsfw: {
type: Boolean
},
summary: {
type: String
},
hidden: {
type: Boolean,
default: false
},
loggedInOnly: {
type: Boolean
},
oneshot: {
type: Boolean,
default: false
},
challenge: {
type: Number,
ref: "Challenge",
default: null
},
ficmas: {
type: Number,
ref: "Ficmas",
default: null
}
})
hasMigrated && DraftSchema.plugin(AutoIncrement, {id: "drafts"}) hasMigrated && DraftSchema.plugin(AutoIncrement, { id: "drafts" });
export const Draft: Model<IDraft> = /* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts") export const Draft: Model<IDraft> =
/* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");