feat: Implement isOwner flag to apps get flows API endpoint

This commit is contained in:
Faruk AYDIN
2025-04-01 16:29:13 +02:00
parent eb45b77c17
commit 988d3cbea6
3 changed files with 11 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import { renderObject } from '../../../../helpers/renderer.js';
import App from '../../../../models/app.js';
import Flow from '../../../../models/flow.js';
import paginateRest from '../../../../helpers/pagination.js';
export default async (request, response) => {
@@ -14,6 +15,10 @@ export default async (request, response) => {
.withGraphFetched({
steps: true,
})
.select('flows.*')
.select(
Flow.raw('flows.user_id = ? as "isOwner"', [request.currentUser.id])
)
.where('steps.app_key', app.key)
.orderBy('active', 'desc')
.orderBy('updated_at', 'desc');

View File

@@ -59,7 +59,8 @@ describe('GET /api/v1/apps/:appKey/flows', () => {
const expectedPayload = await getFlowsMock(
[currentUserFlowOne],
[triggerStepFlowOne, actionStepFlowOne]
[triggerStepFlowOne, actionStepFlowOne],
currentUser.id
);
expect(response.body).toStrictEqual(expectedPayload);
@@ -107,7 +108,8 @@ describe('GET /api/v1/apps/:appKey/flows', () => {
const expectedPayload = await getFlowsMock(
[anotherUserFlowOne],
[triggerStepFlowOne, actionStepFlowOne]
[triggerStepFlowOne, actionStepFlowOne],
currentUser.id
);
expect(response.body).toStrictEqual(expectedPayload);