refactor(db/models): add new story models
This commit is contained in:
parent
0f825c0e0c
commit
1db9bdec9c
65
models/stories/chapter.ts
Normal file
65
models/stories/chapter.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
|
||||
import { IBand } from "../band";
|
||||
export interface IChapter {
|
||||
title: string;
|
||||
summary: string;
|
||||
id?: number;
|
||||
// index: number;
|
||||
words?: number;
|
||||
notes: string;
|
||||
genre: string[];
|
||||
bands: PopulatedDoc<IBand & Document>[];
|
||||
characters: string[];
|
||||
relationships: string[][];
|
||||
nsfw: boolean;
|
||||
loggedInOnly: boolean;
|
||||
hidden: boolean;
|
||||
posted: Date;
|
||||
reviews: number
|
||||
}
|
||||
|
||||
export const Chapter = new mongoose.Schema<IChapter>({
|
||||
title: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
id: {
|
||||
type: Number
|
||||
},
|
||||
summary: {
|
||||
type: String
|
||||
},
|
||||
words: {
|
||||
type: Number
|
||||
},
|
||||
notes: {
|
||||
type: String
|
||||
},
|
||||
genre: [{
|
||||
type: String
|
||||
}],
|
||||
bands: [{
|
||||
type: Number,
|
||||
ref: "Band"
|
||||
}],
|
||||
reviews: {
|
||||
type: Number
|
||||
},
|
||||
characters: [{ type: String }],
|
||||
relationships: [{ type: String }],
|
||||
nsfw: {
|
||||
type: Boolean
|
||||
},
|
||||
loggedInOnly: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
hidden: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
posted: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
}
|
||||
})
|
96
models/stories/draft.ts
Normal file
96
models/stories/draft.ts
Normal file
@ -0,0 +1,96 @@
|
||||
import { hasMigrated } from "../../lib/dbconfig";
|
||||
import { IBand } from "../../models/band";
|
||||
import { IFicmas } from "../../models/challenges/ficmas";
|
||||
import { IChallenge } from "../../models/challenges/gen";
|
||||
import { IUser } from "../../models/user";
|
||||
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
|
||||
import SequenceFactory from "mongoose-sequence";
|
||||
|
||||
const AutoIncrement = SequenceFactory(mongoose);
|
||||
|
||||
export interface IDraft {
|
||||
_id?: number,
|
||||
title: string;
|
||||
chaptertitle: string;
|
||||
updatedAt: Date;
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
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>({
|
||||
title: {
|
||||
type: String
|
||||
},
|
||||
_id: {
|
||||
type: Number
|
||||
},
|
||||
chaptertitle: {
|
||||
type: String,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
},
|
||||
author: {
|
||||
type: Number,
|
||||
ref: "User"
|
||||
},
|
||||
notes: {
|
||||
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"})
|
||||
|
||||
export const Draft: Model<IDraft> = /* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts")
|
86
models/stories/index.ts
Normal file
86
models/stories/index.ts
Normal file
@ -0,0 +1,86 @@
|
||||
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
|
||||
import SequenceFactory from "mongoose-sequence";
|
||||
|
||||
const AutoIncrement = SequenceFactory(mongoose);
|
||||
|
||||
import { Chapter, IChapter } from "./chapter";
|
||||
import {IUser} from "../../models/user";
|
||||
import { Ficmas, IFicmas } from "../../models/challenges/ficmas";
|
||||
import { IChallenge, Challenge } from "../../models/challenges/gen";
|
||||
import { hasMigrated } from "../../lib/dbconfig";
|
||||
|
||||
export interface IStory extends Document {
|
||||
_id?: number;
|
||||
title: string;
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
chapters: IChapter[]
|
||||
recs: number;
|
||||
favs: number;
|
||||
reviews: number;
|
||||
views: number;
|
||||
completed: boolean;
|
||||
challenge: PopulatedDoc<IChallenge & Document> | null;
|
||||
ficmas: PopulatedDoc<IFicmas & Document> | null;
|
||||
downloads: number;
|
||||
lastUpdate: Date;
|
||||
posted: Date;
|
||||
}
|
||||
|
||||
const StorySchema = new mongoose.Schema<IStory>({
|
||||
_id: {
|
||||
type: Number
|
||||
},
|
||||
title: {
|
||||
type: String
|
||||
},
|
||||
author: {
|
||||
type: Number,
|
||||
ref: "User"
|
||||
},
|
||||
chapters: [Chapter],
|
||||
recs: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
favs: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
reviews: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
views: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
completed: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
challenge: {
|
||||
type: Number,
|
||||
ref: "Challenge",
|
||||
default: null
|
||||
},
|
||||
ficmas: {
|
||||
type: Number,
|
||||
ref: "Ficmas",
|
||||
default: null
|
||||
},
|
||||
downloads: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
lastUpdate: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
},
|
||||
posted: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
}
|
||||
})
|
||||
hasMigrated && Chapter.plugin(AutoIncrement, {id: "chapterid", inc_field: "id"})
|
||||
hasMigrated && StorySchema.plugin(AutoIncrement, {id: "storyid"})
|
||||
export const Story: Model<IStory> = /* mongoose.models.Story || */ mongoose.model("Story", StorySchema, "stories")
|
69
models/stories/review.ts
Normal file
69
models/stories/review.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
|
||||
import SequenceFactory from "mongoose-sequence";
|
||||
import { hasMigrated } from "~/lib/dbconfig";
|
||||
import { populate, populateSelected } from "~/lib/functions";
|
||||
import { IUser } from "~/models/user";
|
||||
|
||||
const AutoIncrement = SequenceFactory(mongoose);
|
||||
|
||||
export interface IReview {
|
||||
_id: number;
|
||||
text: string;
|
||||
leftOn: number;
|
||||
whichChapter: number;
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
datePosted: Date;
|
||||
replyingTo: PopulatedDoc<IReview & Document> | null;
|
||||
replies: PopulatedDoc<IReview & Document>[]
|
||||
}
|
||||
const CommentSchema = new mongoose.Schema<IReview>({
|
||||
_id: {
|
||||
type: Number
|
||||
},
|
||||
text: {
|
||||
type: String
|
||||
},
|
||||
leftOn: {
|
||||
type: Number
|
||||
},
|
||||
whichChapter: {
|
||||
type: Number
|
||||
},
|
||||
author: {
|
||||
type: Number,
|
||||
ref: "User"
|
||||
},
|
||||
datePosted: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
},
|
||||
replyingTo: {
|
||||
default: null,
|
||||
type: Number,
|
||||
ref: "Review"
|
||||
},
|
||||
replies: [{
|
||||
default: null,
|
||||
type: Number,
|
||||
ref: "Review"
|
||||
}]
|
||||
})
|
||||
|
||||
CommentSchema.virtual('story', {
|
||||
ref: 'Story',
|
||||
localField: 'leftOn',
|
||||
foreignField: '_id',
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
CommentSchema
|
||||
.pre('findOne', populate('replies'))
|
||||
.pre('find', populate('replies'))
|
||||
.pre("findOne", populate("commentAuthor"))
|
||||
.pre("find", populate("commentAuthor"))
|
||||
.pre("findOne", populateSelected("replyingTo", "-replies"))
|
||||
.pre("find", populateSelected("replyingTo", "-replies"));
|
||||
|
||||
hasMigrated && CommentSchema.plugin(AutoIncrement, {id: "reviews"})
|
||||
|
||||
export const Review: Model<IReview> = /* mongoose.models.Review || */ mongoose.model("Review", CommentSchema, "reviews")
|
Loading…
Reference in New Issue
Block a user