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-11 16:45:11 -04:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isLoggedIn(ev);
|
|
|
|
let stories = await Story.find({
|
|
|
|
author: ev.context.currentUser!._id,
|
|
|
|
}).exec();
|
|
|
|
let idArr = stories.map((a) => a._id);
|
|
|
|
let ar = await Review.find({
|
|
|
|
leftOn: {
|
|
|
|
$in: idArr,
|
|
|
|
},
|
|
|
|
replyingTo: null,
|
|
|
|
})
|
|
|
|
.populate("story")
|
|
|
|
.exec();
|
2023-12-29 20:53:29 -05:00
|
|
|
return ar.map((a) => a.toObject()).sort((a, b) => b.datePosted.getMilliseconds() - a.datePosted.getMilliseconds());
|
2023-10-11 16:45:11 -04:00
|
|
|
});
|