next/server/api/story/[id]/index.delete.ts

20 lines
508 B
TypeScript

import { messages } from "@server/constants";
import { storyQuerier } from "@server/dbHelpers";
import { canDelete } from "@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],
});
});