feat: Implement isOwner flag for connections get flows API endpoint
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
import paginateRest from '../../../../helpers/pagination.js';
|
import paginateRest from '../../../../helpers/pagination.js';
|
||||||
|
import Flow from '../../../../models/flow.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const flowsQuery = request.currentUser.authorizedFlows
|
const flowsQuery = request.currentUser.authorizedFlows
|
||||||
@@ -11,6 +12,10 @@ export default async (request, response) => {
|
|||||||
.withGraphFetched({
|
.withGraphFetched({
|
||||||
steps: true,
|
steps: true,
|
||||||
})
|
})
|
||||||
|
.select('flows.*')
|
||||||
|
.select(
|
||||||
|
Flow.raw('flows.user_id = ? as "isOwner"', [request.currentUser.id])
|
||||||
|
)
|
||||||
.where('steps.connection_id', request.params.connectionId)
|
.where('steps.connection_id', request.params.connectionId)
|
||||||
.orderBy('active', 'desc')
|
.orderBy('active', 'desc')
|
||||||
.orderBy('updated_at', 'desc');
|
.orderBy('updated_at', 'desc');
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ describe('GET /api/v1/connections/:connectionId/flows', () => {
|
|||||||
|
|
||||||
const expectedPayload = await getFlowsMock(
|
const expectedPayload = await getFlowsMock(
|
||||||
[currentUserFlowOne],
|
[currentUserFlowOne],
|
||||||
[triggerStepFlowOne, actionStepFlowOne]
|
[triggerStepFlowOne, actionStepFlowOne],
|
||||||
|
currentUser.id
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.body).toStrictEqual(expectedPayload);
|
expect(response.body).toStrictEqual(expectedPayload);
|
||||||
@@ -120,7 +121,8 @@ describe('GET /api/v1/connections/:connectionId/flows', () => {
|
|||||||
|
|
||||||
const expectedPayload = await getFlowsMock(
|
const expectedPayload = await getFlowsMock(
|
||||||
[anotherUserFlowOne],
|
[anotherUserFlowOne],
|
||||||
[triggerStepFlowOne, actionStepFlowOne]
|
[triggerStepFlowOne, actionStepFlowOne],
|
||||||
|
currentUser.id
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.body).toStrictEqual(expectedPayload);
|
expect(response.body).toStrictEqual(expectedPayload);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const getFlowsMock = async (flows, steps) => {
|
const getFlowsMock = async (flows, steps, currentUserId) => {
|
||||||
const data = flows.map((flow) => {
|
const data = flows.map((flow) => {
|
||||||
const flowSteps = steps.filter((step) => step.flowId === flow.id);
|
const flowSteps = steps.filter((step) => step.flowId === flow.id);
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ const getFlowsMock = async (flows, steps) => {
|
|||||||
id: flow.id,
|
id: flow.id,
|
||||||
name: flow.name,
|
name: flow.name,
|
||||||
status: flow.active ? 'published' : 'draft',
|
status: flow.active ? 'published' : 'draft',
|
||||||
|
isOwner: flow.userId === currentUserId,
|
||||||
createdAt: flow.createdAt.getTime(),
|
createdAt: flow.createdAt.getTime(),
|
||||||
updatedAt: flow.updatedAt.getTime(),
|
updatedAt: flow.updatedAt.getTime(),
|
||||||
steps: flowSteps.map((step) => ({
|
steps: flowSteps.map((step) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user