From 08c49e4bddc47055d1ef7fd3487cc8e08c3cbf66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Tue, 3 Oct 2023 01:22:43 -0400 Subject: [PATCH] style(db/models): format --- models/band.ts | 32 ++++++++++++++---------- models/privMsg.ts | 35 +++++++++++++++----------- models/quickMenu.ts | 10 ++++---- models/sidebarEntry.ts | 29 ++++++++++++--------- models/stories/review.ts | 54 ++++++++++++++++++++++------------------ 5 files changed, 91 insertions(+), 69 deletions(-) diff --git a/models/band.ts b/models/band.ts index e4d57ea..d6c3710 100644 --- a/models/band.ts +++ b/models/band.ts @@ -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({ _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 = /* mongoose.models.Band || */ model("Band", BandSchema, "bands") +hasMigrated && BandSchema.plugin(AutoIncrement, { id: "band" }); +export const Band: Model = /* mongoose.models.Band || */ model( + "Band", + BandSchema, + "bands", +); diff --git a/models/privMsg.ts b/models/privMsg.ts index 0f5cc88..11bb785 100644 --- a/models/privMsg.ts +++ b/models/privMsg.ts @@ -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({ - _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 = /* mongoose.models.PrivMsg || */ mongoose.model("PrivMsg", PMSchema, "private_messages") +export const PrivMsg: Model = + /* mongoose.models.PrivMsg || */ mongoose.model( + "PrivMsg", + PMSchema, + "private_messages", + ); diff --git a/models/quickMenu.ts b/models/quickMenu.ts index 0fecc7f..bf4f988 100644 --- a/models/quickMenu.ts +++ b/models/quickMenu.ts @@ -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({ // @ts-ignore SHUT UP BITCH I KNOW WHAT I'M DOING title: String, url: String, - divider: Boolean -}) + divider: Boolean, +}); diff --git a/models/sidebarEntry.ts b/models/sidebarEntry.ts index 92d70b9..de2fb32 100644 --- a/models/sidebarEntry.ts +++ b/models/sidebarEntry.ts @@ -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({ 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 = /* mongoose.models.SidebarItem || */ mongoose.model("SidebarItem", SISchema, "sidebar") +export const SidebarItem: Model = + /* mongoose.models.SidebarItem || */ mongoose.model( + "SidebarItem", + SISchema, + "sidebar", + ); diff --git a/models/stories/review.ts b/models/stories/review.ts index 01496f8..5760205 100644 --- a/models/stories/review.ts +++ b/models/stories/review.ts @@ -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; datePosted: Date; replyingTo: PopulatedDoc | null; - replies: PopulatedDoc[] + replies: PopulatedDoc[]; } const CommentSchema = new mongoose.Schema({ _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 = /* mongoose.models.Review || */ mongoose.model("Review", CommentSchema, "reviews") +export const Review: Model = + /* mongoose.models.Review || */ mongoose.model( + "Review", + CommentSchema, + "reviews", + );