refactor(api): rename imports and refactor error messages

This commit is contained in:
parent 08c49e4bdd
commit b000c6734a
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
3 changed files with 84 additions and 82 deletions

@ -1,3 +1,4 @@
import { messages } from "~/lib/server/constants";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier"; import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { canDelete } from "~/lib/server/middlewareButNotReally/storyPrivileges"; import { canDelete } from "~/lib/server/middlewareButNotReally/storyPrivileges";
import { Story } from "~/models/stories"; import { Story } from "~/models/stories";
@ -13,6 +14,6 @@ export default eventHandler(async (ev) => {
} }
throw createError({ throw createError({
statusCode: 403, statusCode: 403,
message: "Forbidden", message: messages[403],
}); });
}); });

@ -1,7 +1,7 @@
import { Readable } from "stream"; import { Readable } from "stream";
import { Document } from "mongoose"; import { Document } from "mongoose";
import { IStory, Story } from "~/models/stories"; import { IStory, Story } from "~/models/stories";
import { FormStory } from "~/lib/client/types/FormStory"; import { FormStory } from "~/lib/client/types/form/story";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier"; import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges"; import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
@ -12,6 +12,7 @@ import {
replaceOrUploadContent, replaceOrUploadContent,
} from "~/lib/server/storyHelpers"; } from "~/lib/server/storyHelpers";
import { countWords } from "~/lib/functions"; import { countWords } from "~/lib/functions";
import { messages } from "~/lib/server/constants";
export default eventHandler(async (ev) => { export default eventHandler(async (ev) => {
let os: let os:
@ -25,10 +26,10 @@ export default eventHandler(async (ev) => {
if (!canModify(ev, os)) { if (!canModify(ev, os)) {
throw createError({ throw createError({
statusCode: 403, statusCode: 403,
message: "Forbidden", message: messages[403],
}); });
} }
const body = await readBody<FormStory>(ev); const body: FormStory = await readBody<FormStory>(ev);
const update: Partial<IStory> = { const update: Partial<IStory> = {
title: body.title, title: body.title,
completed: body.completed, completed: body.completed,

@ -1,6 +1,6 @@
import { Readable } from "stream"; import { Readable } from "stream";
import san from "sanitize-html"; import san from "sanitize-html";
import { FormStory } from "~/lib/client/types/FormStory"; import { FormStory } from "~/lib/client/types/form/story";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { import {
getBucket, getBucket,