feat: Add status flag to get flows filters
This commit is contained in:
@@ -531,7 +531,7 @@ class User extends Base {
|
||||
return folders.map((folder) => folder.id);
|
||||
}
|
||||
|
||||
getFlows({ folderId, name }, ownedFolderIds) {
|
||||
getFlows({ folderId, name, status }, ownedFolderIds) {
|
||||
return this.authorizedFlows
|
||||
.clone()
|
||||
.withGraphFetched({
|
||||
@@ -542,6 +542,12 @@ class User extends Base {
|
||||
builder.where('flows.name', 'ilike', `%${name}%`);
|
||||
}
|
||||
|
||||
if (status === 'published') {
|
||||
builder.where('flows.active', true);
|
||||
} else if (status === 'draft') {
|
||||
builder.where('flows.active', false);
|
||||
}
|
||||
|
||||
if (folderId === 'null') {
|
||||
builder
|
||||
.whereNull('flows.folder_id')
|
||||
|
||||
@@ -1202,11 +1202,13 @@ describe('User model', () => {
|
||||
flowOne = await createFlow({
|
||||
userId: currentUser.id,
|
||||
folderId: folder.id,
|
||||
active: true,
|
||||
name: 'Flow One',
|
||||
});
|
||||
|
||||
flowTwo = await createFlow({
|
||||
userId: currentUser.id,
|
||||
active: false,
|
||||
name: 'Flow Two',
|
||||
});
|
||||
|
||||
@@ -1237,6 +1239,25 @@ describe('User model', () => {
|
||||
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 with specific folder ID', async () => {
|
||||
const flows = await currentUser.getFlows({ folderId: folder.id }, [
|
||||
folder.id,
|
||||
|
||||
Reference in New Issue
Block a user