UNPKG

@wepublish/api

Version:
53 lines 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteCommentRatingAnswer = exports.createCommentRatingAnswer = exports.updateRatingSystem = void 0; const tslib_1 = require("tslib"); const api_1 = require("../../../../permissions-api/src"); const permissions_1 = require("../permissions"); const updateRatingSystem = (ratingSystemId, name, answers, authenticate, ratingSystem) => { const { roles } = authenticate(); (0, permissions_1.authorise)(api_1.CanUpdateCommentRatingSystem, roles); return ratingSystem.update({ where: { id: ratingSystemId }, data: { name, answers: { update: answers === null || answers === void 0 ? void 0 : answers.map(answer => ({ where: { id: answer.id }, data: { answer: answer.answer } })) } }, include: { answers: true } }); }; exports.updateRatingSystem = updateRatingSystem; const createCommentRatingAnswer = (ratingSystemId, type, answer, authenticate, ratingAnswer) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const { roles } = authenticate(); (0, permissions_1.authorise)(api_1.CanUpdateCommentRatingSystem, roles); return ratingAnswer.create({ data: { type, answer, ratingSystem: { connect: { id: ratingSystemId } } } }); }); exports.createCommentRatingAnswer = createCommentRatingAnswer; const deleteCommentRatingAnswer = (answerId, authenticate, commentRatingAnswer) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const { roles } = authenticate(); (0, permissions_1.authorise)(api_1.CanUpdateCommentRatingSystem, roles); return commentRatingAnswer.delete({ where: { id: answerId } }); }); exports.deleteCommentRatingAnswer = deleteCommentRatingAnswer; //# sourceMappingURL=comment-rating.private-mutation.js.map