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";
|
||||
const {Schema, model} = mongoose
|
||||
import mongoose, { connect, PopulatedDoc, Document, Model } from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
import SequenceFactory from "mongoose-sequence";
|
||||
import { hasMigrated } from "../lib/dbconfig";
|
||||
import { hasMigrated } from "~/lib/dbconfig";
|
||||
|
||||
const AutoIncrement = SequenceFactory(mongoose);
|
||||
|
||||
@ -9,24 +9,30 @@ export interface IBand {
|
||||
_id: number;
|
||||
name: string;
|
||||
locked: boolean;
|
||||
characters: string[]
|
||||
characters: string[];
|
||||
}
|
||||
|
||||
const BandSchema = new mongoose.Schema<IBand>({
|
||||
_id: {
|
||||
type: Number
|
||||
type: Number,
|
||||
},
|
||||
name: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
locked: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
},
|
||||
characters: [{
|
||||
type: String
|
||||
}]
|
||||
})
|
||||
characters: [
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
hasMigrated && BandSchema.plugin(AutoIncrement, {id: "band"})
|
||||
export const Band: Model<IBand> = /* mongoose.models.Band || */ model<IBand>("Band", BandSchema, "bands")
|
||||
hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" });
|
||||
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 { hasMigrated } from "../lib/dbconfig";
|
||||
import { hasMigrated } from "~/lib/dbconfig";
|
||||
import { IUser } from "./user";
|
||||
|
||||
const AutoIncrement = SequenceFactory(mongoose);
|
||||
@ -16,40 +16,45 @@ export interface IPrivMsg {
|
||||
deletedBy: {
|
||||
sender: boolean;
|
||||
recipient: boolean;
|
||||
}
|
||||
};
|
||||
}
|
||||
const PMSchema = new mongoose.Schema<IPrivMsg>({
|
||||
_id: { type: Number},
|
||||
_id: { type: Number },
|
||||
from: {
|
||||
type: Number,
|
||||
ref: "User"
|
||||
ref: "User",
|
||||
},
|
||||
to: {
|
||||
type: Number,
|
||||
ref: "User"
|
||||
ref: "User",
|
||||
},
|
||||
subject: { type: String },
|
||||
content: { type: String },
|
||||
sentAt: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
default: new Date(),
|
||||
},
|
||||
read: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
},
|
||||
deletedBy: {
|
||||
sender: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
},
|
||||
recipient: {
|
||||
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",
|
||||
);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import mongoose, {connect, PopulatedDoc, Document} from "mongoose";
|
||||
const {Schema, model} = mongoose;
|
||||
import mongoose, { connect, PopulatedDoc, Document } from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
interface IAbstractQM {
|
||||
index: number;
|
||||
@ -11,7 +11,7 @@ interface IQuickMenuLink extends IAbstractQM {
|
||||
}
|
||||
|
||||
interface IQuickMenuDiv extends IAbstractQM {
|
||||
divider: boolean
|
||||
divider: boolean;
|
||||
}
|
||||
|
||||
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
|
||||
title: String,
|
||||
url: String,
|
||||
divider: Boolean
|
||||
})
|
||||
divider: Boolean,
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
|
||||
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
|
||||
|
||||
export enum Color {
|
||||
"orange" = "orange",
|
||||
@ -9,30 +9,35 @@ export enum Color {
|
||||
"blue" = "blue",
|
||||
"purple" = "purple",
|
||||
"red" = "red",
|
||||
"pink" = "pink"
|
||||
"pink" = "pink",
|
||||
}
|
||||
|
||||
export interface ISidebarItem {
|
||||
color: Color
|
||||
url: string
|
||||
linkTitle: string
|
||||
color: Color;
|
||||
url: string;
|
||||
linkTitle: string;
|
||||
index: number;
|
||||
}
|
||||
|
||||
const SISchema = new mongoose.Schema<ISidebarItem>({
|
||||
color: {
|
||||
type: String,
|
||||
enum: Object.values(Color)
|
||||
enum: Object.values(Color),
|
||||
},
|
||||
url: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
linkTitle: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
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",
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
|
||||
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
|
||||
import SequenceFactory from "mongoose-sequence";
|
||||
import { hasMigrated } from "~/lib/dbconfig";
|
||||
import { populate, populateSelected } from "~/lib/functions";
|
||||
@ -14,56 +14,62 @@ export interface IReview {
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
datePosted: Date;
|
||||
replyingTo: PopulatedDoc<IReview & Document> | null;
|
||||
replies: PopulatedDoc<IReview & Document>[]
|
||||
replies: PopulatedDoc<IReview & Document>[];
|
||||
}
|
||||
const CommentSchema = new mongoose.Schema<IReview>({
|
||||
_id: {
|
||||
type: Number
|
||||
type: Number,
|
||||
},
|
||||
text: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
leftOn: {
|
||||
type: Number
|
||||
type: Number,
|
||||
},
|
||||
whichChapter: {
|
||||
type: Number
|
||||
type: Number,
|
||||
},
|
||||
author: {
|
||||
type: Number,
|
||||
ref: "User"
|
||||
ref: "User",
|
||||
},
|
||||
datePosted: {
|
||||
type: Date,
|
||||
default: new Date()
|
||||
default: new Date(),
|
||||
},
|
||||
replyingTo: {
|
||||
default: null,
|
||||
type: Number,
|
||||
ref: "Review"
|
||||
ref: "Review",
|
||||
},
|
||||
replies: [{
|
||||
default: null,
|
||||
type: Number,
|
||||
ref: "Review"
|
||||
}]
|
||||
})
|
||||
replies: [
|
||||
{
|
||||
default: null,
|
||||
type: Number,
|
||||
ref: "Review",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
CommentSchema.virtual('story', {
|
||||
ref: 'Story',
|
||||
localField: 'leftOn',
|
||||
foreignField: '_id',
|
||||
CommentSchema.virtual("story", {
|
||||
ref: "Story",
|
||||
localField: "leftOn",
|
||||
foreignField: "_id",
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
CommentSchema
|
||||
.pre('findOne', populate('replies'))
|
||||
.pre('find', populate('replies'))
|
||||
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"})
|
||||
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