feat: do not delete the last workflow

This commit is contained in:
Marc-Roig 2023-05-17 10:45:34 +02:00
parent 38377a89b7
commit 72c08abd23
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -132,6 +132,12 @@ module.exports = ({ strapi }) => {
async delete(workflow, opts) {
const stageService = getService('stages', { strapi });
const workflowCount = await this.count();
if (workflowCount <= 1) {
throw new ApplicationError('Can not delete the last workflow');
}
return strapi.db.transaction(async () => {
// Delete stages
await stageService.deleteMany(workflow.stages.map((stage) => stage.id));