2023-10-03 00:21:14 -04:00
|
|
|
import san from "sanitize-html";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { messages } from "@server/constants";
|
|
|
|
import { log } from "@server/logger";
|
2023-12-29 16:32:32 -05:00
|
|
|
import { isLoggedIn } from "@server/middlewareButNotReally";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { Review } from "@models/stories/review";
|
2023-10-03 00:21:14 -04:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isLoggedIn(ev);
|
|
|
|
const revid = parseInt(getRouterParam(ev, "revid")!);
|
|
|
|
let c = await Review.findById(revid);
|
|
|
|
if (!c) {
|
|
|
|
throw createError({
|
|
|
|
statusCode: 404,
|
|
|
|
message: messages[404],
|
|
|
|
});
|
|
|
|
}
|
2023-12-06 21:48:29 -05:00
|
|
|
log.silly(`${ev.context.currentUser!._id!} || ${c.author}`, {
|
|
|
|
label: "what the fuck",
|
|
|
|
});
|
|
|
|
if (c?.author._id != ev.context.currentUser?._id) {
|
2023-10-03 00:21:14 -04:00
|
|
|
throw createError({
|
|
|
|
message: messages[403],
|
|
|
|
statusCode: 403,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const body = await readBody(ev);
|
|
|
|
await Review.findByIdAndUpdate(revid, {
|
|
|
|
$set: {
|
|
|
|
text: san(body.content),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
data: await Review.findById(revid)
|
|
|
|
.populate("author", "username _id")
|
|
|
|
.exec(),
|
|
|
|
};
|
|
|
|
});
|