chore: move get CT with RW activated to utils

This commit is contained in:
Marc-Roig 2023-04-14 12:31:05 +02:00
parent ddc3c98c25
commit 077631d18b
3 changed files with 11 additions and 8 deletions

View File

@ -1,8 +1,9 @@
'use strict'; 'use strict';
const { set, get, forEach, keys, pickBy, pipe } = require('lodash/fp'); const { set, forEach, pipe } = require('lodash/fp');
const { mapAsync } = require('@strapi/utils'); const { mapAsync } = require('@strapi/utils');
const { getService } = require('../../utils'); const { getService } = require('../../utils');
const { getContentTypeUIDsWithActivatedReviewWorkflows } = require('../../utils/review-workflows');
const defaultStages = require('../../constants/default-stages.json'); const defaultStages = require('../../constants/default-stages.json');
const defaultWorkflow = require('../../constants/default-workflow.json'); const defaultWorkflow = require('../../constants/default-workflow.json');
@ -13,13 +14,6 @@ const {
} = require('../../migrations/review-workflows'); } = require('../../migrations/review-workflows');
const { getDefaultWorkflow } = require('../../utils/review-workflows'); const { getDefaultWorkflow } = require('../../utils/review-workflows');
const getContentTypeUIDsWithActivatedReviewWorkflows = pipe([
// Pick only content-types with reviewWorkflows options set to true
pickBy(get('options.reviewWorkflows')),
// Get UIDs
keys,
]);
async function initDefaultWorkflow({ workflowsService, stagesService, strapi }) { async function initDefaultWorkflow({ workflowsService, stagesService, strapi }) {
const wfCount = await workflowsService.count(); const wfCount = await workflowsService.count();
const stagesCount = await stagesService.count(); const stagesCount = await stagesService.count();

View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
const { get, keys, pickBy, pipe } = require('lodash/fp');
const { WORKFLOW_MODEL_UID } = require('../constants/workflows'); const { WORKFLOW_MODEL_UID } = require('../constants/workflows');
/** /**
@ -19,7 +20,15 @@ function hasReviewWorkflow({ strapi }, contentType) {
const getDefaultWorkflow = async ({ strapi }) => const getDefaultWorkflow = async ({ strapi }) =>
strapi.query(WORKFLOW_MODEL_UID).findOne({ populate: ['stages'] }); strapi.query(WORKFLOW_MODEL_UID).findOne({ populate: ['stages'] });
const getContentTypeUIDsWithActivatedReviewWorkflows = pipe([
// Pick only content-types with reviewWorkflows options set to true
pickBy(get('options.reviewWorkflows')),
// Get UIDs
keys,
]);
module.exports = { module.exports = {
hasReviewWorkflow, hasReviewWorkflow,
getDefaultWorkflow, getDefaultWorkflow,
getContentTypeUIDsWithActivatedReviewWorkflows,
}; };