2023-10-03 01:24:06 -04:00
|
|
|
import { messages } from "~/lib/server/constants";
|
2023-10-02 15:44:55 -04:00
|
|
|
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
|
|
|
|
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,
|
2023-10-03 01:24:06 -04:00
|
|
|
message: messages[403],
|
2023-10-02 15:44:55 -04:00
|
|
|
});
|
|
|
|
});
|