Merge pull request #2427 from automatisch/is-owner
feat: Implement isOwner flag to apps get flows API endpoint
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
Reference in New Issue
Block a user