feat: Implement isOwner flag for get flows API endpoint

This commit is contained in:
Faruk AYDIN
2025-03-31 21:18:33 +02:00
parent 351576b6b3
commit 59b887079a
10 changed files with 133 additions and 8 deletions

View File

@@ -537,6 +537,8 @@ class User extends Base {
.withGraphFetched({
steps: true,
})
.select('flows.*')
.select(Flow.raw('flows.user_id = ? as "isOwner"', [this.id]))
.where((builder) => {
if (name) {
builder.where('flows.name', 'ilike', `%${name}%`);

View File

@@ -1333,6 +1333,23 @@ describe('User model', () => {
);
});
it('should return isOwner false if the flow is owned by another user', async () => {
const anotherUser = await createUser();
await createFlow({
userId: anotherUser.id,
folderId: folder.id,
active: true,
name: 'Another User Flow One',
});
const flows = await currentUser.getFlows({ onlyOwnedFlows: false }, [
folder.id,
]);
expect(flows[0].isOwner).toBe(false);
});
it('should return specified flows with all filters together', async () => {
const flows = await currentUser.getFlows(
{