2023-10-02 15:44:55 -04:00
|
|
|
import type { H3Event, EventHandlerRequest } from "h3";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { IStory } from "@models/stories";
|
2023-12-29 16:32:32 -05:00
|
|
|
import { isLoggedIn } from "@server/middlewareButNotReally";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { IDraft } from "@models/stories/draft";
|
2023-12-29 19:06:55 -05:00
|
|
|
import { IUser } from "@models/user";
|
2023-10-02 15:44:55 -04:00
|
|
|
export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) {
|
2023-12-09 17:00:22 -05:00
|
|
|
isLoggedIn(event);
|
2023-12-29 20:53:29 -05:00
|
|
|
return event.context.currentUser?.profile.isAdmin || (story.author as IUser)._id === event.context.currentUser?._id;
|
2023-10-02 15:44:55 -04:00
|
|
|
}
|
2023-12-29 20:53:29 -05:00
|
|
|
export function canDeleteDraft(event: H3Event<EventHandlerRequest>, story: IDraft) {
|
2023-12-20 17:23:31 -05:00
|
|
|
isLoggedIn(event);
|
|
|
|
return story.author === event.context.currentUser?._id;
|
|
|
|
}
|
2023-12-29 20:53:29 -05:00
|
|
|
export function canModify(event: H3Event<EventHandlerRequest>, story: IStory | IDraft) {
|
2023-12-09 17:00:22 -05:00
|
|
|
isLoggedIn(event);
|
2023-12-29 20:53:29 -05:00
|
|
|
return event.context.currentUser?._id === (story.author as IUser)._id || (story.coAuthor as IUser)?._id === event.context.currentUser?._id;
|
2023-10-02 15:44:55 -04:00
|
|
|
}
|