@wepublish/api
Version:
API core for we.publish.
76 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateAuthor = exports.createAuthor = exports.deleteAuthorById = void 0;
const tslib_1 = require("tslib");
const api_1 = require("../../../../permissions-api/src");
const permissions_1 = require("../permissions");
const deleteAuthorById = (id, authenticate, author) => {
const { roles } = authenticate();
(0, permissions_1.authorise)(api_1.CanDeleteAuthor, roles);
return author.delete({
where: {
id
}
});
};
exports.deleteAuthorById = deleteAuthorById;
const createAuthor = (_a, authenticate, author) => {
var { id: authorId, links, tagIds } = _a, input = tslib_1.__rest(_a, ["id", "links", "tagIds"]);
const { roles } = authenticate();
(0, permissions_1.authorise)(api_1.CanCreateAuthor, roles);
return author.create({
data: Object.assign(Object.assign({}, input), { tags: {
create: tagIds === null || tagIds === void 0 ? void 0 : tagIds.map(tagId => ({
tagId
}))
}, links: {
create: links
} }),
include: {
links: true
}
});
};
exports.createAuthor = createAuthor;
const updateAuthor = (id, _a, authenticate, author) => {
var { links, tagIds } = _a, input = tslib_1.__rest(_a, ["links", "tagIds"]);
const { roles } = authenticate();
(0, permissions_1.authorise)(api_1.CanCreateAuthor, roles);
return author.update({
where: { id },
data: Object.assign(Object.assign({}, input), { tags: tagIds
? {
connectOrCreate: tagIds.map(tagId => ({
where: {
authorId_tagId: {
authorId: id,
tagId
}
},
create: {
tagId
}
})),
deleteMany: {
authorId: id,
tagId: {
notIn: tagIds
}
}
}
: undefined, links: {
deleteMany: {
authorId: {
equals: id
}
},
create: links
} }),
include: {
links: true,
tags: true
}
});
};
exports.updateAuthor = updateAuthor;
//# sourceMappingURL=author.private-mutation.js.map