2023-10-02 21:43:24 -04:00
|
|
|
import san from "sanitize-html";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { storyQuerier } from "@server/dbHelpers";
|
2023-12-29 16:32:32 -05:00
|
|
|
import { isLoggedIn } from "@server/middlewareButNotReally";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { Story } from "@models/stories";
|
|
|
|
import { Review } from "@models/stories/review";
|
2023-10-02 21:43:24 -04:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isLoggedIn(ev);
|
|
|
|
let body = await readBody(ev);
|
|
|
|
let parent = await storyQuerier(ev);
|
|
|
|
let newReview = new Review({
|
|
|
|
text: san(body.review),
|
|
|
|
leftOn: parent._id,
|
|
|
|
author: ev.context.currentUser!._id,
|
|
|
|
replyingTo: null,
|
|
|
|
replies: [],
|
|
|
|
datePosted: new Date(),
|
|
|
|
});
|
|
|
|
await newReview.save();
|
|
|
|
parent.reviews += 1;
|
|
|
|
await parent.save();
|
|
|
|
// TODO: emails lol
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
data: newReview.toObject(),
|
|
|
|
};
|
|
|
|
});
|