refactor(server/utils): allow an IDraft to be passed to permission checker

This commit is contained in:
parent fd4de6489f
commit 0ebc25a1c8
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -1,6 +1,7 @@
import type { H3Event, EventHandlerRequest } from "h3";
import { IStory } from "~/models/stories";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { IDraft } from "~/models/stories/draft";
export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) {
isLoggedIn(event);
return (
@ -8,7 +9,10 @@ export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) {
story.author._id === event.context.currentUser?._id
);
}
export function canModify(event: H3Event<EventHandlerRequest>, story: IStory) {
export function canModify(
event: H3Event<EventHandlerRequest>,
story: IStory | IDraft,
) {
isLoggedIn(event);
return (
event.context.currentUser?._id === story.author._id ||