mirror of
https://github.com/strapi/strapi.git
synced 2025-09-23 07:22:51 +00:00
fix(ee): retrieve stage name and ID from updated entity
This commit is contained in:
parent
2ca802bcbd
commit
5985781a9a
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const { omit } = require('lodash/fp');
|
const { omit } = require('lodash/fp');
|
||||||
const { WORKFLOW_UPDATE_STAGE } = require('../../../constants/webhookEvents');
|
const { WORKFLOW_UPDATE_STAGE } = require('../../../constants/webhookEvents');
|
||||||
const { STAGE_MODEL_UID } = require('../../../constants/workflows');
|
const { ENTITY_STAGE_ATTRIBUTE } = require('../../../constants/workflows');
|
||||||
const { decorator } = require('../entity-service-decorator')();
|
const { decorator } = require('../entity-service-decorator')();
|
||||||
|
|
||||||
jest.mock('../../../utils');
|
jest.mock('../../../utils');
|
||||||
@ -109,22 +109,23 @@ describe('Entity service decorator', () => {
|
|||||||
const stageToId = 3;
|
const stageToId = 3;
|
||||||
|
|
||||||
const defaultService = {
|
const defaultService = {
|
||||||
update: jest.fn(() => Promise.resolve({ id: entityId })),
|
update: jest.fn(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
id: entityId,
|
||||||
|
[ENTITY_STAGE_ATTRIBUTE]: {
|
||||||
|
id: stageToId,
|
||||||
|
name: `Stage ${stageToId}`,
|
||||||
|
workflow: { id: workflowId },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
const emit = jest.fn();
|
const emit = jest.fn();
|
||||||
global.strapi = {
|
global.strapi = {
|
||||||
...global.strapi,
|
...global.strapi,
|
||||||
entityService: {
|
entityService: {
|
||||||
findOne: jest.fn((uid, id) => {
|
findOne: jest.fn(() => {
|
||||||
if (uid === STAGE_MODEL_UID) {
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
name: `Stage ${id}`,
|
|
||||||
workflow: { id: workflowId },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
strapi_reviewWorkflows_stage: {
|
strapi_reviewWorkflows_stage: {
|
||||||
id: stageFromId,
|
id: stageFromId,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { isNil, isNull } = require('lodash/fp');
|
const { isNil, isNull } = require('lodash/fp');
|
||||||
const { ENTITY_STAGE_ATTRIBUTE, STAGE_MODEL_UID } = require('../../constants/workflows');
|
const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows');
|
||||||
const { WORKFLOW_UPDATE_STAGE } = require('../../constants/webhookEvents');
|
const { WORKFLOW_UPDATE_STAGE } = require('../../constants/webhookEvents');
|
||||||
const { hasReviewWorkflow, getDefaultWorkflow } = require('../../utils/review-workflows');
|
const { hasReviewWorkflow, getDefaultWorkflow } = require('../../utils/review-workflows');
|
||||||
|
|
||||||
@ -66,15 +66,11 @@ const decorator = (service) => ({
|
|||||||
return service.update.call(this, uid, entityId, { ...opts, data });
|
return service.update.call(this, uid, entityId, { ...opts, data });
|
||||||
}
|
}
|
||||||
|
|
||||||
const newStage = await strapi.entityService.findOne(
|
|
||||||
STAGE_MODEL_UID,
|
|
||||||
data[ENTITY_STAGE_ATTRIBUTE]
|
|
||||||
);
|
|
||||||
const previousStage = await getEntityStage(uid, entityId);
|
const previousStage = await getEntityStage(uid, entityId);
|
||||||
|
|
||||||
const updatedEntity = await service.update.call(this, uid, entityId, { ...opts, data });
|
const updatedEntity = await service.update.call(this, uid, entityId, { ...opts, data });
|
||||||
|
|
||||||
if (previousStage?.id && previousStage.id !== newStage.id) {
|
if (previousStage?.id && previousStage.id !== updatedEntity[ENTITY_STAGE_ATTRIBUTE].id) {
|
||||||
const model = strapi.getModel(uid);
|
const model = strapi.getModel(uid);
|
||||||
|
|
||||||
strapi.eventHub.emit(WORKFLOW_UPDATE_STAGE, {
|
strapi.eventHub.emit(WORKFLOW_UPDATE_STAGE, {
|
||||||
@ -91,8 +87,8 @@ const decorator = (service) => ({
|
|||||||
name: previousStage.name,
|
name: previousStage.name,
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
id: newStage.id,
|
id: updatedEntity[ENTITY_STAGE_ATTRIBUTE].id,
|
||||||
name: newStage.name,
|
name: updatedEntity[ENTITY_STAGE_ATTRIBUTE].name,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user