2023-10-02 15:44:55 -04:00
|
|
|
import type { H3Event, EventHandlerRequest } from "h3";
|
|
|
|
import { IStory } from "~/models/stories";
|
2023-12-09 17:00:22 -05:00
|
|
|
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
2023-12-11 21:20:06 -05:00
|
|
|
import { IDraft } from "~/models/stories/draft";
|
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-10-02 15:44:55 -04:00
|
|
|
return (
|
|
|
|
event.context.currentUser?.profile.isAdmin ||
|
|
|
|
story.author._id === event.context.currentUser?._id
|
|
|
|
);
|
|
|
|
}
|
2023-12-11 21:20:06 -05:00
|
|
|
export function canModify(
|
|
|
|
event: H3Event<EventHandlerRequest>,
|
|
|
|
story: IStory | IDraft,
|
|
|
|
) {
|
2023-12-09 17:00:22 -05:00
|
|
|
isLoggedIn(event);
|
2023-10-11 15:31:02 -04:00
|
|
|
return (
|
|
|
|
event.context.currentUser?._id === story.author._id ||
|
2023-12-09 17:00:22 -05:00
|
|
|
story.coAuthor?._id === event.context.currentUser?._id
|
2023-10-11 15:31:02 -04:00
|
|
|
);
|
2023-10-02 15:44:55 -04:00
|
|
|
}
|