gemcap-be-common 1.5.83 → 1.5.85
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/models/HistoricalLoanCharge.model.d.ts +61 -0
- package/models/HistoricalLoanCharge.model.js +71 -0
- package/models/HistoricalLoanCharge.model.ts +106 -0
- package/models/_models.d.ts +1 -0
- package/models/_models.js +2 -1
- package/models/_models.ts +2 -1
- package/package.json +1 -1
- package/services/compliance-borrowers.service.d.ts +1 -1
- package/services/loan-transactions.service.d.ts +9 -0
- package/services/loan-transactions.service.js +64 -44
- package/services/loan-transactions.service.ts +125 -38
- package/services/quickbooks.service.d.ts +1 -1
- package/services/yield.service.d.ts +1 -1
- package/services/yield.service.js +2 -2
- package/services/yield.service.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/types" />
|
|
2
|
+
/// <reference types="mongoose/types/models" />
|
|
3
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
4
|
+
/// <reference types="mongoose/types/utility" />
|
|
5
|
+
/// <reference types="mongoose/types/document" />
|
|
6
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
7
|
+
/// <reference types="mongoose/types/callback" />
|
|
8
|
+
/// <reference types="mongoose/types/collection" />
|
|
9
|
+
/// <reference types="mongoose/types/connection" />
|
|
10
|
+
/// <reference types="mongoose/types/cursor" />
|
|
11
|
+
/// <reference types="mongoose/types/document" />
|
|
12
|
+
/// <reference types="mongoose/types/error" />
|
|
13
|
+
/// <reference types="mongoose/types/expressions" />
|
|
14
|
+
/// <reference types="mongoose/types/helpers" />
|
|
15
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
16
|
+
/// <reference types="mongoose/types/indexes" />
|
|
17
|
+
/// <reference types="mongoose/types/models" />
|
|
18
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
19
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
20
|
+
/// <reference types="mongoose/types/populate" />
|
|
21
|
+
/// <reference types="mongoose/types/query" />
|
|
22
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
23
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
24
|
+
/// <reference types="mongoose/types/session" />
|
|
25
|
+
/// <reference types="mongoose/types/types" />
|
|
26
|
+
/// <reference types="mongoose/types/utility" />
|
|
27
|
+
/// <reference types="mongoose/types/validation" />
|
|
28
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
29
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
30
|
+
import mongoose from 'mongoose';
|
|
31
|
+
import Joi from 'joi';
|
|
32
|
+
export interface IHistoricalLoanCharge {
|
|
33
|
+
loanProductId: mongoose.Types.ObjectId;
|
|
34
|
+
date: Date;
|
|
35
|
+
paymentDate: Date;
|
|
36
|
+
source: string;
|
|
37
|
+
chargeId: mongoose.Types.ObjectId;
|
|
38
|
+
chargeName: string;
|
|
39
|
+
amount: number;
|
|
40
|
+
amountPaid: number;
|
|
41
|
+
}
|
|
42
|
+
export type THistoricalLoanChargeDoc = mongoose.HydratedDocument<IHistoricalLoanCharge>;
|
|
43
|
+
export interface IHistoricalLoanChargeLean extends IHistoricalLoanCharge {
|
|
44
|
+
_id: mongoose.Types.ObjectId;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
updatedAt: Date;
|
|
47
|
+
}
|
|
48
|
+
export interface IHistoricalLoanChargePlain extends Omit<IHistoricalLoanCharge, 'loanProductId' | 'chargeId'> {
|
|
49
|
+
_id: string;
|
|
50
|
+
loanProductId: string;
|
|
51
|
+
chargeId: string;
|
|
52
|
+
createdAt: Date;
|
|
53
|
+
updatedAt: Date;
|
|
54
|
+
}
|
|
55
|
+
export declare const HistoricalLoanChargeCreateValidationSchema: Joi.ObjectSchema<any>;
|
|
56
|
+
export declare const HistoricalLoanChargeUpdateValidationSchema: Joi.ObjectSchema<any>;
|
|
57
|
+
export type THistoricalLoanChargeModel = mongoose.Model<IHistoricalLoanCharge>;
|
|
58
|
+
export declare const HistoricalLoanChargeSchema: mongoose.Schema<IHistoricalLoanCharge, THistoricalLoanChargeModel, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, IHistoricalLoanCharge, mongoose.Document<unknown, {}, mongoose.FlatRecord<IHistoricalLoanCharge>> & mongoose.FlatRecord<IHistoricalLoanCharge> & {
|
|
59
|
+
_id: mongoose.Types.ObjectId;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const HistoricalLoanCharge: THistoricalLoanChargeModel;
|
|
@@ -0,0 +1,71 @@
|
|
|
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.HistoricalLoanCharge = exports.HistoricalLoanChargeSchema = exports.HistoricalLoanChargeUpdateValidationSchema = exports.HistoricalLoanChargeCreateValidationSchema = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
9
|
+
const _models_1 = require("./_models");
|
|
10
|
+
exports.HistoricalLoanChargeCreateValidationSchema = joi_1.default.object({
|
|
11
|
+
loanProductId: joi_1.default.string().required(),
|
|
12
|
+
date: joi_1.default.date().required(),
|
|
13
|
+
paymentDate: joi_1.default.date().required(),
|
|
14
|
+
chargeId: joi_1.default.string().required(),
|
|
15
|
+
source: joi_1.default.string().required(),
|
|
16
|
+
chargeName: joi_1.default.string().required(),
|
|
17
|
+
amount: joi_1.default.number().required(),
|
|
18
|
+
amountPaid: joi_1.default.number().required(),
|
|
19
|
+
});
|
|
20
|
+
exports.HistoricalLoanChargeUpdateValidationSchema = joi_1.default.object({
|
|
21
|
+
_id: joi_1.default.string().required(),
|
|
22
|
+
loanProductId: joi_1.default.string(),
|
|
23
|
+
date: joi_1.default.date(),
|
|
24
|
+
paymentDate: joi_1.default.date(),
|
|
25
|
+
chargeId: joi_1.default.string(),
|
|
26
|
+
source: joi_1.default.string(),
|
|
27
|
+
chargeName: joi_1.default.string(),
|
|
28
|
+
amount: joi_1.default.number(),
|
|
29
|
+
amountPaid: joi_1.default.number(),
|
|
30
|
+
});
|
|
31
|
+
exports.HistoricalLoanChargeSchema = new mongoose_1.default.Schema({
|
|
32
|
+
loanProductId: {
|
|
33
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
34
|
+
ref: _models_1.MODEL_NAMES.loanProducts,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
date: {
|
|
38
|
+
type: Date,
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
paymentDate: {
|
|
42
|
+
type: Date,
|
|
43
|
+
required: true,
|
|
44
|
+
},
|
|
45
|
+
source: {
|
|
46
|
+
type: String,
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
chargeId: {
|
|
50
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
51
|
+
ref: _models_1.MODEL_NAMES.loanCharges,
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
54
|
+
chargeName: {
|
|
55
|
+
type: String,
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
amount: {
|
|
59
|
+
type: Number,
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
amountPaid: {
|
|
63
|
+
type: Number,
|
|
64
|
+
required: true,
|
|
65
|
+
},
|
|
66
|
+
}, {
|
|
67
|
+
timestamps: { createdAt: true, updatedAt: true },
|
|
68
|
+
versionKey: false,
|
|
69
|
+
});
|
|
70
|
+
exports.HistoricalLoanChargeSchema.index({ loanProductId: 1, chargeId: 1, date: 1 }, { unique: true });
|
|
71
|
+
exports.HistoricalLoanCharge = mongoose_1.default.model(_models_1.MODEL_NAMES.historicalLoanCharges, exports.HistoricalLoanChargeSchema);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import Joi from 'joi';
|
|
3
|
+
|
|
4
|
+
import { MODEL_NAMES } from './_models';
|
|
5
|
+
|
|
6
|
+
export interface IHistoricalLoanCharge {
|
|
7
|
+
loanProductId: mongoose.Types.ObjectId;
|
|
8
|
+
date: Date;
|
|
9
|
+
paymentDate: Date;
|
|
10
|
+
source: string;
|
|
11
|
+
chargeId: mongoose.Types.ObjectId;
|
|
12
|
+
chargeName: string;
|
|
13
|
+
amount: number;
|
|
14
|
+
amountPaid: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type THistoricalLoanChargeDoc = mongoose.HydratedDocument<IHistoricalLoanCharge>;
|
|
18
|
+
|
|
19
|
+
export interface IHistoricalLoanChargeLean extends IHistoricalLoanCharge {
|
|
20
|
+
_id: mongoose.Types.ObjectId;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IHistoricalLoanChargePlain extends Omit<IHistoricalLoanCharge, 'loanProductId' | 'chargeId'> {
|
|
26
|
+
_id: string;
|
|
27
|
+
loanProductId: string;
|
|
28
|
+
chargeId: string;
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
updatedAt: Date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const HistoricalLoanChargeCreateValidationSchema = Joi.object({
|
|
34
|
+
loanProductId: Joi.string().required(),
|
|
35
|
+
date: Joi.date().required(),
|
|
36
|
+
paymentDate: Joi.date().required(),
|
|
37
|
+
chargeId: Joi.string().required(),
|
|
38
|
+
source: Joi.string().required(),
|
|
39
|
+
chargeName: Joi.string().required(),
|
|
40
|
+
amount: Joi.number().required(),
|
|
41
|
+
amountPaid: Joi.number().required(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const HistoricalLoanChargeUpdateValidationSchema = Joi.object({
|
|
45
|
+
_id: Joi.string().required(),
|
|
46
|
+
loanProductId: Joi.string(),
|
|
47
|
+
date: Joi.date(),
|
|
48
|
+
paymentDate: Joi.date(),
|
|
49
|
+
chargeId: Joi.string(),
|
|
50
|
+
source: Joi.string(),
|
|
51
|
+
chargeName: Joi.string(),
|
|
52
|
+
amount: Joi.number(),
|
|
53
|
+
amountPaid: Joi.number(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export type THistoricalLoanChargeModel = mongoose.Model<IHistoricalLoanCharge>;
|
|
57
|
+
|
|
58
|
+
export const HistoricalLoanChargeSchema = new mongoose.Schema<IHistoricalLoanCharge, THistoricalLoanChargeModel>(
|
|
59
|
+
{
|
|
60
|
+
loanProductId: {
|
|
61
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
62
|
+
ref: MODEL_NAMES.loanProducts,
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
date: {
|
|
66
|
+
type: Date,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
paymentDate: {
|
|
70
|
+
type: Date,
|
|
71
|
+
required: true,
|
|
72
|
+
},
|
|
73
|
+
source: {
|
|
74
|
+
type: String,
|
|
75
|
+
required: true,
|
|
76
|
+
},
|
|
77
|
+
chargeId: {
|
|
78
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
79
|
+
ref: MODEL_NAMES.loanCharges,
|
|
80
|
+
required: true,
|
|
81
|
+
},
|
|
82
|
+
chargeName: {
|
|
83
|
+
type: String,
|
|
84
|
+
required: true,
|
|
85
|
+
},
|
|
86
|
+
amount: {
|
|
87
|
+
type: Number,
|
|
88
|
+
required: true,
|
|
89
|
+
},
|
|
90
|
+
amountPaid: {
|
|
91
|
+
type: Number,
|
|
92
|
+
required: true,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
timestamps: { createdAt: true, updatedAt: true },
|
|
97
|
+
versionKey: false,
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
HistoricalLoanChargeSchema.index(
|
|
102
|
+
{ loanProductId: 1, chargeId: 1, date: 1 },
|
|
103
|
+
{ unique: true },
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export const HistoricalLoanCharge = mongoose.model<IHistoricalLoanCharge, THistoricalLoanChargeModel>(MODEL_NAMES.historicalLoanCharges, HistoricalLoanChargeSchema);
|
package/models/_models.d.ts
CHANGED
package/models/_models.js
CHANGED
|
@@ -79,7 +79,8 @@ exports.MODEL_NAMES = {
|
|
|
79
79
|
financialSpreadingExclusion: 'financial_spreading_exclusions',
|
|
80
80
|
financialSpreadingSheets: 'financial_spreading_sheets',
|
|
81
81
|
globals: 'globals',
|
|
82
|
-
loanSnapshots: '
|
|
82
|
+
loanSnapshots: 'loan_snapshots',
|
|
83
|
+
historicalLoanCharges: 'historical_loan_charges',
|
|
83
84
|
insuranceReportSettings: 'insurance_report_settings',
|
|
84
85
|
inventories: 'inventories',
|
|
85
86
|
inventoryAvailability: 'inventoryAvailabilities',
|
package/models/_models.ts
CHANGED
|
@@ -76,7 +76,8 @@ export const MODEL_NAMES = {
|
|
|
76
76
|
financialSpreadingExclusion: 'financial_spreading_exclusions',
|
|
77
77
|
financialSpreadingSheets: 'financial_spreading_sheets',
|
|
78
78
|
globals: 'globals',
|
|
79
|
-
loanSnapshots: '
|
|
79
|
+
loanSnapshots: 'loan_snapshots',
|
|
80
|
+
historicalLoanCharges: 'historical_loan_charges',
|
|
80
81
|
insuranceReportSettings: 'insurance_report_settings',
|
|
81
82
|
inventories: 'inventories',
|
|
82
83
|
inventoryAvailability: 'inventoryAvailabilities',
|
package/package.json
CHANGED
|
@@ -60,7 +60,7 @@ export declare class ComplianceBorrowersService {
|
|
|
60
60
|
isComplianceBorrowerAllowed(userAccess: IUserAccess, requestedBorrowerId: string): boolean;
|
|
61
61
|
calculateInstanceStatuses(instance: IBorrowerItemInstance, item: IBorrowerItemLean): IInstanceStatus;
|
|
62
62
|
getFullComplianceBorrowerById(complianceBorrowerId: string): Promise<IComplianceBorrowerDocumentFullWithStatuses>;
|
|
63
|
-
getAllBorrowersShortened(userAccess: IUserAccess): Promise<Pick<IComplianceBorrowerWithBorrower, "
|
|
63
|
+
getAllBorrowersShortened(userAccess: IUserAccess): Promise<Pick<IComplianceBorrowerWithBorrower, "borrower" | "fundingStatus" | "items">[]>;
|
|
64
64
|
generateInstances(complianceBorrowerId: any): Promise<IComplianceBorrowerDocumentFullWithStatuses>;
|
|
65
65
|
calculateAndUpdateFundingStatus(complianceBorrowerId: string): Promise<void>;
|
|
66
66
|
calculateFundingStatus(complianceBorrower: IComplianceBorrowerDocumentFull): string;
|
|
@@ -60,6 +60,13 @@ export interface ITransactionsFilter {
|
|
|
60
60
|
amount?: number;
|
|
61
61
|
reference?: string;
|
|
62
62
|
}
|
|
63
|
+
export interface ITransactionsMultiProductsFilter {
|
|
64
|
+
periodStart: Date;
|
|
65
|
+
periodEnd: Date;
|
|
66
|
+
productIds: string[];
|
|
67
|
+
amount?: number;
|
|
68
|
+
reference?: string;
|
|
69
|
+
}
|
|
63
70
|
export declare class LoanTransactionsService {
|
|
64
71
|
private readonly attachedFilesService;
|
|
65
72
|
private readonly banksService;
|
|
@@ -80,7 +87,9 @@ export declare class LoanTransactionsService {
|
|
|
80
87
|
getTransactionsById(transactionId: string): Promise<mongoose.FlattenMaps<ILoanTransaction> & {
|
|
81
88
|
_id: mongoose.Types.ObjectId;
|
|
82
89
|
}>;
|
|
90
|
+
private getLoanTransactionsInternal;
|
|
83
91
|
getLoanTransactions<T extends boolean>(transactionsFilter: ITransactionsFilter, paginatorOptions: IPaginatorOptions, withBanks: T, isReverse?: boolean, isMinified?: boolean): Promise<(T extends true ? ILoanTransactionViewWithBank : ILoanTransactionView)[]>;
|
|
92
|
+
getLoanTransactionsForProducts<T extends boolean>(transactionsFilter: ITransactionsMultiProductsFilter, paginatorOptions: IPaginatorOptions, withBanks: T, isReverse?: boolean, isMinified?: boolean): Promise<(T extends true ? ILoanTransactionViewWithBank : ILoanTransactionView)[]>;
|
|
84
93
|
getLoanTransactionsForFilter(periodStart: Date, periodEnd: Date, productId: string): Promise<ILoanTransactionView[]>;
|
|
85
94
|
getLoanTransactionsForProduct(productId: string): Promise<ILoanTransactionView[]>;
|
|
86
95
|
getLoanTransactionFiles(): Promise<{
|
|
@@ -61,62 +61,82 @@ class LoanTransactionsService {
|
|
|
61
61
|
async getTransactionsById(transactionId) {
|
|
62
62
|
return LoanTransaction_model_1.LoanTransaction.findById(transactionId).lean();
|
|
63
63
|
}
|
|
64
|
-
async
|
|
65
|
-
const borrowerProducts = await this.loanChargesService.getLoanProducts(transactionsFilter.borrowerId);
|
|
66
|
-
const productIds = borrowerProducts
|
|
67
|
-
.filter((product) => transactionsFilter.productId ? product._id.toString() === transactionsFilter.productId : true)
|
|
68
|
-
.map((product) => product._id);
|
|
64
|
+
async getLoanTransactionsInternal(productIds, transactionsFilter, paginatorOptions, withBanks, isReverse = false, isMinified = false) {
|
|
69
65
|
const optionalFilters = [];
|
|
70
66
|
if (transactionsFilter.amount) {
|
|
71
|
-
optionalFilters.push({
|
|
67
|
+
optionalFilters.push({ amount: transactionsFilter.amount });
|
|
72
68
|
}
|
|
73
69
|
if (transactionsFilter.reference) {
|
|
74
|
-
optionalFilters.push({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
: [
|
|
79
|
-
{
|
|
80
|
-
$lookup: {
|
|
81
|
-
from: 'banks',
|
|
82
|
-
localField: 'bankId',
|
|
83
|
-
foreignField: '_id',
|
|
84
|
-
as: 'bank',
|
|
85
|
-
},
|
|
86
|
-
}, {
|
|
87
|
-
$unwind: {
|
|
88
|
-
path: '$bank',
|
|
89
|
-
preserveNullAndEmptyArrays: true,
|
|
90
|
-
},
|
|
70
|
+
optionalFilters.push({
|
|
71
|
+
reference: {
|
|
72
|
+
$regex: transactionsFilter.reference,
|
|
73
|
+
$options: 'i',
|
|
91
74
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
: [];
|
|
96
|
-
return LoanTransaction_model_1.LoanTransaction.aggregate([
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const pipeline = [
|
|
97
78
|
{
|
|
98
79
|
$match: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
80
|
+
date: {
|
|
81
|
+
$gte: transactionsFilter.periodStart,
|
|
82
|
+
$lte: transactionsFilter.periodEnd,
|
|
83
|
+
},
|
|
84
|
+
productId: { $in: productIds },
|
|
85
|
+
...Object.assign({}, ...optionalFilters),
|
|
105
86
|
},
|
|
106
|
-
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
107
89
|
$sort: {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
90
|
+
date: isReverse ? -1 : 1,
|
|
91
|
+
order: isReverse ? -1 : 1,
|
|
92
|
+
createdAt: isReverse ? -1 : 1,
|
|
111
93
|
},
|
|
112
94
|
},
|
|
113
95
|
...(0, collaterals_db_1.ITEMS_PAGINATION)(paginatorOptions),
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
96
|
+
];
|
|
97
|
+
if (withBanks) {
|
|
98
|
+
pipeline.push({
|
|
99
|
+
$lookup: {
|
|
100
|
+
from: 'banks',
|
|
101
|
+
localField: 'bankId',
|
|
102
|
+
foreignField: '_id',
|
|
103
|
+
as: 'bank',
|
|
104
|
+
},
|
|
105
|
+
}, {
|
|
106
|
+
$unwind: {
|
|
107
|
+
path: '$bank',
|
|
108
|
+
preserveNullAndEmptyArrays: true,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
pipeline.push({
|
|
113
|
+
$unset: loan_products_db_1.fieldsToUnset,
|
|
114
|
+
});
|
|
115
|
+
if (isMinified) {
|
|
116
|
+
pipeline.push({
|
|
117
|
+
$project: {
|
|
118
|
+
_id: 1,
|
|
119
|
+
date: 1,
|
|
120
|
+
amount: 1,
|
|
121
|
+
reference: 1,
|
|
122
|
+
balance: 1,
|
|
123
|
+
transactionType: 1,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return LoanTransaction_model_1.LoanTransaction.aggregate(pipeline);
|
|
128
|
+
}
|
|
129
|
+
async getLoanTransactions(transactionsFilter, paginatorOptions, withBanks, isReverse = false, isMinified = false) {
|
|
130
|
+
const borrowerProducts = await this.loanChargesService.getLoanProducts(transactionsFilter.borrowerId);
|
|
131
|
+
const productIds = borrowerProducts
|
|
132
|
+
.filter((product) => transactionsFilter.productId
|
|
133
|
+
? product._id.toString() === transactionsFilter.productId
|
|
134
|
+
: true)
|
|
135
|
+
.map((product) => product._id);
|
|
136
|
+
return this.getLoanTransactionsInternal(productIds, transactionsFilter, paginatorOptions, withBanks, isReverse, isMinified);
|
|
137
|
+
}
|
|
138
|
+
async getLoanTransactionsForProducts(transactionsFilter, paginatorOptions, withBanks, isReverse = false, isMinified = false) {
|
|
139
|
+
return this.getLoanTransactionsInternal(transactionsFilter.productIds.map((id) => new mongoose_1.default.Types.ObjectId(id)), transactionsFilter, paginatorOptions, withBanks, isReverse, isMinified);
|
|
120
140
|
}
|
|
121
141
|
async getLoanTransactionsForFilter(periodStart, periodEnd, productId) {
|
|
122
142
|
return LoanTransaction_model_1.LoanTransaction.aggregate([
|
|
@@ -68,6 +68,14 @@ export interface ITransactionsFilter {
|
|
|
68
68
|
reference?: string;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export interface ITransactionsMultiProductsFilter {
|
|
72
|
+
periodStart: Date;
|
|
73
|
+
periodEnd: Date;
|
|
74
|
+
productIds: string[];
|
|
75
|
+
amount?: number;
|
|
76
|
+
reference?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
export class LoanTransactionsService {
|
|
72
80
|
|
|
73
81
|
private readonly config: ILoanTransactionsServiceConfig;
|
|
@@ -96,22 +104,57 @@ export class LoanTransactionsService {
|
|
|
96
104
|
return LoanTransaction.findById(transactionId).lean();
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
async
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
private async getLoanTransactionsInternal<T extends boolean>(
|
|
108
|
+
productIds: mongoose.Types.ObjectId[],
|
|
109
|
+
transactionsFilter: {
|
|
110
|
+
periodStart: Date;
|
|
111
|
+
periodEnd: Date;
|
|
112
|
+
amount?: number;
|
|
113
|
+
reference?: string;
|
|
114
|
+
},
|
|
115
|
+
paginatorOptions: IPaginatorOptions,
|
|
116
|
+
withBanks: T,
|
|
117
|
+
isReverse = false,
|
|
118
|
+
isMinified = false,
|
|
119
|
+
) {
|
|
105
120
|
const optionalFilters = [];
|
|
121
|
+
|
|
106
122
|
if (transactionsFilter.amount) {
|
|
107
|
-
optionalFilters.push({
|
|
123
|
+
optionalFilters.push({ amount: transactionsFilter.amount });
|
|
108
124
|
}
|
|
125
|
+
|
|
109
126
|
if (transactionsFilter.reference) {
|
|
110
|
-
optionalFilters.push({
|
|
127
|
+
optionalFilters.push({
|
|
128
|
+
reference: {
|
|
129
|
+
$regex: transactionsFilter.reference,
|
|
130
|
+
$options: 'i',
|
|
131
|
+
},
|
|
132
|
+
});
|
|
111
133
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
|
|
135
|
+
const pipeline: mongoose.PipelineStage[] = [
|
|
136
|
+
{
|
|
137
|
+
$match: {
|
|
138
|
+
date: {
|
|
139
|
+
$gte: transactionsFilter.periodStart,
|
|
140
|
+
$lte: transactionsFilter.periodEnd,
|
|
141
|
+
},
|
|
142
|
+
productId: { $in: productIds },
|
|
143
|
+
...Object.assign({}, ...optionalFilters),
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
$sort: {
|
|
148
|
+
date: isReverse ? -1 : 1,
|
|
149
|
+
order: isReverse ? -1 : 1,
|
|
150
|
+
createdAt: isReverse ? -1 : 1,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
...ITEMS_PAGINATION(paginatorOptions),
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
if (withBanks) {
|
|
157
|
+
pipeline.push(
|
|
115
158
|
{
|
|
116
159
|
$lookup: {
|
|
117
160
|
from: 'banks',
|
|
@@ -119,42 +162,86 @@ export class LoanTransactionsService {
|
|
|
119
162
|
foreignField: '_id',
|
|
120
163
|
as: 'bank',
|
|
121
164
|
},
|
|
122
|
-
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
123
167
|
$unwind: {
|
|
124
168
|
path: '$bank',
|
|
125
169
|
preserveNullAndEmptyArrays: true,
|
|
126
170
|
},
|
|
127
171
|
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const projectedFields = isMinified
|
|
131
|
-
? [{ $project: { _id: 1, date: 1, amount: 1, reference: 1, balance: 1, transactionType: 1 } }]
|
|
132
|
-
: [];
|
|
172
|
+
);
|
|
173
|
+
}
|
|
133
174
|
|
|
134
|
-
|
|
135
|
-
{
|
|
136
|
-
$match: {
|
|
137
|
-
$and: [
|
|
138
|
-
{ 'date': { $gte: transactionsFilter.periodStart } },
|
|
139
|
-
{ 'date': { $lte: transactionsFilter.periodEnd } },
|
|
140
|
-
{ 'productId': { $in: productIds } },
|
|
141
|
-
...optionalFilters,
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
}, {
|
|
145
|
-
$sort: {
|
|
146
|
-
'date': isReverse ? -1 : 1,
|
|
147
|
-
'order': isReverse ? -1 : 1,
|
|
148
|
-
'createdAt': isReverse ? -1 : 1,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
...ITEMS_PAGINATION(paginatorOptions),
|
|
152
|
-
...bankLookup,
|
|
175
|
+
pipeline.push(
|
|
153
176
|
{
|
|
154
177
|
$unset: fieldsToUnset,
|
|
155
178
|
},
|
|
156
|
-
|
|
157
|
-
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if (isMinified) {
|
|
182
|
+
pipeline.push({
|
|
183
|
+
$project: {
|
|
184
|
+
_id: 1,
|
|
185
|
+
date: 1,
|
|
186
|
+
amount: 1,
|
|
187
|
+
reference: 1,
|
|
188
|
+
balance: 1,
|
|
189
|
+
transactionType: 1,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return LoanTransaction.aggregate<
|
|
195
|
+
T extends true ? ILoanTransactionViewWithBank : ILoanTransactionView
|
|
196
|
+
>(pipeline);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async getLoanTransactions<T extends boolean>(
|
|
200
|
+
transactionsFilter: ITransactionsFilter,
|
|
201
|
+
paginatorOptions: IPaginatorOptions,
|
|
202
|
+
withBanks: T,
|
|
203
|
+
isReverse = false,
|
|
204
|
+
isMinified = false,
|
|
205
|
+
) {
|
|
206
|
+
const borrowerProducts = await this.loanChargesService.getLoanProducts(
|
|
207
|
+
transactionsFilter.borrowerId,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const productIds = borrowerProducts
|
|
211
|
+
.filter((product) =>
|
|
212
|
+
transactionsFilter.productId
|
|
213
|
+
? product._id.toString() === transactionsFilter.productId
|
|
214
|
+
: true,
|
|
215
|
+
)
|
|
216
|
+
.map((product) => product._id);
|
|
217
|
+
|
|
218
|
+
return this.getLoanTransactionsInternal(
|
|
219
|
+
productIds,
|
|
220
|
+
transactionsFilter,
|
|
221
|
+
paginatorOptions,
|
|
222
|
+
withBanks,
|
|
223
|
+
isReverse,
|
|
224
|
+
isMinified,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async getLoanTransactionsForProducts<T extends boolean>(
|
|
229
|
+
transactionsFilter: ITransactionsMultiProductsFilter,
|
|
230
|
+
paginatorOptions: IPaginatorOptions,
|
|
231
|
+
withBanks: T,
|
|
232
|
+
isReverse = false,
|
|
233
|
+
isMinified = false,
|
|
234
|
+
) {
|
|
235
|
+
return this.getLoanTransactionsInternal(
|
|
236
|
+
transactionsFilter.productIds.map(
|
|
237
|
+
(id) => new mongoose.Types.ObjectId(id),
|
|
238
|
+
),
|
|
239
|
+
transactionsFilter,
|
|
240
|
+
paginatorOptions,
|
|
241
|
+
withBanks,
|
|
242
|
+
isReverse,
|
|
243
|
+
isMinified,
|
|
244
|
+
);
|
|
158
245
|
}
|
|
159
246
|
|
|
160
247
|
async getLoanTransactionsForFilter(periodStart: Date, periodEnd: Date, productId: string) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/document" />
|
|
2
1
|
/// <reference types="mongoose/types/types" />
|
|
2
|
+
/// <reference types="mongoose/types/document" />
|
|
3
3
|
/// <reference types="mongoose/types/aggregate" />
|
|
4
4
|
/// <reference types="mongoose/types/callback" />
|
|
5
5
|
/// <reference types="mongoose/types/collection" />
|
|
@@ -31,7 +31,7 @@ export declare class YieldService {
|
|
|
31
31
|
getCalculatedYieldTotals(productId: string, selectedMonth: ISelectedMonth): Promise<(mongoose.FlattenMaps<import("../models/Yield.model").IYieldData> & {
|
|
32
32
|
_id: mongoose.Types.ObjectId;
|
|
33
33
|
})[]>;
|
|
34
|
-
getCalculatedYieldTotalsForPeriod(
|
|
34
|
+
getCalculatedYieldTotalsForPeriod(productIds: string[], periodStart: ISelectedMonth, periodEnd: ISelectedMonth): Promise<(mongoose.FlattenMaps<import("../models/Yield.model").IYieldData> & {
|
|
35
35
|
_id: mongoose.Types.ObjectId;
|
|
36
36
|
})[]>;
|
|
37
37
|
getYieldData(params: IYieldParams): Promise<{
|
|
@@ -33,9 +33,9 @@ class YieldService {
|
|
|
33
33
|
month: selectedMonth.month,
|
|
34
34
|
}).lean();
|
|
35
35
|
}
|
|
36
|
-
async getCalculatedYieldTotalsForPeriod(
|
|
36
|
+
async getCalculatedYieldTotalsForPeriod(productIds, periodStart, periodEnd) {
|
|
37
37
|
return Yield_model_1.YieldData.find({
|
|
38
|
-
productId: new mongoose_1.default.Types.ObjectId(productId),
|
|
38
|
+
productId: productIds.map((productId) => new mongoose_1.default.Types.ObjectId(productId)),
|
|
39
39
|
$or: [
|
|
40
40
|
{
|
|
41
41
|
year: periodStart.year,
|