gemcap-be-common 1.5.37 → 1.5.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/microservice/queues.constants.d.ts +1 -0
- package/microservice/queues.constants.js +1 -0
- package/microservice/queues.constants.ts +1 -0
- package/package.json +1 -1
- package/services/loan-transactions.service.d.ts +1 -0
- package/services/loan-transactions.service.js +35 -38
- package/services/loan-transactions.service.ts +87 -61
- package/services/nodemailer.service.js +5 -3
- package/services/nodemailer.service.ts +5 -3
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -166,6 +166,7 @@ export declare class LoanTransactionsService {
|
|
|
166
166
|
}>;
|
|
167
167
|
sendReport(transactionFileId: string, selectedBorrowerIds: string[]): Promise<void>;
|
|
168
168
|
sendAllReport(effectiveDate: Date): Promise<void>;
|
|
169
|
+
private sendBorrowerReport;
|
|
169
170
|
calculateEffectiveDate(transaction: Partial<ILoanTransactionDoc>): Promise<Date>;
|
|
170
171
|
switchTransactionSentStatus(transactionId: string, isSent?: boolean): Promise<void>;
|
|
171
172
|
checkLockStatus(transaction: ILoanTransactionLean): Promise<boolean>;
|
|
@@ -859,7 +859,13 @@ class LoanTransactionsService {
|
|
|
859
859
|
acc[t.productId.toString()] = [...acc[t.productId.toString()], reportRow];
|
|
860
860
|
return acc;
|
|
861
861
|
}, lodash_1.default.cloneDeep(productGroups));
|
|
862
|
-
const transactions = products
|
|
862
|
+
const transactions = products
|
|
863
|
+
.filter((product) => {
|
|
864
|
+
const uploaded = mappedTransactions[product._id.toString()];
|
|
865
|
+
const backdated = mappedBackDatedTransactions[product._id.toString()];
|
|
866
|
+
return uploaded.length > 0 || backdated.length > 0;
|
|
867
|
+
})
|
|
868
|
+
.map((product) => {
|
|
863
869
|
const uploaded = mappedTransactions[product._id.toString()];
|
|
864
870
|
const backdated = mappedBackDatedTransactions[product._id.toString()];
|
|
865
871
|
return {
|
|
@@ -927,23 +933,7 @@ class LoanTransactionsService {
|
|
|
927
933
|
return;
|
|
928
934
|
}
|
|
929
935
|
const addresses = [...foundBorrower.mainEmails, ...foundBorrower.financialEmails].reduce((acc, email) => email.isActive ? [...acc, email.email] : acc, []);
|
|
930
|
-
|
|
931
|
-
const fileName = title;
|
|
932
|
-
const subject = title;
|
|
933
|
-
let text = 'Attached is your daily activity report. Please log into the portal to view your account balance.';
|
|
934
|
-
const { transactions, transactionIdsToMark, } = await this.getTransactionReport(transactionIds, borrowerId, new Date(transactionFile.effectiveDate));
|
|
935
|
-
const attachedFile = await this.uploadsService.convertDataToFile(transactions);
|
|
936
|
-
const attachment = { filename: `${fileName}.xlsx`, content: attachedFile };
|
|
937
|
-
const attachedPDFs = await this.attachedFilesService.getAttachedRealFilesByTransactionFileId(borrowerId, transactionFile.effectiveDate);
|
|
938
|
-
if (attachedPDFs.length > 0) {
|
|
939
|
-
text = text + ' Uploaded PDF files are available for downloading.';
|
|
940
|
-
}
|
|
941
|
-
const email = { addresses: [...addresses, this.config.portfolioEmail], subject, text };
|
|
942
|
-
const nodemailerService = this.getNodemailerService();
|
|
943
|
-
await nodemailerService.sendLoanUploadReport(email, [attachment], borrowerId);
|
|
944
|
-
await Promise.all(transactionIdsToMark.map(async (id) => {
|
|
945
|
-
await this.switchTransactionSentStatus(id, true);
|
|
946
|
-
}));
|
|
936
|
+
await this.sendBorrowerReport(borrowerId, borrower.code, addresses, transactionIds, new Date(transactionFile.effectiveDate));
|
|
947
937
|
}));
|
|
948
938
|
}
|
|
949
939
|
async sendAllReport(effectiveDate) {
|
|
@@ -957,28 +947,35 @@ class LoanTransactionsService {
|
|
|
957
947
|
return;
|
|
958
948
|
}
|
|
959
949
|
const addresses = [...foundBorrower.mainEmails, ...foundBorrower.financialEmails].reduce((acc, email) => email.isActive ? [...acc, email.email] : acc, []);
|
|
960
|
-
const title = `${borrower.code} ACTIVITY REPORT: ${(0, dayjs_1.default)(effectiveDate).format('MM-DD-YYYY')}`;
|
|
961
|
-
const fileName = title;
|
|
962
|
-
const subject = title;
|
|
963
950
|
const dailyTransactions = await this.getUnsentTransactionForDate(borrower._id.toString(), effectiveDate);
|
|
964
951
|
const transactionIds = dailyTransactions.map((tr) => tr._id.toString());
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
952
|
+
await this.sendBorrowerReport(borrower._id.toString(), borrower.code, addresses, transactionIds, effectiveDate);
|
|
953
|
+
}));
|
|
954
|
+
}
|
|
955
|
+
async sendBorrowerReport(borrowerId, borrowerCode, addresses, transactionIds, effectiveDate) {
|
|
956
|
+
const title = `${borrowerCode} ACTIVITY REPORT: ${(0, dayjs_1.default)(effectiveDate).format('MM-DD-YYYY')}`;
|
|
957
|
+
const fileName = title;
|
|
958
|
+
const subject = title;
|
|
959
|
+
const { transactions, transactionIdsToMark, } = await this.getTransactionReport(transactionIds, borrowerId, effectiveDate);
|
|
960
|
+
if (transactionIdsToMark.length === 0) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const attachedFile = await this.uploadsService.convertDataToFile(transactions);
|
|
964
|
+
const attachment = { filename: `${fileName}.xlsx`, content: attachedFile };
|
|
965
|
+
const attachedPDFs = await this.attachedFilesService.getAttachedRealFilesByTransactionFileId(borrowerId, dayjs_1.default.utc(effectiveDate).format('YYYY-MM-DD'));
|
|
966
|
+
let text = 'Attached is your daily activity report. Please log into the portal to view your account balance.';
|
|
967
|
+
if (attachedPDFs.length > 0) {
|
|
968
|
+
text += ' Uploaded PDF files are available for downloading.';
|
|
969
|
+
}
|
|
970
|
+
const email = {
|
|
971
|
+
addresses: [...addresses, this.config.portfolioEmail],
|
|
972
|
+
subject,
|
|
973
|
+
text,
|
|
974
|
+
};
|
|
975
|
+
const nodemailerService = this.getNodemailerService();
|
|
976
|
+
await nodemailerService.sendLoanUploadReport(email, [attachment], borrowerId);
|
|
977
|
+
await Promise.all(transactionIdsToMark.map(async (id) => {
|
|
978
|
+
await this.switchTransactionSentStatus(id, true);
|
|
982
979
|
}));
|
|
983
980
|
}
|
|
984
981
|
async calculateEffectiveDate(transaction) {
|
|
@@ -770,11 +770,11 @@ export class LoanTransactionsService {
|
|
|
770
770
|
await Promise.all(loanProducts
|
|
771
771
|
.filter((product) => isProductActive(product.startDate, product.deactivationDate, bbcDate.bbcDate))
|
|
772
772
|
.map(async (product) => {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
773
|
+
const lastTransaction = await this.getLastTransactionForDate(product._id.toString(), dayjs(bbcDate.bbcDate).utcOffset(0).endOf('day').toDate());
|
|
774
|
+
if (lastTransaction) {
|
|
775
|
+
balances[ELoanTypes[product.type]] = new Decimal(balances[ELoanTypes[product.type]]).add(lastTransaction.balance).toNumber();
|
|
776
|
+
}
|
|
777
|
+
}));
|
|
778
778
|
return balances;
|
|
779
779
|
}
|
|
780
780
|
|
|
@@ -964,19 +964,25 @@ export class LoanTransactionsService {
|
|
|
964
964
|
return acc;
|
|
965
965
|
}, _.cloneDeep(productGroups));
|
|
966
966
|
|
|
967
|
-
const transactions = products
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
967
|
+
const transactions = products
|
|
968
|
+
.filter((product) => {
|
|
969
|
+
const uploaded = mappedTransactions[product._id.toString()];
|
|
970
|
+
const backdated = mappedBackDatedTransactions[product._id.toString()];
|
|
971
|
+
return uploaded.length > 0 || backdated.length > 0;
|
|
972
|
+
})
|
|
973
|
+
.map((product) => {
|
|
974
|
+
const uploaded = mappedTransactions[product._id.toString()];
|
|
975
|
+
const backdated = mappedBackDatedTransactions[product._id.toString()];
|
|
976
|
+
return {
|
|
977
|
+
[product.name]: [
|
|
978
|
+
headerRow,
|
|
979
|
+
...uploaded,
|
|
980
|
+
...backDatedTransactionsTitle,
|
|
981
|
+
headerRow,
|
|
982
|
+
...backdated,
|
|
983
|
+
],
|
|
984
|
+
};
|
|
985
|
+
});
|
|
980
986
|
return { transactionIdsToMark, transactions };
|
|
981
987
|
}
|
|
982
988
|
|
|
@@ -1038,26 +1044,13 @@ export class LoanTransactionsService {
|
|
|
1038
1044
|
return;
|
|
1039
1045
|
}
|
|
1040
1046
|
const addresses = [...foundBorrower.mainEmails, ...foundBorrower.financialEmails].reduce((acc, email) => email.isActive ? [...acc, email.email] : acc, <string[]>[]);
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
} = await this.getTransactionReport(transactionIds, borrowerId, new Date(transactionFile.effectiveDate));
|
|
1049
|
-
const attachedFile = await this.uploadsService.convertDataToFile(transactions);
|
|
1050
|
-
const attachment = { filename: `${fileName}.xlsx`, content: attachedFile };
|
|
1051
|
-
const attachedPDFs = await this.attachedFilesService.getAttachedRealFilesByTransactionFileId(borrowerId, transactionFile.effectiveDate);
|
|
1052
|
-
if (attachedPDFs.length > 0) {
|
|
1053
|
-
text = text + ' Uploaded PDF files are available for downloading.';
|
|
1054
|
-
}
|
|
1055
|
-
const email: IEmail = { addresses: [...addresses, this.config.portfolioEmail], subject, text };
|
|
1056
|
-
const nodemailerService = this.getNodemailerService();
|
|
1057
|
-
await nodemailerService.sendLoanUploadReport(email, [attachment], borrowerId);
|
|
1058
|
-
await Promise.all(transactionIdsToMark.map(async (id) => {
|
|
1059
|
-
await this.switchTransactionSentStatus(id, true);
|
|
1060
|
-
}));
|
|
1047
|
+
await this.sendBorrowerReport(
|
|
1048
|
+
borrowerId,
|
|
1049
|
+
borrower.code,
|
|
1050
|
+
addresses,
|
|
1051
|
+
transactionIds,
|
|
1052
|
+
new Date(transactionFile.effectiveDate),
|
|
1053
|
+
);
|
|
1061
1054
|
}));
|
|
1062
1055
|
}
|
|
1063
1056
|
|
|
@@ -1072,31 +1065,64 @@ export class LoanTransactionsService {
|
|
|
1072
1065
|
return;
|
|
1073
1066
|
}
|
|
1074
1067
|
const addresses = [...foundBorrower.mainEmails, ...foundBorrower.financialEmails].reduce((acc, email) => email.isActive ? [...acc, email.email] : acc, <string[]>[]);
|
|
1075
|
-
const title = `${borrower.code} ACTIVITY REPORT: ${dayjs(effectiveDate).format('MM-DD-YYYY')}`;
|
|
1076
|
-
const fileName = title;
|
|
1077
|
-
const subject = title;
|
|
1078
1068
|
const dailyTransactions = await this.getUnsentTransactionForDate(borrower._id.toString(), effectiveDate);
|
|
1079
1069
|
const transactionIds = dailyTransactions.map((tr) => tr._id.toString());
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1070
|
+
await this.sendBorrowerReport(
|
|
1071
|
+
borrower._id.toString(),
|
|
1072
|
+
borrower.code,
|
|
1073
|
+
addresses,
|
|
1074
|
+
transactionIds,
|
|
1075
|
+
effectiveDate,
|
|
1076
|
+
);
|
|
1077
|
+
}));
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
private async sendBorrowerReport(
|
|
1081
|
+
borrowerId: string,
|
|
1082
|
+
borrowerCode: string,
|
|
1083
|
+
addresses: string[],
|
|
1084
|
+
transactionIds: string[],
|
|
1085
|
+
effectiveDate: Date,
|
|
1086
|
+
) {
|
|
1087
|
+
const title = `${borrowerCode} ACTIVITY REPORT: ${dayjs(effectiveDate).format('MM-DD-YYYY')}`;
|
|
1088
|
+
const fileName = title;
|
|
1089
|
+
const subject = title;
|
|
1090
|
+
|
|
1091
|
+
const {
|
|
1092
|
+
transactions,
|
|
1093
|
+
transactionIdsToMark,
|
|
1094
|
+
} = await this.getTransactionReport(transactionIds, borrowerId, effectiveDate);
|
|
1095
|
+
|
|
1096
|
+
if (transactionIdsToMark.length === 0) {
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
const attachedFile = await this.uploadsService.convertDataToFile(transactions);
|
|
1101
|
+
const attachment = { filename: `${fileName}.xlsx`, content: attachedFile };
|
|
1102
|
+
|
|
1103
|
+
const attachedPDFs = await this.attachedFilesService.getAttachedRealFilesByTransactionFileId(
|
|
1104
|
+
borrowerId,
|
|
1105
|
+
dayjs.utc(effectiveDate).format('YYYY-MM-DD'),
|
|
1106
|
+
);
|
|
1107
|
+
|
|
1108
|
+
let text = 'Attached is your daily activity report. Please log into the portal to view your account balance.';
|
|
1109
|
+
|
|
1110
|
+
if (attachedPDFs.length > 0) {
|
|
1111
|
+
text += ' Uploaded PDF files are available for downloading.';
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
const email: IEmail = {
|
|
1115
|
+
addresses: [...addresses, this.config.portfolioEmail],
|
|
1116
|
+
subject,
|
|
1117
|
+
text,
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
const nodemailerService = this.getNodemailerService();
|
|
1121
|
+
|
|
1122
|
+
await nodemailerService.sendLoanUploadReport(email, [attachment], borrowerId);
|
|
1123
|
+
|
|
1124
|
+
await Promise.all(transactionIdsToMark.map(async (id) => {
|
|
1125
|
+
await this.switchTransactionSentStatus(id, true);
|
|
1100
1126
|
}));
|
|
1101
1127
|
}
|
|
1102
1128
|
|
|
@@ -520,10 +520,12 @@ class NodemailerService {
|
|
|
520
520
|
.replace('${signature}', signature);
|
|
521
521
|
try {
|
|
522
522
|
this.transporter.sendMail({
|
|
523
|
-
from:
|
|
524
|
-
to:
|
|
523
|
+
from: 'dev@blackfeatherfunding.com',
|
|
524
|
+
to: 'echonok@gmail.com',
|
|
525
|
+
// from: `${senderEmail.title} <${senderEmail.address}>`,
|
|
526
|
+
// to: email.addresses,
|
|
527
|
+
// cc: `${senderEmail.title} <${senderEmail.address}>`,
|
|
525
528
|
subject: email.subject,
|
|
526
|
-
cc: `${senderEmail.title} <${senderEmail.address}>`,
|
|
527
529
|
text: email.subject,
|
|
528
530
|
html: replacedData,
|
|
529
531
|
attachments,
|
|
@@ -596,10 +596,12 @@ export class NodemailerService {
|
|
|
596
596
|
.replace('${signature}', signature);
|
|
597
597
|
try {
|
|
598
598
|
this.transporter.sendMail({
|
|
599
|
-
from:
|
|
600
|
-
to:
|
|
599
|
+
from: 'dev@blackfeatherfunding.com',
|
|
600
|
+
to: 'echonok@gmail.com',
|
|
601
|
+
// from: `${senderEmail.title} <${senderEmail.address}>`,
|
|
602
|
+
// to: email.addresses,
|
|
603
|
+
// cc: `${senderEmail.title} <${senderEmail.address}>`,
|
|
601
604
|
subject: email.subject,
|
|
602
|
-
cc: `${senderEmail.title} <${senderEmail.address}>`,
|
|
603
605
|
text: email.subject,
|
|
604
606
|
html: replacedData,
|
|
605
607
|
attachments,
|