UNPKG

@speckle/shared

Version:

Shared code between various Speckle JS packages

27 lines 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.canEditProjectCommentPolicy = void 0; const result_1 = require("true-myth/result"); const authErrors_js_1 = require("../../../domain/authErrors.js"); const canCreate_js_1 = require("./canCreate.js"); const canEditProjectCommentPolicy = (loaders) => async ({ userId, commentId, projectId }) => { // Includes canCreate check const canCreate = await (0, canCreate_js_1.canCreateProjectCommentPolicy)(loaders)({ userId, projectId }); if (canCreate.isErr) { return (0, result_1.err)(canCreate.error); } // Check that comment exists const comment = await loaders.getComment({ commentId, projectId }); if (!comment) return (0, result_1.err)(new authErrors_js_1.CommentNotFoundError()); // Disallow if user is not the author if (comment.authorId !== userId) { return (0, result_1.err)(new authErrors_js_1.CommentNoAccessError('You do not have access to edit this comment')); } return (0, result_1.ok)(); }; exports.canEditProjectCommentPolicy = canEditProjectCommentPolicy; //# sourceMappingURL=canEdit.js.map