feat: updateEntity workflow validations

This commit is contained in:
Marc-Roig 2023-05-15 10:25:12 +02:00
parent 5a84955297
commit ff5e7076b6
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -1,8 +1,7 @@
'use strict';
const { ApplicationError } = require('@strapi/utils/lib/errors');
const { ApplicationError } = require('@strapi/utils').errors;
const { getService } = require('../../../utils');
const { hasReviewWorkflow } = require('../../../utils/review-workflows');
const { validateUpdateStageOnEntity } = require('../../../validation/review-workflows');
module.exports = {
@ -58,6 +57,7 @@ module.exports = {
*/
async updateEntity(ctx) {
const stagesService = getService('stages');
const workflowService = getService('workflows');
const { model_uid: modelUID, id: entityIdString } = ctx.params;
const entityId = Number(entityIdString);
@ -66,12 +66,8 @@ module.exports = {
'You should pass an id to the body of the put request.'
);
if (!hasReviewWorkflow({ strapi }, modelUID)) {
throw new ApplicationError(`Review workflows is not activated on ${modelUID}.`);
}
// TODO When multiple workflows are possible, check if the stage is part of the right one
// Didn't need this today as their can only be one workflow
const workflow = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);
workflowService.assertStageBelongsToWorkflow(stageId, workflow);
const data = await stagesService.updateEntity({ id: entityId, modelUID }, stageId);