@@ -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 ) {
@@ -52,12 +53,16 @@ export class StartProcess {
52
53
{ _id : _uploadId } ,
53
54
{ status : UploadStatusEnum . COMPLETED }
54
55
) ;
56
+
57
+ await this . updateTemplateStatistics ( { uploadInfo, userEmail } ) ;
55
58
} else {
56
59
// if template destination has callbackUrl then start sending data to the callbackUrl
57
60
uploadInfo = await this . uploadRepository . findOneAndUpdate (
58
61
{ _id : _uploadId } ,
59
62
{ status : UploadStatusEnum . PROCESSING }
60
63
) ;
64
+
65
+ await this . updateTemplateStatistics ( { uploadInfo, userEmail } ) ;
61
66
}
62
67
63
68
this . amplitudeService . recordsImported ( userEmail , {
@@ -113,4 +118,33 @@ export class StartProcess {
113
118
114
119
return importedData ;
115
120
}
121
+
122
+ private async updateTemplateStatistics ( { uploadInfo, userEmail } : { uploadInfo : UploadEntity ; userEmail : string } ) {
123
+ //if its a file based import do-review will handle the further process
124
+ if ( uploadInfo . _uploadedFileId || uploadInfo . originalFileName ) {
125
+ return ;
126
+ }
127
+ await this . templateRepository . findOneAndUpdate (
128
+ {
129
+ _id : uploadInfo . _templateId ,
130
+ } ,
131
+ {
132
+ $inc : {
133
+ totalUploads : uploadInfo . totalRecords ,
134
+ totalRecords : uploadInfo . totalRecords ,
135
+ totalInvalidRecords : uploadInfo . invalidRecords ,
136
+ } ,
137
+ }
138
+ ) ;
139
+
140
+ await this . paymentAPIService . createEvent (
141
+ {
142
+ uploadId : uploadInfo . _id ,
143
+ totalRecords : uploadInfo . totalRecords ,
144
+ validRecords : uploadInfo . validRecords ,
145
+ invalidRecords : uploadInfo . invalidRecords ,
146
+ } ,
147
+ userEmail
148
+ ) ;
149
+ }
116
150
}
0 commit comments