@@ -11,7 +11,7 @@ import {
11
11
import { PaymentAPIService } from '@impler/services' ;
12
12
import { QueueService } from '@shared/services/queue.service' ;
13
13
import { AmplitudeService } from '@shared/services/amplitude.service' ;
14
- import { DalService , TemplateEntity , UploadRepository } from '@impler/dal' ;
14
+ import { DalService , TemplateEntity , TemplateRepository , UploadEntity , UploadRepository } from '@impler/dal' ;
15
15
16
16
@Injectable ( )
17
17
export class StartProcess {
@@ -20,7 +20,8 @@ export class StartProcess {
20
20
private queueService : QueueService ,
21
21
private uploadRepository : UploadRepository ,
22
22
private amplitudeService : AmplitudeService ,
23
- private paymentAPIService : PaymentAPIService
23
+ private paymentAPIService : PaymentAPIService ,
24
+ private templateRepository : TemplateRepository
24
25
) { }
25
26
26
27
async execute ( _uploadId : string ) {
@@ -43,6 +44,8 @@ export class StartProcess {
43
44
} ) ;
44
45
}
45
46
47
+ await this . updateTemplateStatistics ( { uploadInfo, userEmail } ) ;
48
+
46
49
// if destination is frontend or not defined then complete the upload process
47
50
if (
48
51
! destination ||
@@ -113,4 +116,33 @@ export class StartProcess {
113
116
114
117
return importedData ;
115
118
}
119
+
120
+ private async updateTemplateStatistics ( { uploadInfo, userEmail } : { uploadInfo : UploadEntity ; userEmail : string } ) {
121
+ //if its a file based import do-review will handle the further process
122
+ if ( uploadInfo . _uploadedFileId || uploadInfo . originalFileName ) {
123
+ return ;
124
+ }
125
+ await this . templateRepository . findOneAndUpdate (
126
+ {
127
+ _id : uploadInfo . _templateId ,
128
+ } ,
129
+ {
130
+ $inc : {
131
+ totalUploads : uploadInfo . totalRecords ,
132
+ totalRecords : uploadInfo . totalRecords ,
133
+ totalInvalidRecords : uploadInfo . invalidRecords ,
134
+ } ,
135
+ }
136
+ ) ;
137
+
138
+ await this . paymentAPIService . createEvent (
139
+ {
140
+ uploadId : uploadInfo . _id ,
141
+ totalRecords : uploadInfo . totalRecords ,
142
+ validRecords : uploadInfo . validRecords ,
143
+ invalidRecords : uploadInfo . invalidRecords ,
144
+ } ,
145
+ userEmail
146
+ ) ;
147
+ }
116
148
}
0 commit comments