feat: Implement isOwner flag for connections get flows API endpoint

This commit is contained in:
Faruk AYDIN
2025-04-01 16:30:42 +02:00
parent 988d3cbea6
commit 1ecf1af24b
3 changed files with 11 additions and 3 deletions

View File

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

View File

@@ -66,7 +66,8 @@ describe('GET /api/v1/connections/:connectionId/flows', () => {
const expectedPayload = await getFlowsMock(
[currentUserFlowOne],
[triggerStepFlowOne, actionStepFlowOne]
[triggerStepFlowOne, actionStepFlowOne],
currentUser.id
);
expect(response.body).toStrictEqual(expectedPayload);
@@ -120,7 +121,8 @@ describe('GET /api/v1/connections/:connectionId/flows', () => {
const expectedPayload = await getFlowsMock(
[anotherUserFlowOne],
[triggerStepFlowOne, actionStepFlowOne]
[triggerStepFlowOne, actionStepFlowOne],
currentUser.id
);
expect(response.body).toStrictEqual(expectedPayload);

View File

@@ -1,4 +1,4 @@
const getFlowsMock = async (flows, steps) => {
const getFlowsMock = async (flows, steps, currentUserId) => {
const data = flows.map((flow) => {
const flowSteps = steps.filter((step) => step.flowId === flow.id);
@@ -7,6 +7,7 @@ const getFlowsMock = async (flows, steps) => {
id: flow.id,
name: flow.name,
status: flow.active ? 'published' : 'draft',
isOwner: flow.userId === currentUserId,
createdAt: flow.createdAt.getTime(),
updatedAt: flow.updatedAt.getTime(),
steps: flowSteps.map((step) => ({