refactor(api): get new reply id from save() call
This commit is contained in:
parent
489b2e0558
commit
7f1f8a72f5
@ -36,10 +36,18 @@ export default eventHandler(async (ev) => {
|
|||||||
whichChapter: replyingTo.whichChapter,
|
whichChapter: replyingTo.whichChapter,
|
||||||
datePosted: new Date(),
|
datePosted: new Date(),
|
||||||
});
|
});
|
||||||
let nrs = await newReply.save();
|
const { _id } = await newReply.save();
|
||||||
|
const nrs = (await Review.findOne({ _id })
|
||||||
|
.populate("author", "username _id blocked")
|
||||||
|
.exec())!;
|
||||||
replyingTo.replies.push(nrs._id);
|
replyingTo.replies.push(nrs._id);
|
||||||
await replyingTo.save();
|
await replyingTo.save();
|
||||||
const story = await Story.findById(replyingTo.leftOn);
|
const story = await Story.findById(replyingTo.leftOn);
|
||||||
|
if (!story) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 404,
|
||||||
|
});
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
back: `/story/${replyingTo.leftOn}/${
|
back: `/story/${replyingTo.leftOn}/${
|
||||||
story!.chapters.findIndex((x) => x.id === nrs.whichChapter) + 1
|
story!.chapters.findIndex((x) => x.id === nrs.whichChapter) + 1
|
||||||
|
Loading…
Reference in New Issue
Block a user