refactor(api/utils): replace repetitive "forbidden" and "unauthorized" literals with constant references
This commit is contained in:
parent
8070e8c555
commit
1059b560e6
@ -1,9 +1,10 @@
|
||||
import { H3Event, EventHandlerRequest } from "h3";
|
||||
import { messages } from "../constants";
|
||||
export default function (ev: H3Event<EventHandlerRequest>) {
|
||||
if (!ev.context.currentUser) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
statusMessage: "Authentication required",
|
||||
statusMessage: messages[401],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import type { H3Event, EventHandlerRequest } from "h3";
|
||||
import type { Document } from "mongoose";
|
||||
import { isFicmasHidden } from "~/lib/functions";
|
||||
import { IStory } from "~/models/stories";
|
||||
import { messages } from "../constants";
|
||||
export default async function (
|
||||
event: H3Event<EventHandlerRequest>,
|
||||
story: IStory,
|
||||
@ -18,11 +19,11 @@ export default async function (
|
||||
}
|
||||
if (
|
||||
story.chapters[num]?.hidden ||
|
||||
(event.context.currentUser._id !== story.author._id &&
|
||||
!event.context.currentUser.isAdmin)
|
||||
(event.context.currentUser?._id !== story.author._id &&
|
||||
!event.context.currentUser?.profile.isAdmin)
|
||||
) {
|
||||
ret.statusCode = 403;
|
||||
ret.message = "Forbidden";
|
||||
ret.message = messages[403];
|
||||
}
|
||||
return !!Object.keys(ret).length ? ret : null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user