@@ -17,16 +17,15 @@ import { CurrentProject } from '@/common/decorators/current-project.decorator';
1717import { BusinessReportService } from '@/business-report/business-report.service' ;
1818import { GetLatestBusinessReportDto } from '@/business-report/get-latest-business-report.dto' ;
1919import {
20- ListBusinessReportsDto ,
20+ BusinessReportListRequestParamDto ,
21+ BusinessReportListResponseDto ,
2122 ListBusinessReportsSchema ,
22- } from '@/business-report/list- business-reports .dto' ;
23+ } from '@/business-report/business-report-list .dto' ;
2324import { Business } from '@prisma/client' ;
2425import { ZodValidationPipe } from '@/common/pipes/zod.pipe' ;
2526import { CreateBusinessReportDto } from '@/business-report/dto/create-business-report.dto' ;
26- import { HookCallbackHandlerService } from '@/workflow/hook-callback-handler.service' ;
2727import { CustomerService } from '@/customer/customer.service' ;
2828import { BusinessService } from '@/business/business.service' ;
29- import { AlertService } from '@/alert/alert.service' ;
3029import { Public } from '@/common/decorators/public.decorator' ;
3130import { VerifyUnifiedApiSignatureDecorator } from '@/common/decorators/verify-unified-api-signature.decorator' ;
3231import { BusinessReportHookBodyDto } from '@/business-report/dtos/business-report-hook-body.dto' ;
@@ -37,90 +36,23 @@ import { fileFilter } from '@/storage/file-filter';
3736import { RemoveTempFileInterceptor } from '@/common/interceptors/remove-temp-file.interceptor' ;
3837import { CreateBusinessReportBatchBodyDto } from '@/business-report/dto/create-business-report-batch-body.dto' ;
3938import type { Response } from 'express' ;
39+ import { BusinessReportDto } from '@/business-report/business-report.dto' ;
4040
4141@ApiBearerAuth ( )
4242@swagger . ApiTags ( 'Business Reports' )
4343@common . Controller ( 'internal/business-reports' )
44- @swagger . ApiExcludeController ( )
4544export class BusinessReportControllerInternal {
4645 constructor (
4746 protected readonly businessReportService : BusinessReportService ,
4847 protected readonly logger : AppLoggerService ,
4948 protected readonly customerService : CustomerService ,
5049 protected readonly businessService : BusinessService ,
51- protected readonly alertService : AlertService ,
52- protected readonly hookCallbackService : HookCallbackHandlerService ,
5350 ) { }
5451
55- @common . Post ( )
56- @swagger . ApiOkResponse ( { type : [ String ] } )
57- @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
58- async createBusinessReport (
59- @Body ( )
60- {
61- websiteUrl,
62- countryCode,
63- merchantName,
64- businessCorrelationId,
65- reportType,
66- workflowVersion,
67- } : CreateBusinessReportDto ,
68- @CurrentProject ( ) currentProjectId : TProjectId ,
69- ) {
70- const { id : customerId , config } = await this . customerService . getByProjectId ( currentProjectId ) ;
71-
72- const { maxBusinessReports, withQualityControl } = config || { } ;
73- await this . businessReportService . checkBusinessReportsLimit ( maxBusinessReports , customerId ) ;
74-
75- let business : Pick < Business , 'id' | 'correlationId' > | undefined ;
76- const merchantNameWithDefault = merchantName || 'Not detected' ;
77-
78- if ( ! businessCorrelationId ) {
79- business = await this . businessService . create ( {
80- data : {
81- companyName : merchantNameWithDefault ,
82- country : countryCode ,
83- website : websiteUrl ,
84- projectId : currentProjectId ,
85- } ,
86- select : {
87- id : true ,
88- correlationId : true ,
89- } ,
90- } ) ;
91- }
92-
93- if ( businessCorrelationId ) {
94- business =
95- ( await this . businessService . getByCorrelationId ( businessCorrelationId , [ currentProjectId ] , {
96- select : {
97- id : true ,
98- correlationId : true ,
99- } ,
100- } ) ) ?? undefined ;
101- }
102-
103- if ( ! business ) {
104- throw new BadRequestException (
105- `Business with an id of ${ businessCorrelationId } was not found` ,
106- ) ;
107- }
108-
109- await this . businessReportService . createBusinessReportAndTriggerReportCreation ( {
110- reportType,
111- business,
112- websiteUrl,
113- countryCode,
114- merchantName : merchantNameWithDefault ,
115- workflowVersion,
116- withQualityControl,
117- customerId,
118- } ) ;
119- }
120-
12152 @common . Post ( '/hook' )
12253 @swagger . ApiOkResponse ( { type : [ String ] } )
12354 @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
55+ @swagger . ApiExcludeEndpoint ( )
12456 @Public ( )
12557 @VerifyUnifiedApiSignatureDecorator ( )
12658 async createBusinessReportCallback (
@@ -156,6 +88,7 @@ export class BusinessReportControllerInternal {
15688 @common . Get ( '/latest' )
15789 @swagger . ApiOkResponse ( { type : [ String ] } )
15890 @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
91+ @swagger . ApiExcludeEndpoint ( )
15992 async getLatestBusinessReport (
16093 @CurrentProject ( ) currentProjectId : TProjectId ,
16194 @Query ( ) { businessId, type } : GetLatestBusinessReportDto ,
@@ -172,12 +105,12 @@ export class BusinessReportControllerInternal {
172105 }
173106
174107 @common . Get ( )
175- @swagger . ApiOkResponse ( { type : [ String ] } )
108+ @swagger . ApiOkResponse ( { type : BusinessReportListResponseDto } )
176109 @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
177110 @common . UsePipes ( new ZodValidationPipe ( ListBusinessReportsSchema , 'query' ) )
178111 async listBusinessReports (
179112 @CurrentProject ( ) currentProjectId : TProjectId ,
180- @Query ( ) { businessId, page, search, orderBy } : ListBusinessReportsDto ,
113+ @Query ( ) { businessId, page, search } : BusinessReportListRequestParamDto ,
181114 ) {
182115 const { id : customerId } = await this . customerService . getByProjectId ( currentProjectId ) ;
183116
@@ -191,8 +124,74 @@ export class BusinessReportControllerInternal {
191124 } ) ;
192125 }
193126
127+ @common . Post ( )
128+ @swagger . ApiOkResponse ( { } )
129+ @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
130+ async createBusinessReport (
131+ @Body ( )
132+ {
133+ websiteUrl,
134+ countryCode,
135+ merchantName,
136+ businessCorrelationId,
137+ reportType,
138+ workflowVersion,
139+ } : CreateBusinessReportDto ,
140+ @CurrentProject ( ) currentProjectId : TProjectId ,
141+ ) {
142+ const { id : customerId , config } = await this . customerService . getByProjectId ( currentProjectId ) ;
143+
144+ const { maxBusinessReports, withQualityControl } = config || { } ;
145+ await this . businessReportService . checkBusinessReportsLimit ( maxBusinessReports , customerId ) ;
146+
147+ let business : Pick < Business , 'id' | 'correlationId' > | undefined ;
148+ const merchantNameWithDefault = merchantName || 'Not detected' ;
149+
150+ if ( ! businessCorrelationId ) {
151+ business = await this . businessService . create ( {
152+ data : {
153+ companyName : merchantNameWithDefault ,
154+ country : countryCode ,
155+ website : websiteUrl ,
156+ projectId : currentProjectId ,
157+ } ,
158+ select : {
159+ id : true ,
160+ correlationId : true ,
161+ } ,
162+ } ) ;
163+ }
164+
165+ if ( businessCorrelationId ) {
166+ business =
167+ ( await this . businessService . getByCorrelationId ( businessCorrelationId , [ currentProjectId ] , {
168+ select : {
169+ id : true ,
170+ correlationId : true ,
171+ } ,
172+ } ) ) ?? undefined ;
173+ }
174+
175+ if ( ! business ) {
176+ throw new BadRequestException (
177+ `Business with an id of ${ businessCorrelationId } was not found` ,
178+ ) ;
179+ }
180+
181+ await this . businessReportService . createBusinessReportAndTriggerReportCreation ( {
182+ reportType,
183+ business,
184+ websiteUrl,
185+ countryCode,
186+ merchantName : merchantNameWithDefault ,
187+ workflowVersion,
188+ withQualityControl,
189+ customerId,
190+ } ) ;
191+ }
192+
194193 @common . Get ( ':id' )
195- @swagger . ApiOkResponse ( { type : [ String ] } )
194+ @swagger . ApiOkResponse ( { type : BusinessReportDto } )
196195 @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
197196 @common . UsePipes ( new ZodValidationPipe ( ListBusinessReportsSchema , 'query' ) )
198197 async getBusinessReportById (
@@ -204,6 +203,7 @@ export class BusinessReportControllerInternal {
204203 return await this . businessReportService . findById ( { id, customerId } ) ;
205204 }
206205
206+ @swagger . ApiExcludeEndpoint ( )
207207 @common . Post ( '/upload-batch' )
208208 @swagger . ApiForbiddenResponse ( { type : errors . ForbiddenException } )
209209 @ApiConsumes ( 'multipart/form-data' )
0 commit comments