feat: Implement onlyOwnedFlows filter to get flows API endpoint

This commit is contained in:
Faruk AYDIN
2025-03-14 16:37:14 +01:00
parent 60b5d71309
commit d8d89032ae
3 changed files with 36 additions and 2 deletions

View File

@@ -16,5 +16,10 @@ export default async (request, response) => {
};
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);
}
getFlows({ folderId, name, status }, ownedFolderIds) {
getFlows({ folderId, name, status, onlyOwnedFlows }, ownedFolderIds) {
return this.authorizedFlows
.clone()
.withGraphFetched({
@@ -548,6 +548,10 @@ class User extends Base {
builder.where('flows.active', false);
}
if (onlyOwnedFlows) {
builder.where('flows.user_id', this.id);
}
if (folderId === 'null') {
builder
.whereNull('flows.folder_id')

View File

@@ -1258,6 +1258,16 @@ describe('User model', () => {
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 () => {
const flows = await currentUser.getFlows({ folderId: folder.id }, [
folder.id,
@@ -1310,6 +1320,21 @@ describe('User model', () => {
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');