next/server/api/story/[id]/index.delete.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 088232f750
refactor(api & server/utils): refactor imports of db helpers
create an index file which exports the functions we need in one accessible place
2023-12-11 21:29:46 -05:00

20 lines
524 B
TypeScript

import { messages } from "~/lib/server/constants";
import { storyQuerier } from "~/lib/server/dbHelpers";
import { canDelete } from "~/lib/server/middlewareButNotReally/storyPrivileges";
import { Story } from "~/models/stories";
export default eventHandler(async (ev) => {
const tmpS = await storyQuerier(ev);
if (canDelete(ev, tmpS)) {
await Story.findByIdAndDelete(tmpS._id);
return {
success: true,
message: "story deleted",
};
}
throw createError({
statusCode: 403,
message: messages[403],
});
});