gemcap-be-common 1.5.38 → 1.5.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.5.38",
3
+ "version": "1.5.40",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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.map((product) => {
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
- const title = `${borrower.code} ACTIVITY REPORT: ${(0, dayjs_1.default)(transactionFile.createdAt).format('MM-DD-YYYY')}`;
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
- const { transactions, transactionIdsToMark, } = await this.getTransactionReport(transactionIds, borrower._id.toString(), effectiveDate);
966
- if (transactionIdsToMark.length === 0) {
967
- return;
968
- }
969
- const attachedFile = await this.uploadsService.convertDataToFile(transactions);
970
- const attachment = { filename: `${fileName}.xlsx`, content: attachedFile };
971
- const attachedPDFs = await this.attachedFilesService.getAttachedRealFilesByTransactionFileId(borrower._id.toString(), (0, dayjs_1.default)(effectiveDate).format('YYYY-MM-DD'));
972
- let text = 'Attached is your daily activity report. Please log into the portal to view your account balance.';
973
- if (attachedPDFs.length > 0) {
974
- text = text + ' Uploaded PDF files are available for downloading.';
975
- }
976
- const email = { addresses: [...addresses, this.config.portfolioEmail], subject, text };
977
- const nodemailerService = this.getNodemailerService();
978
- await nodemailerService.sendLoanUploadReport(email, [attachment], borrower._id.toString());
979
- await Promise.all(transactionIdsToMark.map(async (id) => {
980
- await this.switchTransactionSentStatus(id, true);
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
- 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
- }));
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.map((product) => {
968
- const uploaded = mappedTransactions[product._id.toString()];
969
- const backdated = mappedBackDatedTransactions[product._id.toString()];
970
- return {
971
- [product.name]: [
972
- headerRow,
973
- ...uploaded,
974
- ...backDatedTransactionsTitle,
975
- headerRow,
976
- ...backdated,
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
- const title = `${borrower.code} ACTIVITY REPORT: ${dayjs(transactionFile.createdAt).format('MM-DD-YYYY')}`;
1042
- const fileName = title;
1043
- const subject = title;
1044
- let text = 'Attached is your daily activity report. Please log into the portal to view your account balance.';
1045
- const {
1046
- transactions,
1047
- transactionIdsToMark,
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
- const {
1081
- transactions,
1082
- transactionIdsToMark,
1083
- } = await this.getTransactionReport(transactionIds, borrower._id.toString(), effectiveDate);
1084
- if (transactionIdsToMark.length === 0) {
1085
- return;
1086
- }
1087
- const attachedFile = await this.uploadsService.convertDataToFile(transactions);
1088
- const attachment = { filename: `${fileName}.xlsx`, content: attachedFile };
1089
- const attachedPDFs = await this.attachedFilesService.getAttachedRealFilesByTransactionFileId(borrower._id.toString(), dayjs(effectiveDate).format('YYYY-MM-DD'));
1090
- let text = 'Attached is your daily activity report. Please log into the portal to view your account balance.';
1091
- if (attachedPDFs.length > 0) {
1092
- text = text + ' Uploaded PDF files are available for downloading.';
1093
- }
1094
- const email: IEmail = { addresses: [...addresses, this.config.portfolioEmail], subject, text };
1095
- const nodemailerService = this.getNodemailerService();
1096
- await nodemailerService.sendLoanUploadReport(email, [attachment], borrower._id.toString());
1097
- await Promise.all(transactionIdsToMark.map(async (id) => {
1098
- await this.switchTransactionSentStatus(id, true);
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: `${senderEmail.title} <${senderEmail.address}>`,
524
- to: email.addresses,
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,
@@ -598,8 +598,8 @@ export class NodemailerService {
598
598
  this.transporter.sendMail({
599
599
  from: `${senderEmail.title} <${senderEmail.address}>`,
600
600
  to: email.addresses,
601
- subject: email.subject,
602
601
  cc: `${senderEmail.title} <${senderEmail.address}>`,
602
+ subject: email.subject,
603
603
  text: email.subject,
604
604
  html: replacedData,
605
605
  attachments,