Skip to content

Commit 16a21aa

Browse files
feat: Added the statistics and usage count on templates for manual data entry method (#981)
2 parents 1677d6a + 33dbada commit 16a21aa

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

apps/api/src/app/review/usecases/start-process/start-process.usecase.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { PaymentAPIService } from '@impler/services';
1212
import { QueueService } from '@shared/services/queue.service';
1313
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';
1515

1616
@Injectable()
1717
export class StartProcess {
@@ -20,7 +20,8 @@ export class StartProcess {
2020
private queueService: QueueService,
2121
private uploadRepository: UploadRepository,
2222
private amplitudeService: AmplitudeService,
23-
private paymentAPIService: PaymentAPIService
23+
private paymentAPIService: PaymentAPIService,
24+
private templateRepository: TemplateRepository
2425
) {}
2526

2627
async execute(_uploadId: string) {
@@ -43,6 +44,8 @@ export class StartProcess {
4344
});
4445
}
4546

47+
await this.updateTemplateStatistics({ uploadInfo, userEmail });
48+
4649
// if destination is frontend or not defined then complete the upload process
4750
if (
4851
!destination ||
@@ -113,4 +116,33 @@ export class StartProcess {
113116

114117
return importedData;
115118
}
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+
}
116148
}

0 commit comments

Comments
 (0)