feat: Implement update flow folder API endpoint

This commit is contained in:
Faruk AYDIN
2025-02-04 14:15:49 +01:00
parent 2401d78239
commit 15d02e3b7f
8 changed files with 301 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ import { ValidationError } from 'objection';
import Base from './base.js';
import Step from './step.js';
import User from './user.js';
import Folder from './folder.js';
import Execution from './execution.js';
import ExecutionStep from './execution-step.js';
import globalVariable from '../helpers/global-variable.js';
@@ -88,6 +89,14 @@ class Flow extends Base {
to: 'users.id',
},
},
folder: {
relation: Base.HasOneRelation,
modelClass: Folder,
join: {
from: 'flows.folder_id',
to: 'folders.id',
},
},
});
static async populateStatusProperty(flows) {
@@ -338,6 +347,23 @@ class Flow extends Base {
return allowedToRunFlows ? false : true;
}
async updateFolder(folderId) {
const user = await this.$relatedQuery('user');
const folder = await user
.$relatedQuery('folders')
.findOne({
id: folderId,
})
.throwIfNotFound();
await this.$query().patch({
folderId: folder.id,
});
return this.$query().withGraphFetched('folder');
}
async updateStatus(newActiveValue) {
if (this.active === newActiveValue) {
return this;