gemcap-be-common 1.2.140 → 1.3.0
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/classes/bank-transaction-item.d.ts +17 -0
- package/classes/bank-transaction-item.js +64 -0
- package/classes/bank-transaction-item.ts +66 -0
- package/classes/bank-uploaded-transaction.d.ts +17 -0
- package/classes/bank-uploaded-transaction.js +35 -0
- package/classes/bank-uploaded-transaction.ts +35 -0
- package/classes/inventory-item.d.ts +41 -0
- package/classes/inventory-item.js +44 -0
- package/classes/inventory-item.ts +63 -0
- package/classes/payable-account-item.d.ts +22 -0
- package/classes/payable-account-item.js +27 -0
- package/classes/payable-account-item.ts +35 -0
- package/classes/quickbook-item.d.ts +37 -0
- package/classes/quickbook-item.js +51 -0
- package/classes/quickbook-item.ts +59 -0
- package/classes/receivable-item.d.ts +26 -0
- package/classes/receivable-item.js +28 -0
- package/classes/receivable-item.ts +38 -0
- package/constants/date-formats.contsants.d.ts +1 -0
- package/constants/date-formats.contsants.js +4 -0
- package/constants/date-formats.contsants.ts +1 -0
- package/db/brokers.db.d.ts +185 -0
- package/db/brokers.db.js +35 -2
- package/db/brokers.db.ts +34 -1
- package/db/collateral-adjustments.db.d.ts +34 -0
- package/db/collateral-adjustments.db.js +52 -0
- package/db/collateral-adjustments.db.ts +54 -0
- package/db/collaterals.db.d.ts +1 -1
- package/db/equipment.db.d.ts +40 -0
- package/db/equipment.db.js +55 -0
- package/db/equipment.db.ts +56 -0
- package/db/financial-spreading.db.ts +2 -1
- package/db/groups.d.ts +5 -0
- package/db/groups.js +57 -0
- package/db/groups.ts +52 -0
- package/db/inventories.d.ts +91 -0
- package/db/inventories.js +449 -0
- package/db/inventories.ts +481 -0
- package/db/inventory-availability.d.ts +3 -0
- package/db/inventory-availability.js +103 -0
- package/db/inventory-availability.ts +113 -0
- package/db/new-summary.d.ts +31 -0
- package/db/new-summary.js +1295 -0
- package/db/new-summary.ts +1509 -0
- package/db/payable-accounts.d.ts +30 -0
- package/db/payable-accounts.js +55 -0
- package/db/payable-accounts.ts +50 -0
- package/db/reserve.db.d.ts +34 -0
- package/db/reserve.db.js +52 -0
- package/db/reserve.db.ts +48 -0
- package/db/uploads.db.d.ts +2 -0
- package/db/uploads.db.js +29 -0
- package/db/uploads.db.ts +24 -0
- package/helpers/main.helper.d.ts +31 -0
- package/helpers/main.helper.js +63 -0
- package/helpers/main.helper.ts +63 -0
- package/models/AccountPayableItem.model.d.ts +6 -6
- package/models/AllocatedBankTransaction.model.d.ts +54 -0
- package/models/AllocatedBankTransaction.model.js +70 -0
- package/models/AllocatedBankTransaction.model.ts +94 -0
- package/models/AllocatedData.model.d.ts +33 -0
- package/models/AllocatedData.model.js +19 -0
- package/models/AllocatedData.model.ts +24 -0
- package/models/BBCDate.model.d.ts +3 -3
- package/models/BBCSheet.model.d.ts +3 -3
- package/models/Banks.model.d.ts +3 -3
- package/models/Borrower.model.d.ts +3 -3
- package/models/BorrowerData.model.d.ts +3 -3
- package/models/BorrowerDataInsurance.model.d.ts +3 -3
- package/models/BorrowerDataTerm.model.d.ts +3 -3
- package/models/BorrowerSummary.model.js +1 -1
- package/models/BorrowerSummary.model.ts +1 -1
- package/models/CalandarDay.model.d.ts +40 -0
- package/models/CalandarDay.model.js +47 -0
- package/models/CalandarDay.model.ts +61 -0
- package/models/CashAllocationProduct.model.d.ts +119 -0
- package/models/CashAllocationProduct.model.js +102 -0
- package/models/CashAllocationProduct.model.ts +112 -0
- package/models/CashAllocationReference.model.d.ts +37 -0
- package/models/CashAllocationReference.model.js +27 -0
- package/models/CashAllocationReference.model.ts +40 -0
- package/models/CollateralAdjustment.model.d.ts +51 -0
- package/models/CollateralAdjustment.model.js +61 -0
- package/models/CollateralAdjustment.model.ts +98 -0
- package/models/Company.model.d.ts +35 -0
- package/models/Company.model.js +18 -0
- package/models/Company.model.ts +29 -0
- package/models/CustomerAPGroup.model.d.ts +32 -0
- package/models/CustomerAPGroup.model.js +24 -0
- package/models/CustomerAPGroup.model.ts +31 -0
- package/models/Equipment.model.d.ts +53 -0
- package/models/Equipment.model.js +140 -0
- package/models/Equipment.model.ts +172 -0
- package/models/FinancialCompliance.model.d.ts +39 -0
- package/models/FinancialCompliance.model.js +64 -0
- package/models/FinancialCompliance.model.ts +78 -0
- package/models/FinancialComplianceBorrower.model.d.ts +58 -0
- package/models/FinancialComplianceBorrower.model.js +82 -0
- package/models/FinancialComplianceBorrower.model.ts +118 -0
- package/models/FinancialIndexes.model.d.ts +36 -0
- package/models/FinancialIndexes.model.js +27 -0
- package/models/FinancialIndexes.model.ts +37 -0
- package/models/Inventory.model.d.ts +18 -18
- package/models/InventoryAvailability.model.d.ts +21 -21
- package/models/InventoryAvailabilityItem.model.d.ts +6 -6
- package/models/InventoryItem.model.d.ts +24 -24
- package/models/InventoryManualEntry.model.d.ts +9 -9
- package/models/InventorySeasonalRates.model.d.ts +3 -3
- package/models/LoanBroker.model.d.ts +3 -3
- package/models/LoanCharges.model.d.ts +12 -12
- package/models/LoanProducts.model.d.ts +9 -9
- package/models/LoanStatementStatus.model.d.ts +35 -0
- package/models/LoanStatementStatus.model.js +34 -0
- package/models/LoanStatementStatus.model.ts +45 -0
- package/models/LoanStatementTransaction.model.d.ts +9 -9
- package/models/LoanTransactionFile.model.d.ts +41 -0
- package/models/LoanTransactionFile.model.js +44 -0
- package/models/LoanTransactionFile.model.ts +61 -0
- package/models/MappedGroup.model.d.ts +37 -0
- package/models/MappedGroup.model.js +33 -0
- package/models/MappedGroup.model.ts +46 -0
- package/models/MonthEndData.Model.d.ts +41 -0
- package/models/MonthEndData.Model.js +42 -0
- package/models/MonthEndData.Model.ts +53 -0
- package/models/OrganizationEmails.model.d.ts +44 -0
- package/models/OrganizationEmails.model.js +40 -0
- package/models/OrganizationEmails.model.ts +54 -0
- package/models/ProductBroker.model.d.ts +9 -9
- package/models/QuickbooksAccount.model.d.ts +39 -0
- package/models/QuickbooksAccount.model.js +43 -0
- package/models/QuickbooksAccount.model.ts +57 -0
- package/models/Receivable.model.d.ts +12 -12
- package/models/ReceivableAvailability.model.d.ts +54 -54
- package/models/ReceivableAvailabilityItem.model.d.ts +57 -57
- package/models/ReceivableItem.model.d.ts +6 -6
- package/models/Reserve.model.d.ts +51 -0
- package/models/Reserve.model.js +96 -0
- package/models/Reserve.model.ts +125 -0
- package/models/TermLoan.model.d.ts +3 -3
- package/models/TermLoanCalculated.model.d.ts +6 -6
- package/models/TransactionAttachedFile.Model.d.ts +35 -0
- package/models/TransactionAttachedFile.Model.js +37 -0
- package/models/TransactionAttachedFile.Model.ts +48 -0
- package/models/UploadedBankTransaction.model.d.ts +56 -0
- package/models/UploadedBankTransaction.model.js +78 -0
- package/models/UploadedBankTransaction.model.ts +110 -0
- package/models/UploadedData.model.d.ts +36 -0
- package/models/UploadedData.model.js +23 -0
- package/models/UploadedData.model.ts +35 -0
- package/models/UploadedFile.model.d.ts +40 -0
- package/models/UploadedFile.model.js +41 -0
- package/models/UploadedFile.model.ts +57 -0
- package/models/UploadedSheet.model.d.ts +46 -0
- package/models/UploadedSheet.model.js +27 -0
- package/models/UploadedSheet.model.ts +51 -0
- package/package.json +10 -1
- package/repositories/globals.repository.d.ts +8 -0
- package/repositories/globals.repository.js +24 -0
- package/repositories/globals.repository.ts +21 -0
- package/services/attached-files.service.d.ts +57 -0
- package/services/attached-files.service.js +103 -0
- package/services/attached-files.service.ts +123 -0
- package/services/availability.service.d.ts +77 -0
- package/services/availability.service.js +897 -0
- package/services/availability.service.ts +1034 -0
- package/services/bank-uploaded-transactions.service.d.ts +33 -0
- package/services/bank-uploaded-transactions.service.js +430 -0
- package/services/bank-uploaded-transactions.service.ts +475 -0
- package/services/banks.service.d.ts +36 -0
- package/services/banks.service.js +91 -0
- package/services/banks.service.ts +95 -0
- package/services/borrower-summary.service.d.ts +35 -0
- package/services/borrower-summary.service.js +310 -0
- package/services/borrower-summary.service.ts +334 -0
- package/services/borrowers.service.d.ts +103 -0
- package/services/borrowers.service.js +268 -0
- package/services/borrowers.service.ts +302 -0
- package/services/brokers.service.d.ts +212 -0
- package/services/brokers.service.js +160 -0
- package/services/brokers.service.ts +200 -0
- package/services/calendar.service.d.ts +53 -0
- package/services/calendar.service.js +108 -0
- package/services/calendar.service.ts +128 -0
- package/services/cash-allocation.service.d.ts +40 -0
- package/services/cash-allocation.service.js +92 -0
- package/services/cash-allocation.service.ts +105 -0
- package/services/collateral-adjustments.service.d.ts +38 -0
- package/services/collateral-adjustments.service.js +82 -0
- package/services/collateral-adjustments.service.ts +95 -0
- package/services/collaterals.service.d.ts +69 -0
- package/services/collaterals.service.js +279 -0
- package/services/collaterals.service.ts +319 -0
- package/services/companies.service.d.ts +5 -0
- package/services/companies.service.js +21 -0
- package/services/companies.service.ts +23 -0
- package/services/compliance-borrowers.service.d.ts +152 -0
- package/services/compliance-borrowers.service.js +569 -0
- package/services/compliance-borrowers.service.ts +617 -0
- package/services/equipment.service.d.ts +42 -0
- package/services/equipment.service.js +120 -0
- package/services/equipment.service.ts +149 -0
- package/services/file-manager.service.d.ts +44 -0
- package/services/file-manager.service.js +120 -0
- package/services/file-manager.service.ts +146 -0
- package/services/financial-compliance.service.d.ts +58 -0
- package/services/financial-compliance.service.js +281 -0
- package/services/financial-compliance.service.ts +309 -0
- package/services/financial-indexes.service.d.ts +20 -0
- package/services/financial-indexes.service.js +241 -0
- package/services/financial-indexes.service.ts +257 -0
- package/services/financial-spreading.service.d.ts +74 -0
- package/services/financial-spreading.service.js +450 -0
- package/services/financial-spreading.service.ts +517 -0
- package/services/globals.service.d.ts +5 -0
- package/services/globals.service.js +11 -0
- package/services/globals.service.ts +8 -0
- package/services/groups.service.d.ts +39 -0
- package/services/groups.service.js +65 -0
- package/services/groups.service.ts +64 -0
- package/services/inventory-availability.service.d.ts +13 -0
- package/services/inventory-availability.service.js +170 -0
- package/services/inventory-availability.service.ts +187 -0
- package/services/inventory.service.d.ts +118 -0
- package/services/inventory.service.js +239 -0
- package/services/inventory.service.ts +276 -0
- package/services/loan-charges.service.d.ts +83 -0
- package/services/loan-charges.service.js +343 -0
- package/services/loan-charges.service.ts +396 -0
- package/services/loan-payments.service.d.ts +94 -0
- package/services/loan-payments.service.js +485 -0
- package/services/loan-payments.service.ts +541 -0
- package/services/loan-products.service.d.ts +12 -0
- package/services/loan-products.service.js +55 -0
- package/services/loan-products.service.ts +58 -0
- package/services/loan-statement-balance.service.d.ts +16 -0
- package/services/loan-statement-balance.service.js +106 -0
- package/services/loan-statement-balance.service.ts +113 -0
- package/services/loan-statement-effects.service.d.ts +8 -0
- package/services/loan-statement-effects.service.js +42 -0
- package/services/loan-statement-effects.service.ts +41 -0
- package/services/loan-statement-status.service.d.ts +208 -0
- package/services/loan-statement-status.service.js +159 -0
- package/services/loan-statement-status.service.ts +177 -0
- package/services/loan-statement.service.d.ts +186 -0
- package/services/loan-statement.service.js +935 -0
- package/services/loan-statement.service.ts +1040 -0
- package/services/loan-transactions.service.d.ts +169 -0
- package/services/loan-transactions.service.js +941 -0
- package/services/loan-transactions.service.ts +1042 -0
- package/services/lock.service.d.ts +6 -0
- package/services/lock.service.js +45 -0
- package/services/lock.service.ts +45 -0
- package/services/manual-entry.service.d.ts +20 -0
- package/services/manual-entry.service.js +186 -0
- package/services/manual-entry.service.ts +201 -0
- package/services/month-end-data.service.d.ts +34 -0
- package/services/month-end-data.service.js +30 -0
- package/services/month-end-data.service.ts +35 -0
- package/services/nodemailer.service.d.ts +96 -0
- package/services/nodemailer.service.js +689 -0
- package/services/nodemailer.service.ts +774 -0
- package/services/organization-emails.service.d.ts +31 -0
- package/services/organization-emails.service.js +10 -0
- package/services/organization-emails.service.ts +7 -0
- package/services/organizations.service.d.ts +34 -0
- package/services/organizations.service.js +74 -0
- package/services/organizations.service.ts +84 -0
- package/services/pdf.service.d.ts +61 -0
- package/services/pdf.service.js +547 -0
- package/services/pdf.service.ts +642 -0
- package/services/quickbooks.service.d.ts +99 -0
- package/services/quickbooks.service.js +640 -0
- package/services/quickbooks.service.ts +734 -0
- package/services/reports/investor-summary.service.d.ts +28 -0
- package/services/reports/investor-summary.service.js +136 -0
- package/services/reports/investor-summary.service.ts +159 -0
- package/services/reports.service.d.ts +126 -0
- package/services/reports.service.js +584 -0
- package/services/reports.service.ts +702 -0
- package/services/reserve.service.d.ts +37 -0
- package/services/reserve.service.js +76 -0
- package/services/reserve.service.ts +79 -0
- package/services/sentry.service.d.ts +11 -0
- package/services/sentry.service.js +49 -0
- package/services/sentry.service.ts +33 -0
- package/services/signs.service.d.ts +69 -0
- package/services/signs.service.js +230 -0
- package/services/signs.service.ts +260 -0
- package/services/term-loan.service.d.ts +30 -0
- package/services/term-loan.service.js +614 -0
- package/services/term-loan.service.ts +696 -0
- package/services/uploads.service.d.ts +134 -0
- package/services/uploads.service.js +587 -0
- package/services/uploads.service.ts +643 -0
- package/services/user-logs.service.d.ts +23 -0
- package/services/user-logs.service.js +160 -0
- package/services/user-logs.service.ts +177 -0
- package/services/users.service.d.ts +4 -4
- package/services/yield.service.d.ts +46 -0
- package/services/yield.service.js +42 -12
- package/services/yield.service.ts +38 -8
- package/tsconfig.json +5 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UserLogsService = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const user_logs_db_1 = require("../db/user-logs.db");
|
|
9
|
+
const UserLog_model_1 = require("../models/UserLog.model");
|
|
10
|
+
const DeletedRecords_model_1 = require("../models/DeletedRecords.model");
|
|
11
|
+
const createLogs = true;
|
|
12
|
+
class UserLogsService {
|
|
13
|
+
banksService;
|
|
14
|
+
borrowerService;
|
|
15
|
+
loanChargesService;
|
|
16
|
+
constructor(banksService, borrowerService, loanChargesService) {
|
|
17
|
+
this.banksService = banksService;
|
|
18
|
+
this.borrowerService = borrowerService;
|
|
19
|
+
this.loanChargesService = loanChargesService;
|
|
20
|
+
}
|
|
21
|
+
async createUserLog(params) {
|
|
22
|
+
if (createLogs) {
|
|
23
|
+
await (0, user_logs_db_1.createLog)(params);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async filterByBorrower(logs, borrowerId) {
|
|
27
|
+
const products = await this.loanChargesService.getBorrowersLoanProducts(borrowerId);
|
|
28
|
+
const productIds = products.map((product) => product._id.toString());
|
|
29
|
+
return logs.filter((r) => {
|
|
30
|
+
if (r.logType === UserLog_model_1.ELogType.LOAN_TRANSACTION && r.record) {
|
|
31
|
+
return productIds.includes(r.record.productId.toString());
|
|
32
|
+
}
|
|
33
|
+
if (r.details && r.details.hasOwnProperty('borrowerId')) {
|
|
34
|
+
if (r.details.borrowerId && r.details.borrowerId === borrowerId) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async replaceBorrowers(logs) {
|
|
42
|
+
const convertToMap = (arr) => {
|
|
43
|
+
return arr.reduce((acc, item) => {
|
|
44
|
+
acc.set(item._id.toString(), item.name);
|
|
45
|
+
return acc;
|
|
46
|
+
}, new Map());
|
|
47
|
+
};
|
|
48
|
+
const borrowers = await this.borrowerService.getAllBorrowers();
|
|
49
|
+
const borrowersMap = convertToMap(borrowers);
|
|
50
|
+
const products = await this.loanChargesService.getAllLoanProducts();
|
|
51
|
+
const productsMap = convertToMap(products);
|
|
52
|
+
const banks = await this.banksService.getBanks();
|
|
53
|
+
const banksMap = convertToMap(banks);
|
|
54
|
+
const replacedFields = {
|
|
55
|
+
borrowerId: borrowersMap,
|
|
56
|
+
productId: productsMap,
|
|
57
|
+
bankId: banksMap,
|
|
58
|
+
};
|
|
59
|
+
return logs.map((r) => {
|
|
60
|
+
Object.keys(replacedFields).forEach((key) => {
|
|
61
|
+
if (r.details && r.details.hasOwnProperty(key) && r.details[key]) {
|
|
62
|
+
r.details[key] = `${replacedFields[key].get(r.details[key].toString())} (${r.details[key].toString()})`;
|
|
63
|
+
}
|
|
64
|
+
if (r.record && r.record.hasOwnProperty(key) && r.record[key]) {
|
|
65
|
+
r.record[key] = `${replacedFields[key].get(r.record[key].toString())} (${r.record[key].toString()})`;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async performDynamicLookup(record) {
|
|
71
|
+
try {
|
|
72
|
+
const { _id, recordCollection } = record;
|
|
73
|
+
if (!recordCollection) {
|
|
74
|
+
return record;
|
|
75
|
+
}
|
|
76
|
+
const pipeline = [
|
|
77
|
+
{
|
|
78
|
+
$match: {
|
|
79
|
+
_id,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
$lookup: {
|
|
84
|
+
from: recordCollection,
|
|
85
|
+
localField: 'recordId',
|
|
86
|
+
foreignField: '_id',
|
|
87
|
+
as: 'record',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
$unwind: {
|
|
92
|
+
path: '$record',
|
|
93
|
+
preserveNullAndEmptyArrays: true,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
const result = await UserLog_model_1.UserLog.aggregate(pipeline);
|
|
98
|
+
if (result.length > 0 && result[0]) {
|
|
99
|
+
const foundRecord = result[0].record;
|
|
100
|
+
if (!foundRecord) {
|
|
101
|
+
const deletedRecord = await DeletedRecords_model_1.DeletedRecord
|
|
102
|
+
.findOne({ DBCollection: recordCollection, recordId: record.recordId })
|
|
103
|
+
.lean();
|
|
104
|
+
if (deletedRecord) {
|
|
105
|
+
result[0].record = deletedRecord.record;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result[0];
|
|
109
|
+
}
|
|
110
|
+
return record;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error('Error performing dynamic lookup:', error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async getLogs(filter) {
|
|
118
|
+
const logs = await UserLog_model_1.UserLog.aggregate([
|
|
119
|
+
{
|
|
120
|
+
$match: {
|
|
121
|
+
$and: [
|
|
122
|
+
{ 'timestamp': { $gte: filter.periodStart } },
|
|
123
|
+
{ 'timestamp': { $lte: filter.periodEnd } },
|
|
124
|
+
filter.userId ? { 'userId': new mongoose_1.default.Types.ObjectId(filter.userId) } : {},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
$sort: {
|
|
130
|
+
'timestamp': 1,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
]);
|
|
134
|
+
const logsWithRecord = await Promise.all(logs.map(async (log) => await this.performDynamicLookup(log)));
|
|
135
|
+
const filteredByBorrowers = !filter.borrowerId
|
|
136
|
+
? logsWithRecord.slice()
|
|
137
|
+
: await this.filterByBorrower(logsWithRecord, filter.borrowerId);
|
|
138
|
+
await this.replaceBorrowers(filteredByBorrowers);
|
|
139
|
+
return filteredByBorrowers;
|
|
140
|
+
}
|
|
141
|
+
async getDocumentLogs(documentId) {
|
|
142
|
+
const logs = await UserLog_model_1.UserLog.aggregate([
|
|
143
|
+
{
|
|
144
|
+
$match: {
|
|
145
|
+
$and: [
|
|
146
|
+
{ 'recordCollection': 'loan_transactions' },
|
|
147
|
+
{ 'recordId': new mongoose_1.default.Types.ObjectId(documentId) },
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
$sort: {
|
|
153
|
+
'timestamp': 1,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
]);
|
|
157
|
+
return await Promise.all(logs.map(async (log) => await this.performDynamicLookup(log)));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.UserLogsService = UserLogsService;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
import { createLog, ICreateLogParams } from '../db/user-logs.db';
|
|
4
|
+
import { ELogType, IUserLog, IUserLogWithLookup, UserLog } from '../models/UserLog.model';
|
|
5
|
+
import { DeletedRecord } from '../models/DeletedRecords.model';
|
|
6
|
+
|
|
7
|
+
import { BanksService } from './banks.service';
|
|
8
|
+
import { BorrowerService } from './borrowers.service';
|
|
9
|
+
import { LoanChargesService } from './loan-charges.service';
|
|
10
|
+
|
|
11
|
+
export interface IUserLogFilter {
|
|
12
|
+
userId: string;
|
|
13
|
+
borrowerId: string;
|
|
14
|
+
periodStart: Date;
|
|
15
|
+
periodEnd: Date;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const createLogs = true;
|
|
19
|
+
|
|
20
|
+
export class UserLogsService {
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly banksService: BanksService,
|
|
24
|
+
private readonly borrowerService: BorrowerService,
|
|
25
|
+
private readonly loanChargesService: LoanChargesService,
|
|
26
|
+
) {
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async createUserLog(params: ICreateLogParams) {
|
|
30
|
+
if (createLogs) {
|
|
31
|
+
await createLog(params);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async filterByBorrower(logs: IUserLogWithLookup[], borrowerId: string): Promise<IUserLogWithLookup[]> {
|
|
36
|
+
const products = await this.loanChargesService.getBorrowersLoanProducts(borrowerId);
|
|
37
|
+
const productIds = products.map((product) => <string>product._id.toString());
|
|
38
|
+
return logs.filter((r) => {
|
|
39
|
+
if (r.logType === ELogType.LOAN_TRANSACTION && r.record) {
|
|
40
|
+
return productIds.includes(r.record.productId.toString());
|
|
41
|
+
}
|
|
42
|
+
if (r.details && r.details.hasOwnProperty('borrowerId')) {
|
|
43
|
+
if (r.details.borrowerId && r.details.borrowerId === borrowerId) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async replaceBorrowers(logs: IUserLogWithLookup[]) {
|
|
52
|
+
const convertToMap = (arr: any[]): Map<string, string> => {
|
|
53
|
+
return arr.reduce((acc, item) => {
|
|
54
|
+
acc.set(item._id.toString(), item.name);
|
|
55
|
+
return acc;
|
|
56
|
+
}, new Map<string, string>());
|
|
57
|
+
};
|
|
58
|
+
const borrowers = await this.borrowerService.getAllBorrowers();
|
|
59
|
+
const borrowersMap = convertToMap(borrowers);
|
|
60
|
+
|
|
61
|
+
const products = await this.loanChargesService.getAllLoanProducts();
|
|
62
|
+
const productsMap = convertToMap(products);
|
|
63
|
+
|
|
64
|
+
const banks = await this.banksService.getBanks();
|
|
65
|
+
const banksMap = convertToMap(banks);
|
|
66
|
+
|
|
67
|
+
const replacedFields = {
|
|
68
|
+
borrowerId: borrowersMap,
|
|
69
|
+
productId: productsMap,
|
|
70
|
+
bankId: banksMap,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return logs.map((r) => {
|
|
74
|
+
Object.keys(replacedFields).forEach((key) => {
|
|
75
|
+
if (r.details && r.details.hasOwnProperty(key) && r.details[key]) {
|
|
76
|
+
r.details[key] = `${replacedFields[key].get(r.details[key].toString())} (${r.details[key].toString()})`;
|
|
77
|
+
}
|
|
78
|
+
if (r.record && r.record.hasOwnProperty(key) && r.record[key]) {
|
|
79
|
+
r.record[key] = `${replacedFields[key].get(r.record[key].toString())} (${r.record[key].toString()})`;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async performDynamicLookup(record: IUserLog): Promise<IUserLogWithLookup> {
|
|
86
|
+
try {
|
|
87
|
+
const { _id, recordCollection } = record;
|
|
88
|
+
if (!recordCollection) {
|
|
89
|
+
return record;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const pipeline = [
|
|
93
|
+
{
|
|
94
|
+
$match: {
|
|
95
|
+
_id,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
$lookup: {
|
|
100
|
+
from: recordCollection,
|
|
101
|
+
localField: 'recordId',
|
|
102
|
+
foreignField: '_id',
|
|
103
|
+
as: 'record',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
$unwind: {
|
|
108
|
+
path: '$record',
|
|
109
|
+
preserveNullAndEmptyArrays: true,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
const result = await UserLog.aggregate(pipeline);
|
|
115
|
+
if (result.length > 0 && result[0]) {
|
|
116
|
+
const foundRecord = result[0].record;
|
|
117
|
+
if (!foundRecord) {
|
|
118
|
+
const deletedRecord = await DeletedRecord
|
|
119
|
+
.findOne({ DBCollection: recordCollection, recordId: record.recordId })
|
|
120
|
+
.lean();
|
|
121
|
+
if (deletedRecord) {
|
|
122
|
+
result[0].record = deletedRecord.record;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result[0];
|
|
126
|
+
}
|
|
127
|
+
return record;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error('Error performing dynamic lookup:', error);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async getLogs(filter: IUserLogFilter) {
|
|
135
|
+
const logs = await UserLog.aggregate<IUserLog>([
|
|
136
|
+
{
|
|
137
|
+
$match: {
|
|
138
|
+
$and: [
|
|
139
|
+
{ 'timestamp': { $gte: filter.periodStart } },
|
|
140
|
+
{ 'timestamp': { $lte: filter.periodEnd } },
|
|
141
|
+
filter.userId ? { 'userId': new mongoose.Types.ObjectId(filter.userId) } : {},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
$sort: {
|
|
147
|
+
'timestamp': 1,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
const logsWithRecord = await Promise.all(logs.map(async (log) => await this.performDynamicLookup(log)));
|
|
152
|
+
const filteredByBorrowers = !filter.borrowerId
|
|
153
|
+
? logsWithRecord.slice()
|
|
154
|
+
: await this.filterByBorrower(logsWithRecord, filter.borrowerId);
|
|
155
|
+
await this.replaceBorrowers(filteredByBorrowers);
|
|
156
|
+
return filteredByBorrowers;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async getDocumentLogs(documentId: string) {
|
|
160
|
+
const logs = await UserLog.aggregate<IUserLog>([
|
|
161
|
+
{
|
|
162
|
+
$match: {
|
|
163
|
+
$and: [
|
|
164
|
+
{ 'recordCollection': 'loan_transactions' },
|
|
165
|
+
{ 'recordId': new mongoose.Types.ObjectId(documentId) },
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
$sort: {
|
|
171
|
+
'timestamp': 1,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
175
|
+
return await Promise.all(logs.map(async (log) => await this.performDynamicLookup(log)));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -57,10 +57,10 @@ export declare class UsersService {
|
|
|
57
57
|
};
|
|
58
58
|
firstName: string;
|
|
59
59
|
lastName: string;
|
|
60
|
-
roles?: IGroupedKeycloakRoles;
|
|
61
|
-
username: string;
|
|
62
60
|
enabled: boolean;
|
|
61
|
+
username: string;
|
|
63
62
|
email: string;
|
|
63
|
+
roles?: IGroupedKeycloakRoles;
|
|
64
64
|
emailVerified: boolean;
|
|
65
65
|
access: {
|
|
66
66
|
manageGroupMembership: boolean;
|
|
@@ -143,10 +143,10 @@ export declare class UsersService {
|
|
|
143
143
|
};
|
|
144
144
|
firstName: string;
|
|
145
145
|
lastName: string;
|
|
146
|
-
roles?: IGroupedKeycloakRoles;
|
|
147
|
-
username: string;
|
|
148
146
|
enabled: boolean;
|
|
147
|
+
username: string;
|
|
149
148
|
email: string;
|
|
149
|
+
roles?: IGroupedKeycloakRoles;
|
|
150
150
|
emailVerified: boolean;
|
|
151
151
|
access: {
|
|
152
152
|
manageGroupMembership: boolean;
|
|
@@ -35,6 +35,52 @@ interface IYieldViewData {
|
|
|
35
35
|
class?: string;
|
|
36
36
|
[data: string]: number | string | ILoanChargeDoc | ILoanProductDoc;
|
|
37
37
|
}
|
|
38
|
+
export declare enum ETotalType {
|
|
39
|
+
AVERAGE_BALANCE = "AVERAGE_BALANCE",
|
|
40
|
+
AVERAGE_LIFE_BALANCE = "AVERAGE_LIFE_BALANCE",
|
|
41
|
+
BROKER = "BROKER",
|
|
42
|
+
GROSS = "GROSS",
|
|
43
|
+
NET = "NET",
|
|
44
|
+
APR_GROSS = "APR_GROSS",
|
|
45
|
+
APR_LIFE_GROSS = "APR_LIFE_GROSS"
|
|
46
|
+
}
|
|
47
|
+
export declare const YIELD_TOTALS_MAP: {
|
|
48
|
+
AVERAGE_BALANCE: {
|
|
49
|
+
order: number;
|
|
50
|
+
title: string;
|
|
51
|
+
class: string;
|
|
52
|
+
};
|
|
53
|
+
AVERAGE_LIFE_BALANCE: {
|
|
54
|
+
order: number;
|
|
55
|
+
title: string;
|
|
56
|
+
class: string;
|
|
57
|
+
};
|
|
58
|
+
GROSS: {
|
|
59
|
+
order: number;
|
|
60
|
+
title: string;
|
|
61
|
+
class: string;
|
|
62
|
+
};
|
|
63
|
+
BROKER: {
|
|
64
|
+
order: number;
|
|
65
|
+
title: string;
|
|
66
|
+
class: string;
|
|
67
|
+
};
|
|
68
|
+
NET: {
|
|
69
|
+
order: number;
|
|
70
|
+
title: string;
|
|
71
|
+
class: string;
|
|
72
|
+
};
|
|
73
|
+
APR_GROSS: {
|
|
74
|
+
order: number;
|
|
75
|
+
title: string;
|
|
76
|
+
class: string;
|
|
77
|
+
};
|
|
78
|
+
APR_LIFE_GROSS: {
|
|
79
|
+
order: number;
|
|
80
|
+
title: string;
|
|
81
|
+
class: string;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
38
84
|
export declare class YieldService {
|
|
39
85
|
private getCalculatedYieldData;
|
|
40
86
|
getCalculatedYieldTotals(productId: string, selectedMonth: ISelectedMonth): Promise<(mongoose.FlattenMaps<import("../models/Yield.model").IYieldData> & Required<{
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.YieldService = void 0;
|
|
6
|
+
exports.YieldService = exports.YIELD_TOTALS_MAP = exports.ETotalType = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
7
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
9
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
10
|
const date_helper_1 = require("../helpers/date.helper");
|
|
@@ -12,6 +13,35 @@ const LoanCharges_model_1 = require("../models/LoanCharges.model");
|
|
|
12
13
|
const LoanProducts_model_1 = require("../models/LoanProducts.model");
|
|
13
14
|
const microservice_tasks_db_1 = require("../db/microservice-tasks.db");
|
|
14
15
|
const microservice_task_enum_1 = require("../enums/microservice-task.enum");
|
|
16
|
+
function getStartOfMonthsBetweenDates(startDate, endDate) {
|
|
17
|
+
let start = (0, dayjs_1.default)(startDate).utcOffset(0).startOf('month');
|
|
18
|
+
const end = (0, dayjs_1.default)(endDate).utcOffset(0).startOf('month');
|
|
19
|
+
const dates = {};
|
|
20
|
+
while (start.isBefore(end) || start.isSame(end)) {
|
|
21
|
+
dates[start.format('YYYY-MM')] = { year: start.year(), month: start.month() + 1 };
|
|
22
|
+
start = start.add(1, 'month');
|
|
23
|
+
}
|
|
24
|
+
return dates;
|
|
25
|
+
}
|
|
26
|
+
var ETotalType;
|
|
27
|
+
(function (ETotalType) {
|
|
28
|
+
ETotalType["AVERAGE_BALANCE"] = "AVERAGE_BALANCE";
|
|
29
|
+
ETotalType["AVERAGE_LIFE_BALANCE"] = "AVERAGE_LIFE_BALANCE";
|
|
30
|
+
ETotalType["BROKER"] = "BROKER";
|
|
31
|
+
ETotalType["GROSS"] = "GROSS";
|
|
32
|
+
ETotalType["NET"] = "NET";
|
|
33
|
+
ETotalType["APR_GROSS"] = "APR_GROSS";
|
|
34
|
+
ETotalType["APR_LIFE_GROSS"] = "APR_LIFE_GROSS";
|
|
35
|
+
})(ETotalType || (exports.ETotalType = ETotalType = {}));
|
|
36
|
+
exports.YIELD_TOTALS_MAP = {
|
|
37
|
+
[ETotalType.AVERAGE_BALANCE]: { order: -2, title: 'Average Balance in Month $', class: 'whiteOnOrange' },
|
|
38
|
+
[ETotalType.AVERAGE_LIFE_BALANCE]: { order: -1, title: 'Average loan life balance $', class: 'whiteOnOrange' },
|
|
39
|
+
[ETotalType.GROSS]: { order: 1, title: 'Gross income $', class: 'whiteOnGray' },
|
|
40
|
+
[ETotalType.BROKER]: { order: 2, title: 'Broker Fees $', class: 'whiteOnGray' },
|
|
41
|
+
[ETotalType.NET]: { order: 3, title: 'Net income $', class: 'whiteOnGray' },
|
|
42
|
+
[ETotalType.APR_GROSS]: { order: 6, title: 'Yield in month', class: 'whiteOnBlack' },
|
|
43
|
+
[ETotalType.APR_LIFE_GROSS]: { order: 7, title: 'Yield since inception', class: 'whiteOnBlack' },
|
|
44
|
+
};
|
|
15
45
|
class YieldService {
|
|
16
46
|
async getCalculatedYieldData(charge, selectedMonth) {
|
|
17
47
|
const oldData = await Yield_model_1.YieldData.findOne({
|
|
@@ -81,7 +111,7 @@ class YieldService {
|
|
|
81
111
|
},
|
|
82
112
|
};
|
|
83
113
|
}, {});
|
|
84
|
-
const allDates =
|
|
114
|
+
const allDates = getStartOfMonthsBetweenDates(startDate, endDate);
|
|
85
115
|
const allResults = [];
|
|
86
116
|
let hasAllData = true;
|
|
87
117
|
await Promise.all(Object.keys(productMap).map(async (productId) => {
|
|
@@ -113,13 +143,13 @@ class YieldService {
|
|
|
113
143
|
}
|
|
114
144
|
await Promise.all(products.map(async (product) => {
|
|
115
145
|
const productTotalList = [
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
146
|
+
ETotalType.GROSS,
|
|
147
|
+
ETotalType.BROKER,
|
|
148
|
+
ETotalType.NET,
|
|
149
|
+
ETotalType.AVERAGE_BALANCE,
|
|
150
|
+
ETotalType.AVERAGE_LIFE_BALANCE,
|
|
151
|
+
ETotalType.APR_GROSS,
|
|
152
|
+
ETotalType.APR_LIFE_GROSS,
|
|
123
153
|
];
|
|
124
154
|
const productTotal = productTotalList.reduce((acc, p) => {
|
|
125
155
|
return {
|
|
@@ -127,9 +157,9 @@ class YieldService {
|
|
|
127
157
|
[p]: {
|
|
128
158
|
charge: null,
|
|
129
159
|
product,
|
|
130
|
-
order:
|
|
131
|
-
title: `${product.name} (${
|
|
132
|
-
class:
|
|
160
|
+
order: exports.YIELD_TOTALS_MAP[p].order,
|
|
161
|
+
title: `${product.name} (${exports.YIELD_TOTALS_MAP[p].title})`,
|
|
162
|
+
class: exports.YIELD_TOTALS_MAP[p].class,
|
|
133
163
|
},
|
|
134
164
|
};
|
|
135
165
|
}, {});
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
1
2
|
import _ from 'lodash';
|
|
2
3
|
import mongoose from 'mongoose';
|
|
3
4
|
|
|
4
|
-
import { convertSelectedMonthToDate,
|
|
5
|
-
import {
|
|
6
|
-
ETotalType,
|
|
7
|
-
IYieldParams,
|
|
8
|
-
YIELD_TOTALS_MAP,
|
|
9
|
-
YieldData,
|
|
10
|
-
yieldParamsValidationSchema,
|
|
11
|
-
} from '../models/Yield.model';
|
|
5
|
+
import { convertSelectedMonthToDate, ISelectedMonth } from '../helpers/date.helper';
|
|
6
|
+
import { IYieldParams, YieldData, yieldParamsValidationSchema } from '../models/Yield.model';
|
|
12
7
|
import { ILoanChargeDoc, LoanCharge } from '../models/LoanCharges.model';
|
|
13
8
|
import { ILoanProductDoc, LoanProduct } from '../models/LoanProducts.model';
|
|
14
9
|
import { createMicroserviceTasks } from '../db/microservice-tasks.db';
|
|
@@ -24,6 +19,41 @@ interface IYieldViewData {
|
|
|
24
19
|
[data: string]: number | string | ILoanChargeDoc | ILoanProductDoc;
|
|
25
20
|
}
|
|
26
21
|
|
|
22
|
+
function getStartOfMonthsBetweenDates(startDate: Date, endDate: Date): {
|
|
23
|
+
[dateView: string]: { year: number; month: number }
|
|
24
|
+
} {
|
|
25
|
+
let start = dayjs(startDate).utcOffset(0).startOf('month');
|
|
26
|
+
const end = dayjs(endDate).utcOffset(0).startOf('month');
|
|
27
|
+
const dates = {};
|
|
28
|
+
|
|
29
|
+
while (start.isBefore(end) || start.isSame(end)) {
|
|
30
|
+
dates[start.format('YYYY-MM')] = <ISelectedMonth>{ year: start.year(), month: start.month() + 1 };
|
|
31
|
+
start = start.add(1, 'month');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return dates;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export enum ETotalType {
|
|
38
|
+
AVERAGE_BALANCE = 'AVERAGE_BALANCE',
|
|
39
|
+
AVERAGE_LIFE_BALANCE = 'AVERAGE_LIFE_BALANCE',
|
|
40
|
+
BROKER = 'BROKER',
|
|
41
|
+
GROSS = 'GROSS',
|
|
42
|
+
NET = 'NET',
|
|
43
|
+
APR_GROSS = 'APR_GROSS',
|
|
44
|
+
APR_LIFE_GROSS = 'APR_LIFE_GROSS',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const YIELD_TOTALS_MAP = {
|
|
48
|
+
[ETotalType.AVERAGE_BALANCE]: { order: -2, title: 'Average Balance in Month $', class: 'whiteOnOrange' },
|
|
49
|
+
[ETotalType.AVERAGE_LIFE_BALANCE]: { order: -1, title: 'Average loan life balance $', class: 'whiteOnOrange' },
|
|
50
|
+
[ETotalType.GROSS]: { order: 1, title: 'Gross income $', class: 'whiteOnGray' },
|
|
51
|
+
[ETotalType.BROKER]: { order: 2, title: 'Broker Fees $', class: 'whiteOnGray' },
|
|
52
|
+
[ETotalType.NET]: { order: 3, title: 'Net income $', class: 'whiteOnGray' },
|
|
53
|
+
[ETotalType.APR_GROSS]: { order: 6, title: 'Yield in month', class: 'whiteOnBlack' },
|
|
54
|
+
[ETotalType.APR_LIFE_GROSS]: { order: 7, title: 'Yield since inception', class: 'whiteOnBlack' },
|
|
55
|
+
};
|
|
56
|
+
|
|
27
57
|
export class YieldService {
|
|
28
58
|
|
|
29
59
|
private async getCalculatedYieldData(charge: ILoanChargeDoc, selectedMonth: ISelectedMonth) {
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"incremental": true,
|
|
4
3
|
"target": "ES2022",
|
|
5
4
|
"module": "CommonJS",
|
|
6
|
-
"declaration": true,
|
|
7
5
|
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
6
|
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"
|
|
11
|
-
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"incremental": true
|
|
11
|
+
}
|
|
12
12
|
}
|