feat(api): integrate co-author feature in api routes and helpers

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-11 15:31:02 -04:00
parent 54349b4f29
commit 01d3b7f22b
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
5 changed files with 8 additions and 1 deletions

View File

@ -22,6 +22,7 @@ export default async function (query, context, limit?: number, sort?) {
path: "ficmas",
populate: { path: "wisher", model: "User", select: "username _id" },
})
.populate("coAuthor", "username _id")
.populate("chapters.bands")
.populate({ path: "challenge", model: Challenge })
.populate("author", "username _id")

View File

@ -11,6 +11,7 @@ export default async function (ev: H3Event<EventHandlerRequest>) {
});
const story = await Story.findById(id)
.populate("author", "username profile blocked")
.populate("coAuthor", "username profile")
.populate("chapters.bands")
.populate({
path: "ficmas",

View File

@ -7,5 +7,8 @@ export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) {
);
}
export function canModify(event: H3Event<EventHandlerRequest>, story: IStory) {
return event.context.currentUser?._id === story.author._id;
return (
event.context.currentUser?._id === story.author._id ||
story.coAuthor._id === event.context.currentUser?._id
);
}

View File

@ -33,6 +33,7 @@ export default eventHandler(async (ev) => {
const update: Partial<IStory> = {
title: body.title,
completed: body.completed,
coAuthor: body.coAuthor,
chapters: [],
};
for (const oc of os.chapters) {

View File

@ -18,6 +18,7 @@ export default eventHandler(async (ev) => {
const story = new Story({
title: body.title,
author: ev.context.currentUser!._id,
coAuthor: body.coAuthor,
views: 0,
reviews: 0,
downloads: 0,