Merge pull request #2401 from automatisch/flow-filters

feat: Add status flag to get flows filters
This commit is contained in:
Ali BARIN
2025-03-18 10:55:22 +01:00
committed by GitHub
3 changed files with 63 additions and 2 deletions

View File

@@ -16,5 +16,10 @@ export default async (request, response) => {
}; };
const flowParams = (request) => { const flowParams = (request) => {
return { folderId: request.query.folderId, name: request.query.name }; return {
folderId: request.query.folderId,
name: request.query.name,
status: request.query.status,
onlyOwnedFlows: request.query.onlyOwnedFlows,
};
}; };

View File

@@ -531,7 +531,7 @@ class User extends Base {
return folders.map((folder) => folder.id); return folders.map((folder) => folder.id);
} }
getFlows({ folderId, name }, ownedFolderIds) { getFlows({ folderId, name, status, onlyOwnedFlows }, ownedFolderIds) {
return this.authorizedFlows return this.authorizedFlows
.clone() .clone()
.withGraphFetched({ .withGraphFetched({
@@ -542,6 +542,16 @@ class User extends Base {
builder.where('flows.name', 'ilike', `%${name}%`); builder.where('flows.name', 'ilike', `%${name}%`);
} }
if (status === 'published') {
builder.where('flows.active', true);
} else if (status === 'draft') {
builder.where('flows.active', false);
}
if (onlyOwnedFlows) {
builder.where('flows.user_id', this.id);
}
if (folderId === 'null') { if (folderId === 'null') {
builder builder
.whereNull('flows.folder_id') .whereNull('flows.folder_id')

View File

@@ -1202,11 +1202,13 @@ describe('User model', () => {
flowOne = await createFlow({ flowOne = await createFlow({
userId: currentUser.id, userId: currentUser.id,
folderId: folder.id, folderId: folder.id,
active: true,
name: 'Flow One', name: 'Flow One',
}); });
flowTwo = await createFlow({ flowTwo = await createFlow({
userId: currentUser.id, userId: currentUser.id,
active: false,
name: 'Flow Two', name: 'Flow Two',
}); });
@@ -1237,6 +1239,35 @@ describe('User model', () => {
expect(flows[0].id).toBe(flowTwo.id); expect(flows[0].id).toBe(flowTwo.id);
}); });
it('should return flows filtered by status', async () => {
const flows = await currentUser.getFlows({ status: 'published' }, [
folder.id,
]);
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowOne.id);
});
it('should return flows filtered by name and status', async () => {
const flows = await currentUser.getFlows(
{ name: 'Flow One', status: 'published' },
[folder.id]
);
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowOne.id);
});
it('should return flows filtered by onlyOwnedFlows', async () => {
const flows = await currentUser.getFlows({ onlyOwnedFlows: true }, [
folder.id,
]);
expect(flows).toHaveLength(2);
expect(flows[0].id).toBe(flowOne.id);
expect(flows[1].id).toBe(flowTwo.id);
});
it('should return flows with specific folder ID', async () => { it('should return flows with specific folder ID', async () => {
const flows = await currentUser.getFlows({ folderId: folder.id }, [ const flows = await currentUser.getFlows({ folderId: folder.id }, [
folder.id, folder.id,
@@ -1289,6 +1320,21 @@ describe('User model', () => {
expect.arrayContaining([flowTwo.id, flowThree.id]) expect.arrayContaining([flowTwo.id, flowThree.id])
); );
}); });
it('should return specified flows with all filters together', async () => {
const flows = await currentUser.getFlows(
{
folderId: folder.id,
name: 'Flow One',
status: 'published',
onlyOwnedFlows: true,
},
[folder.id]
);
expect(flows).toHaveLength(1);
expect(flows[0].id).toBe(flowOne.id);
});
}); });
it.todo('getApps'); it.todo('getApps');