feat(api): create endpoint to retrieve all reviews left on the current user's story
This commit is contained in:
parent
25af14ceea
commit
da0b811428
24
server/api/user/me/reviews.get.ts
Normal file
24
server/api/user/me/reviews.get.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
||||||
|
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();
|
||||||
|
return ar
|
||||||
|
.map((a) => a.toObject())
|
||||||
|
.sort(
|
||||||
|
(a, b) => b.datePosted.getMilliseconds() - a.datePosted.getMilliseconds(),
|
||||||
|
);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user