UNPKG

@speckle/shared

Version:

Shared code between various Speckle JS packages

23 lines 921 B
import { err, ok } from 'true-myth/result'; import { CommentNoAccessError, CommentNotFoundError } from '../../../domain/authErrors.js'; import { canCreateProjectCommentPolicy } from './canCreate.js'; export const canEditProjectCommentPolicy = (loaders) => async ({ userId, commentId, projectId }) => { // Includes canCreate check const canCreate = await canCreateProjectCommentPolicy(loaders)({ userId, projectId }); if (canCreate.isErr) { return err(canCreate.error); } // Check that comment exists const comment = await loaders.getComment({ commentId, projectId }); if (!comment) return err(new CommentNotFoundError()); // Disallow if user is not the author if (comment.authorId !== userId) { return err(new CommentNoAccessError('You do not have access to edit this comment')); } return ok(); }; //# sourceMappingURL=canEdit.js.map