Skip to content

Commit e821203

Browse files
committed
add
1 parent 386fefa commit e821203

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

server/src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const ENDPOINTS = {
5454
GET_ONE: '/flow/get-one',
5555
PUBLISH: '/flow/publish-flow',
5656
ADD_CHANNELS: '/flow/add-channels',
57-
SELECT_FLOWS_FOR_CHANNEL: '/flow/select'
57+
SELECT_FLOWS_FOR_CHANNEL: '/flow/select',
5858
}
5959
};
6060

server/src/controllers/flows.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,11 @@ export class FlowController {
8383
);
8484
res.status(StatusCodes.OK).json({ data });
8585
});
86+
87+
public getFlowByContactId = catchAsync(async (req: RequestWithUser, res) => {
88+
const data = await this.flowService.getFlowByContactId(
89+
req.params.contactId,
90+
);
91+
res.status(StatusCodes.OK).json({ data });
92+
});
8693
}

server/src/database/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export const flows = pgTable('flows', {
123123
deleted: boolean('deleted').default(false),
124124
updatedAt: timestamp('updated_at'),
125125
createdAt: timestamp('created_at').defaultNow(),
126-
diagrams: json('diagrams').default([]).$type<any[]>(),
127126
edges: json('edges').default([]).$type<any[]>(),
128127
nodes: json('nodes').default([]).$type<any[]>(),
129128
settings: json('settings').default([]).$type<any[]>(),

server/src/routes/flow.route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ export class FlowRoute implements Routes {
6666
authMiddleware,
6767
this.controller.selectFlowsForChannel
6868
);
69+
70+
this.router.get(
71+
`${ENDPOINTS.FLOW.INDEX}/:contactId`,
72+
authMiddleware,
73+
this.controller.getFlowByContactId
74+
);
6975
}
7076
}

server/src/services/flows.service.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { HttpException } from '@/exceptions/http-exception';
77
import { LocaleService } from '@/i18n/ctx';
88
import { FlowExtend } from '@/interfaces/flows.interface';
99
import { Paging } from '@/interfaces/paging.interface';
10-
import { and, asc, desc, eq, like, ne, notExists, sql } from 'drizzle-orm';
10+
import { and, asc, desc, eq, isNotNull, like, ne, notExists, sql } from 'drizzle-orm';
1111
import { StatusCodes } from 'http-status-codes';
1212
import { Inject, Service } from 'typedi';
1313
import { ChannelService } from './channels.service';
@@ -152,10 +152,6 @@ export class FlowService {
152152
return flowExisted;
153153
}
154154

155-
public async getFlowByContactId(contactId: string) {
156-
157-
}
158-
159155
public async getAllFlows(paging: PagingDTO,
160156
userId: string
161157
): Promise<Paging<FlowExtend>> {
@@ -201,7 +197,6 @@ export class FlowService {
201197
return orderBy;
202198
}
203199

204-
205200
public async addMultipleChannels(channelIDs: string[], flowId: string, userId: string) {
206201
const flowExisted = await db.query.flows.findFirst({
207202
where: and(
@@ -251,4 +246,32 @@ export class FlowService {
251246

252247
return result;
253248
}
249+
250+
public async getFlowByContactId(contactId: string) {
251+
const flow = db.query.flows.findFirst({
252+
where: and(
253+
eq(flows.deleted, false),
254+
isNotNull(flows.publishAt),
255+
isNotNull(
256+
db.select({
257+
id: channels.id
258+
})
259+
.from(channels)
260+
.where(
261+
and(
262+
eq(channels.contactId, contactId),
263+
)
264+
)
265+
)
266+
)
267+
});
268+
269+
if (!flow) {
270+
throw new HttpException(
271+
StatusCodes.BAD_REQUEST,
272+
this.localeService.i18n().FLOW.NOT_FOUND()
273+
);
274+
}
275+
return flow;
276+
}
254277
}

0 commit comments

Comments
 (0)