mirror of
https://github.com/strapi/strapi.git
synced 2025-12-04 11:02:12 +00:00
feat: updateEntity workflow validations
This commit is contained in:
parent
5a84955297
commit
ff5e7076b6
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user