@@ -7,7 +7,7 @@ import { HttpException } from '@/exceptions/http-exception';
77import { LocaleService } from '@/i18n/ctx' ;
88import { FlowExtend } from '@/interfaces/flows.interface' ;
99import { 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' ;
1111import { StatusCodes } from 'http-status-codes' ;
1212import { Inject , Service } from 'typedi' ;
1313import { 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