style(db/models): format
This commit is contained in:
parent
218bd5f565
commit
08c49e4bdd
@ -1,7 +1,7 @@
|
|||||||
import mongoose, { connect, PopulatedDoc, Document, Model } from "mongoose";
|
import mongoose, { connect, PopulatedDoc, Document, Model } from "mongoose";
|
||||||
const {Schema, model} = mongoose
|
const { Schema, model } = mongoose;
|
||||||
import SequenceFactory from "mongoose-sequence";
|
import SequenceFactory from "mongoose-sequence";
|
||||||
import { hasMigrated } from "../lib/dbconfig";
|
import { hasMigrated } from "~/lib/dbconfig";
|
||||||
|
|
||||||
const AutoIncrement = SequenceFactory(mongoose);
|
const AutoIncrement = SequenceFactory(mongoose);
|
||||||
|
|
||||||
@ -9,24 +9,30 @@ export interface IBand {
|
|||||||
_id: number;
|
_id: number;
|
||||||
name: string;
|
name: string;
|
||||||
locked: boolean;
|
locked: boolean;
|
||||||
characters: string[]
|
characters: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const BandSchema = new mongoose.Schema<IBand>({
|
const BandSchema = new mongoose.Schema<IBand>({
|
||||||
_id: {
|
_id: {
|
||||||
type: Number
|
type: Number,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
locked: {
|
locked: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
characters: [{
|
characters: [
|
||||||
type: String
|
{
|
||||||
}]
|
type: String,
|
||||||
})
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
hasMigrated && BandSchema.plugin(AutoIncrement, {id: "band"})
|
hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" });
|
||||||
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>("Band", BandSchema, "bands")
|
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>(
|
||||||
|
"Band",
|
||||||
|
BandSchema,
|
||||||
|
"bands",
|
||||||
|
);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
|
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
|
||||||
import SequenceFactory from "mongoose-sequence";
|
import SequenceFactory from "mongoose-sequence";
|
||||||
import { hasMigrated } from "../lib/dbconfig";
|
import { hasMigrated } from "~/lib/dbconfig";
|
||||||
import { IUser } from "./user";
|
import { IUser } from "./user";
|
||||||
|
|
||||||
const AutoIncrement = SequenceFactory(mongoose);
|
const AutoIncrement = SequenceFactory(mongoose);
|
||||||
@ -16,40 +16,45 @@ export interface IPrivMsg {
|
|||||||
deletedBy: {
|
deletedBy: {
|
||||||
sender: boolean;
|
sender: boolean;
|
||||||
recipient: boolean;
|
recipient: boolean;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
const PMSchema = new mongoose.Schema<IPrivMsg>({
|
const PMSchema = new mongoose.Schema<IPrivMsg>({
|
||||||
_id: { type: Number },
|
_id: { type: Number },
|
||||||
from: {
|
from: {
|
||||||
type: Number,
|
type: Number,
|
||||||
ref: "User"
|
ref: "User",
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
type: Number,
|
type: Number,
|
||||||
ref: "User"
|
ref: "User",
|
||||||
},
|
},
|
||||||
subject: { type: String },
|
subject: { type: String },
|
||||||
content: { type: String },
|
content: { type: String },
|
||||||
sentAt: {
|
sentAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: new Date()
|
default: new Date(),
|
||||||
},
|
},
|
||||||
read: {
|
read: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
deletedBy: {
|
deletedBy: {
|
||||||
sender: {
|
sender: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
recipient: {
|
recipient: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
hasMigrated && PMSchema.plugin(AutoIncrement, {id: "private_message"})
|
hasMigrated && PMSchema.plugin(AutoIncrement, { id: "private_message" });
|
||||||
|
|
||||||
export const PrivMsg: Model<IPrivMsg> = /* mongoose.models.PrivMsg || */ mongoose.model("PrivMsg", PMSchema, "private_messages")
|
export const PrivMsg: Model<IPrivMsg> =
|
||||||
|
/* mongoose.models.PrivMsg || */ mongoose.model(
|
||||||
|
"PrivMsg",
|
||||||
|
PMSchema,
|
||||||
|
"private_messages",
|
||||||
|
);
|
||||||
|
@ -11,7 +11,7 @@ interface IQuickMenuLink extends IAbstractQM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IQuickMenuDiv extends IAbstractQM {
|
interface IQuickMenuDiv extends IAbstractQM {
|
||||||
divider: boolean
|
divider: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type QuickMenuItem = IQuickMenuDiv | IQuickMenuLink;
|
export type QuickMenuItem = IQuickMenuDiv | IQuickMenuLink;
|
||||||
@ -21,5 +21,5 @@ export const QuickMenuSchema = new Schema<QuickMenuItem>({
|
|||||||
// @ts-ignore SHUT UP BITCH I KNOW WHAT I'M DOING
|
// @ts-ignore SHUT UP BITCH I KNOW WHAT I'M DOING
|
||||||
title: String,
|
title: String,
|
||||||
url: String,
|
url: String,
|
||||||
divider: Boolean
|
divider: Boolean,
|
||||||
})
|
});
|
||||||
|
@ -9,30 +9,35 @@ export enum Color {
|
|||||||
"blue" = "blue",
|
"blue" = "blue",
|
||||||
"purple" = "purple",
|
"purple" = "purple",
|
||||||
"red" = "red",
|
"red" = "red",
|
||||||
"pink" = "pink"
|
"pink" = "pink",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISidebarItem {
|
export interface ISidebarItem {
|
||||||
color: Color
|
color: Color;
|
||||||
url: string
|
url: string;
|
||||||
linkTitle: string
|
linkTitle: string;
|
||||||
index: number;
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SISchema = new mongoose.Schema<ISidebarItem>({
|
const SISchema = new mongoose.Schema<ISidebarItem>({
|
||||||
color: {
|
color: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: Object.values(Color)
|
enum: Object.values(Color),
|
||||||
},
|
},
|
||||||
url: {
|
url: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
linkTitle: {
|
linkTitle: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
index: {
|
index: {
|
||||||
type: Number
|
type: Number,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
export const SidebarItem: Model<ISidebarItem> = /* mongoose.models.SidebarItem || */ mongoose.model("SidebarItem", SISchema, "sidebar")
|
export const SidebarItem: Model<ISidebarItem> =
|
||||||
|
/* mongoose.models.SidebarItem || */ mongoose.model(
|
||||||
|
"SidebarItem",
|
||||||
|
SISchema,
|
||||||
|
"sidebar",
|
||||||
|
);
|
||||||
|
@ -14,56 +14,62 @@ export interface IReview {
|
|||||||
author: PopulatedDoc<IUser & Document>;
|
author: PopulatedDoc<IUser & Document>;
|
||||||
datePosted: Date;
|
datePosted: Date;
|
||||||
replyingTo: PopulatedDoc<IReview & Document> | null;
|
replyingTo: PopulatedDoc<IReview & Document> | null;
|
||||||
replies: PopulatedDoc<IReview & Document>[]
|
replies: PopulatedDoc<IReview & Document>[];
|
||||||
}
|
}
|
||||||
const CommentSchema = new mongoose.Schema<IReview>({
|
const CommentSchema = new mongoose.Schema<IReview>({
|
||||||
_id: {
|
_id: {
|
||||||
type: Number
|
type: Number,
|
||||||
},
|
},
|
||||||
text: {
|
text: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
leftOn: {
|
leftOn: {
|
||||||
type: Number
|
type: Number,
|
||||||
},
|
},
|
||||||
whichChapter: {
|
whichChapter: {
|
||||||
type: Number
|
type: Number,
|
||||||
},
|
},
|
||||||
author: {
|
author: {
|
||||||
type: Number,
|
type: Number,
|
||||||
ref: "User"
|
ref: "User",
|
||||||
},
|
},
|
||||||
datePosted: {
|
datePosted: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: new Date()
|
default: new Date(),
|
||||||
},
|
},
|
||||||
replyingTo: {
|
replyingTo: {
|
||||||
default: null,
|
default: null,
|
||||||
type: Number,
|
type: Number,
|
||||||
ref: "Review"
|
ref: "Review",
|
||||||
},
|
},
|
||||||
replies: [{
|
replies: [
|
||||||
|
{
|
||||||
default: null,
|
default: null,
|
||||||
type: Number,
|
type: Number,
|
||||||
ref: "Review"
|
ref: "Review",
|
||||||
}]
|
},
|
||||||
})
|
],
|
||||||
|
});
|
||||||
|
|
||||||
CommentSchema.virtual('story', {
|
CommentSchema.virtual("story", {
|
||||||
ref: 'Story',
|
ref: "Story",
|
||||||
localField: 'leftOn',
|
localField: "leftOn",
|
||||||
foreignField: '_id',
|
foreignField: "_id",
|
||||||
justOne: true,
|
justOne: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
CommentSchema
|
CommentSchema.pre("findOne", populate("replies"))
|
||||||
.pre('findOne', populate('replies'))
|
.pre("find", populate("replies"))
|
||||||
.pre('find', populate('replies'))
|
|
||||||
.pre("findOne", populate("commentAuthor"))
|
.pre("findOne", populate("commentAuthor"))
|
||||||
.pre("find", populate("commentAuthor"))
|
.pre("find", populate("commentAuthor"))
|
||||||
.pre("findOne", populateSelected("replyingTo", "-replies"))
|
.pre("findOne", populateSelected("replyingTo", "-replies"))
|
||||||
.pre("find", populateSelected("replyingTo", "-replies"));
|
.pre("find", populateSelected("replyingTo", "-replies"));
|
||||||
|
|
||||||
hasMigrated && CommentSchema.plugin(AutoIncrement, {id: "reviews"})
|
hasMigrated && CommentSchema.plugin(AutoIncrement, { id: "reviews" });
|
||||||
|
|
||||||
export const Review: Model<IReview> = /* mongoose.models.Review || */ mongoose.model("Review", CommentSchema, "reviews")
|
export const Review: Model<IReview> =
|
||||||
|
/* mongoose.models.Review || */ mongoose.model(
|
||||||
|
"Review",
|
||||||
|
CommentSchema,
|
||||||
|
"reviews",
|
||||||
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user