mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
feat: upsert stages when creating a workflow
This commit is contained in:
parent
e8dd199183
commit
aa67d1fba2
@ -1,6 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { set } = require('lodash/fp');
|
||||||
const { WORKFLOW_MODEL_UID } = require('../../constants/workflows');
|
const { WORKFLOW_MODEL_UID } = require('../../constants/workflows');
|
||||||
|
const { getService } = require('../../utils');
|
||||||
|
|
||||||
module.exports = ({ strapi }) => ({
|
module.exports = ({ strapi }) => ({
|
||||||
find(opts) {
|
find(opts) {
|
||||||
@ -11,8 +13,19 @@ module.exports = ({ strapi }) => ({
|
|||||||
return strapi.entityService.findOne(WORKFLOW_MODEL_UID, id, opts);
|
return strapi.entityService.findOne(WORKFLOW_MODEL_UID, id, opts);
|
||||||
},
|
},
|
||||||
|
|
||||||
create(workflowData) {
|
async create(opts) {
|
||||||
return strapi.entityService.create(WORKFLOW_MODEL_UID, { data: workflowData });
|
let createOpts = opts;
|
||||||
|
|
||||||
|
// Create stages if provided
|
||||||
|
if (opts.data.stages) {
|
||||||
|
const stageIds = await getService('stages', { strapi })
|
||||||
|
.replaceStages([], opts.data.stages)
|
||||||
|
.then((stages) => stages.map((stage) => stage.id));
|
||||||
|
|
||||||
|
createOpts = set('data.stages', stageIds, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
return strapi.entityService.create(WORKFLOW_MODEL_UID, createOpts);
|
||||||
},
|
},
|
||||||
|
|
||||||
count() {
|
count() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user