fix: Allow to have null folder for flows

This commit is contained in:
Faruk AYDIN
2025-02-14 12:03:07 +01:00
parent 6cbd642c2a
commit f0f5c8fc9a
2 changed files with 40 additions and 6 deletions

View File

@@ -351,17 +351,20 @@ class Flow extends Base {
async updateFolder(folderId) {
const user = await this.$relatedQuery('user');
if (folderId === null) {
return this.updateFolderReference(null);
}
const folder = await user
.$relatedQuery('folders')
.findOne({
id: folderId,
})
.findOne({ id: folderId })
.throwIfNotFound();
await this.$query().patch({
folderId: folder.id,
});
return this.updateFolderReference(folder.id);
}
async updateFolderReference(folderId) {
await this.$query().patch({ folderId });
return this.$query().withGraphFetched('folder');
}

View File

@@ -505,6 +505,37 @@ describe('Flow model', () => {
expect(updatedFlow.folder.id).toBe(folder.id);
expect(updatedFlow.folder.name).toBe(folder.name);
});
it('should return the flow with null folder when folderId is null', async () => {
const user = await createUser();
const flow = await createFlow({ userId: user.id });
const updatedFlow = await flow.updateFolder(null);
expect(updatedFlow.folder).toBe(null);
});
});
describe('updateFolderReference', () => {
it('should update the folder reference and return the flow with the updated folder', async () => {
const user = await createUser();
const flow = await createFlow({ userId: user.id });
const folder = await createFolder({ userId: user.id });
const updatedFlow = await flow.updateFolderReference(folder.id);
expect(updatedFlow.folder.id).toBe(folder.id);
expect(updatedFlow.folder.name).toBe(folder.name);
});
it('should update the folder reference to null and return the flow with null folder', async () => {
const user = await createUser();
const flow = await createFlow({ userId: user.id });
const updatedFlow = await flow.updateFolderReference(null);
expect(updatedFlow.folder).toBe(null);
});
});
describe('throwIfHavingIncompleteSteps', () => {