refactor(db/models): update populatedDoc types
- remove `& Document` qualifier - cast `T | number` to T with the `as` keyword
This commit is contained in:
parent
02ed969132
commit
1447960b1a
@ -2,6 +2,7 @@ import { SingleChapterResult } from "./types/slightlyDifferentStory";
|
||||
import { IChapter } from "@models/stories/chapter";
|
||||
import { IStory } from "@models/stories";
|
||||
import { messages } from "@server/constants";
|
||||
import { IUser } from "@models/user";
|
||||
|
||||
export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const { getSession } = useAuth();
|
||||
@ -33,8 +34,8 @@ export const storyEditMiddleware = defineNuxtRouteMiddleware(
|
||||
return showError({ statusCode: 404, message: messages[404] });
|
||||
}
|
||||
if (
|
||||
curU.value?.user?._id !== storyInfo.value?.author._id &&
|
||||
curU.value?.user?._id !== storyInfo.value?.coAuthor?._id
|
||||
curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id &&
|
||||
curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id
|
||||
) {
|
||||
return showError({
|
||||
statusCode: 403,
|
||||
|
@ -5,8 +5,9 @@ import { resolve } from "path";
|
||||
import { GridFSBucketReadStream } from "mongodb";
|
||||
import { stripHtml } from "string-strip-html";
|
||||
import { IStory } from "@models/stories";
|
||||
import { ficsHidden } from "./server/ficmas";
|
||||
import { ficsHidden } from "@server/ficmas";
|
||||
import { PreMiddlewareFunction, Query } from "mongoose";
|
||||
import { IFicmas } from "@models/challenges/ficmas";
|
||||
|
||||
// const { encode, decode } = iconv;
|
||||
|
||||
@ -36,11 +37,11 @@ export function populateSelected<T>(
|
||||
|
||||
export function isFicmasHidden(story: IStory): boolean {
|
||||
return (
|
||||
(story.ficmas.year == new Date().getFullYear() &&
|
||||
story.ficmas.anniversary &&
|
||||
((story.ficmas as IFicmas)?.year == new Date().getFullYear() &&
|
||||
(story.ficmas as IFicmas)?.anniversary &&
|
||||
new Date() < new Date(Date.parse("Aug 1 " + new Date().getFullYear()))) ||
|
||||
(story.ficmas.year == new Date().getFullYear() &&
|
||||
!story.ficmas.anniversary &&
|
||||
((story.ficmas as IFicmas)?.year == new Date().getFullYear() &&
|
||||
!(story.ficmas as IFicmas)?.anniversary &&
|
||||
ficsHidden(Date.now()))
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import { IStory } from "@models/stories";
|
||||
import { isFicmasHidden } from "@functions";
|
||||
import { IDraft } from "@models/stories/draft";
|
||||
import axios from "axios";
|
||||
import { IUser } from "@models/user";
|
||||
export function isIdNan(ev: H3Event<EventHandlerRequest>) {
|
||||
const id = parseInt(getRouterParam(ev, "id")!);
|
||||
if (Number.isNaN(id)) {
|
||||
@ -50,7 +51,7 @@ export async function storyCheck(
|
||||
}
|
||||
} else if (
|
||||
story.chapters[idx]?.hidden &&
|
||||
event.context.currentUser?._id !== story.author._id &&
|
||||
event.context.currentUser?._id !== (story.author as IUser)._id &&
|
||||
!event.context.currentUser?.profile.isAdmin
|
||||
) {
|
||||
ret.statusCode = 403;
|
||||
|
@ -2,11 +2,12 @@ import type { H3Event, EventHandlerRequest } from "h3";
|
||||
import { IStory } from "@models/stories";
|
||||
import { isLoggedIn } from "@server/middlewareButNotReally";
|
||||
import { IDraft } from "@models/stories/draft";
|
||||
import { IUser } from "@models/user";
|
||||
export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) {
|
||||
isLoggedIn(event);
|
||||
return (
|
||||
event.context.currentUser?.profile.isAdmin ||
|
||||
story.author._id === event.context.currentUser?._id
|
||||
(story.author as IUser)._id === event.context.currentUser?._id
|
||||
);
|
||||
}
|
||||
export function canDeleteDraft(
|
||||
@ -22,7 +23,7 @@ export function canModify(
|
||||
) {
|
||||
isLoggedIn(event);
|
||||
return (
|
||||
event.context.currentUser?._id === story.author._id ||
|
||||
story.coAuthor?._id === event.context.currentUser?._id
|
||||
event.context.currentUser?._id === (story.author as IUser)._id ||
|
||||
(story.coAuthor as IUser)?._id === event.context.currentUser?._id
|
||||
);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ export interface IBiffno {
|
||||
genre: string;
|
||||
cover: string;
|
||||
year: number;
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
author: PopulatedDoc<IUser>;
|
||||
}
|
||||
|
||||
const biffnoschema = new mongoose.Schema<IBiffno>({
|
||||
|
@ -16,10 +16,10 @@ const AutoIncrement = SequenceFactory(mongoose);
|
||||
export interface IFicmas {
|
||||
_id: number;
|
||||
kink: string;
|
||||
year: string;
|
||||
bands: PopulatedDoc<IBand & Document>[];
|
||||
year: number;
|
||||
bands: PopulatedDoc<IBand>[];
|
||||
relationship: string;
|
||||
wisher: PopulatedDoc<IUser & Document>;
|
||||
wisher: PopulatedDoc<IUser>;
|
||||
anniversary: boolean;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ export const FicmasSchema = new mongoose.Schema<IFicmas>({
|
||||
kink: {
|
||||
type: String,
|
||||
},
|
||||
year: { type: String },
|
||||
year: { type: Number },
|
||||
bands: [
|
||||
{
|
||||
type: Number,
|
||||
|
@ -10,10 +10,10 @@ import SequenceFactory from "mongoose-sequence";
|
||||
import { IPrivMsg } from "./privMsg";
|
||||
import { IUser } from "./user";
|
||||
export interface IInbox {
|
||||
owningUser: PopulatedDoc<IUser & Document>;
|
||||
saved: PopulatedDoc<IPrivMsg & Document>[];
|
||||
received: PopulatedDoc<IPrivMsg & Document>[];
|
||||
sent: PopulatedDoc<IPrivMsg & Document>[];
|
||||
owningUser: PopulatedDoc<IUser>;
|
||||
saved: PopulatedDoc<IPrivMsg>[];
|
||||
received: PopulatedDoc<IPrivMsg>[];
|
||||
sent: PopulatedDoc<IPrivMsg>[];
|
||||
}
|
||||
|
||||
const InboxSchema = new Schema<IInbox>({
|
||||
|
@ -7,8 +7,8 @@ const AutoIncrement = SequenceFactory(mongoose);
|
||||
|
||||
export interface IPrivMsg {
|
||||
_id: number;
|
||||
from: PopulatedDoc<IUser & Document>;
|
||||
to: PopulatedDoc<IUser & Document>;
|
||||
from: PopulatedDoc<IUser>;
|
||||
to: PopulatedDoc<IUser>;
|
||||
subject: string;
|
||||
content: string;
|
||||
sentAt: Date;
|
||||
|
@ -8,7 +8,7 @@ export interface IChapter {
|
||||
words?: number;
|
||||
notes: string;
|
||||
genre: string[];
|
||||
bands: PopulatedDoc<IBand & Document>[];
|
||||
bands: PopulatedDoc<IBand>[];
|
||||
characters: string[];
|
||||
relationships: string[][];
|
||||
nsfw: boolean;
|
||||
|
@ -12,19 +12,19 @@ import { hasMigrated } from "@dbconfig";
|
||||
export interface IStory {
|
||||
_id?: number;
|
||||
title: string;
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
author: PopulatedDoc<IUser>;
|
||||
chapters: IChapter[];
|
||||
recs: number;
|
||||
favs: number;
|
||||
reviews: number;
|
||||
views: number;
|
||||
completed: boolean;
|
||||
challenge: PopulatedDoc<IChallenge & Document> | null;
|
||||
ficmas: PopulatedDoc<IFicmas & Document> | null;
|
||||
challenge: PopulatedDoc<IChallenge> | null;
|
||||
ficmas: PopulatedDoc<IFicmas> | null;
|
||||
downloads: number;
|
||||
lastUpdate: Date;
|
||||
posted: Date;
|
||||
coAuthor: PopulatedDoc<IUser & Document> | null;
|
||||
coAuthor: PopulatedDoc<IUser> | null;
|
||||
}
|
||||
|
||||
const StorySchema = new mongoose.Schema<IStory>({
|
||||
|
@ -11,10 +11,10 @@ export interface IReview {
|
||||
text: string;
|
||||
leftOn: number;
|
||||
whichChapter: number;
|
||||
author: PopulatedDoc<IUser & Document>;
|
||||
author: PopulatedDoc<IUser>;
|
||||
datePosted: Date;
|
||||
replyingTo: PopulatedDoc<IReview & Document> | null;
|
||||
replies: PopulatedDoc<IReview & Document>[];
|
||||
replyingTo: PopulatedDoc<IReview> | null;
|
||||
replies: PopulatedDoc<IReview>[];
|
||||
}
|
||||
const CommentSchema = new mongoose.Schema<IReview>({
|
||||
_id: {
|
||||
|
@ -57,19 +57,19 @@ export interface IUser extends Document {
|
||||
wins: number;
|
||||
};
|
||||
favs: {
|
||||
authors: PopulatedDoc<IUser & Document>[];
|
||||
stories: PopulatedDoc<IStory & Document>[];
|
||||
authors: PopulatedDoc<IUser>[];
|
||||
stories: PopulatedDoc<IStory>[];
|
||||
};
|
||||
subscriptions: {
|
||||
authors: PopulatedDoc<IUser & Document>[];
|
||||
bands: PopulatedDoc<IBand & Document>[];
|
||||
stories: PopulatedDoc<IStory & Document>[];
|
||||
authors: PopulatedDoc<IUser>[];
|
||||
bands: PopulatedDoc<IBand>[];
|
||||
stories: PopulatedDoc<IStory>[];
|
||||
};
|
||||
//@ts-ignore SHUT UP
|
||||
hiddenAuthors: PopulatedDoc<IUser & Document>[];
|
||||
hiddenBands: PopulatedDoc<IBand & Document>[];
|
||||
hiddenAuthors: PopulatedDoc<IUser>[];
|
||||
hiddenBands: PopulatedDoc<IBand>[];
|
||||
//@ts-ignore SHUT UP
|
||||
blocked: PopulatedDoc<IUser & Document>[];
|
||||
blocked: PopulatedDoc<IUser>[];
|
||||
sessionId: string | null;
|
||||
banned: boolean;
|
||||
quickMenuConfig: QuickMenuItem[];
|
||||
|
@ -3,6 +3,7 @@ import { messages } from "@server/constants";
|
||||
import { log } from "@server/logger";
|
||||
import { isLoggedIn } from "@server/middlewareButNotReally";
|
||||
import { Review } from "@models/stories/review";
|
||||
import { IUser } from "@models/user";
|
||||
|
||||
export default eventHandler(async (ev) => {
|
||||
isLoggedIn(ev);
|
||||
@ -17,7 +18,7 @@ export default eventHandler(async (ev) => {
|
||||
log.silly(`${ev.context.currentUser!._id!} || ${c.author}`, {
|
||||
label: "what the fuck",
|
||||
});
|
||||
if (c?.author._id != ev.context.currentUser?._id) {
|
||||
if ((c?.author as IUser)?._id != ev.context.currentUser?._id) {
|
||||
throw createError({
|
||||
message: messages[403],
|
||||
statusCode: 403,
|
||||
@ -32,7 +33,7 @@ export default eventHandler(async (ev) => {
|
||||
return {
|
||||
success: true,
|
||||
data: await Review.findById(revid)
|
||||
.populate("author", "username _id")
|
||||
.populate("author", "username profile _id")
|
||||
.exec(),
|
||||
};
|
||||
});
|
||||
|
@ -3,6 +3,7 @@ import { messages } from "@server/constants";
|
||||
import { isLoggedIn } from "@server/middlewareButNotReally";
|
||||
import { Story } from "@models/stories";
|
||||
import { Review } from "@models/stories/review";
|
||||
import { IUser } from "@models/user";
|
||||
|
||||
export default eventHandler(async (ev) => {
|
||||
isLoggedIn(ev);
|
||||
@ -19,8 +20,10 @@ export default eventHandler(async (ev) => {
|
||||
});
|
||||
}
|
||||
if (
|
||||
replyingTo?.author.blocked.includes(ev.context.currentUser!._id) ||
|
||||
ev.context.currentUser!.blocked.includes(replyingTo?.author._id)
|
||||
(replyingTo?.author as IUser).blocked.includes(
|
||||
ev.context.currentUser!._id,
|
||||
) ||
|
||||
ev.context.currentUser!.blocked.includes((replyingTo?.author as IUser)._id)
|
||||
) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
|
@ -34,11 +34,11 @@ export default eventHandler(async (ev) => {
|
||||
"chapters.$.characters": cc.characters,
|
||||
"chapters.$.relationships": Array.from(new Set(cc.relationships)),
|
||||
"chapters.$.bands": cc.bands,
|
||||
"chapters.$.nsfw": !!cc.nsfw,
|
||||
"chapters.$.nsfw": cc.nsfw,
|
||||
"chapters.$.notes": cc.notes,
|
||||
"chapters.$.words": countWords(content),
|
||||
"chapters.$.genre": cc.genre,
|
||||
"chapters.$.loggedInOnly": !!cc.loggedInOnly,
|
||||
"chapters.$.loggedInOnly": cc.loggedInOnly,
|
||||
},
|
||||
},
|
||||
{ new: true },
|
||||
|
@ -2,6 +2,7 @@ import { storyQuerier } from "@server/dbHelpers";
|
||||
import { chapterTransformer } from "@server/dbHelpers";
|
||||
import { isLoggedIn } from "@server/middlewareButNotReally";
|
||||
import { messages } from "@server/constants";
|
||||
import { IUser } from "@models/user";
|
||||
|
||||
export default eventHandler(async (ev) => {
|
||||
isLoggedIn(ev);
|
||||
@ -9,7 +10,7 @@ export default eventHandler(async (ev) => {
|
||||
const hidden = s.chapters.some((a) => a.hidden);
|
||||
if (
|
||||
hidden &&
|
||||
ev.context.currentUser?._id !== s.author._id &&
|
||||
ev.context.currentUser?._id !== (s.author as IUser)._id &&
|
||||
!ev.context.currentUser?.profile.isAdmin
|
||||
) {
|
||||
throw createError({
|
||||
|
@ -2,6 +2,7 @@
|
||||
"extends": "../.nuxt/tsconfig.server.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"outDir": "../out"
|
||||
"outDir": "../out",
|
||||
"noImplicitAny": false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user