Skip to content

Commit af89bb1

Browse files
author
Mayur
committed
feat: Added the statistics and usage count on templates for manual data entry method
1 parent 1677d6a commit af89bb1

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

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

Lines changed: 36 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) {
@@ -52,12 +53,16 @@ export class StartProcess {
5253
{ _id: _uploadId },
5354
{ status: UploadStatusEnum.COMPLETED }
5455
);
56+
57+
await this.updateTemplateStatistics({ uploadInfo, userEmail });
5558
} else {
5659
// if template destination has callbackUrl then start sending data to the callbackUrl
5760
uploadInfo = await this.uploadRepository.findOneAndUpdate(
5861
{ _id: _uploadId },
5962
{ status: UploadStatusEnum.PROCESSING }
6063
);
64+
65+
await this.updateTemplateStatistics({ uploadInfo, userEmail });
6166
}
6267

6368
this.amplitudeService.recordsImported(userEmail, {
@@ -113,4 +118,33 @@ export class StartProcess {
113118

114119
return importedData;
115120
}
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+
}
116150
}

0 commit comments

Comments
 (0)