next/server/api/user/me/reviews.get.ts

21 lines
577 B
TypeScript
Raw Normal View History

import { isLoggedIn } from "@server/middlewareButNotReally";
import { Story } from "@models/stories";
import { Review } from "@models/stories/review";
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());
});