gemcap-be-common 1.4.2 → 1.4.4
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/db/availability.db.d.ts +29 -2
- package/db/availability.db.js +1 -72
- package/db/availability.db.ts +1 -75
- package/interfaces/auth-user.interface.d.ts +7 -0
- package/interfaces/auth-user.interface.ts +8 -0
- package/models/AccountPayableItem.model.d.ts +3 -3
- package/models/AvailabilitySigns.model.d.ts +13 -0
- package/models/AvailabilitySigns.model.ts +15 -0
- package/models/BBCSheet.model.d.ts +4 -4
- package/models/BBCSheet.model.js +1 -2
- package/models/BBCSheet.model.ts +2 -3
- package/models/BorrowerCompliance.model.d.ts +3 -3
- package/models/BorrowerCompliance.model.js +1 -2
- package/models/BorrowerCompliance.model.ts +1 -2
- package/models/Globals.model.d.ts +4 -4
- package/models/Globals.model.js +1 -2
- package/models/Globals.model.ts +2 -3
- package/models/InventoryItem.model.d.ts +3 -3
- package/models/LoanStatementTransaction.model.d.ts +10 -10
- package/models/LoanStatementTransaction.model.js +1 -2
- package/models/LoanStatementTransaction.model.ts +2 -3
- package/models/LoanTransaction.model.d.ts +1 -1
- package/models/LoanTransaction.model.js +1 -2
- package/models/LoanTransaction.model.ts +2 -3
- package/models/MicroserviceTask.model.d.ts +4 -4
- package/models/MicroserviceTask.model.js +1 -2
- package/models/MicroserviceTask.model.ts +2 -3
- package/models/QueryResult.model.d.ts +1 -1
- package/models/QueryResult.model.js +1 -2
- package/models/QueryResult.model.ts +2 -3
- package/models/ReceivableAvailability.model.d.ts +4 -4
- package/models/ReceivableAvailability.model.js +1 -2
- package/models/ReceivableAvailability.model.ts +2 -3
- package/models/TransactionAttachedFile.Model.d.ts +7 -7
- package/models/TransactionAttachedFile.Model.js +1 -2
- package/models/TransactionAttachedFile.Model.ts +2 -3
- package/models/Underwriter.model.d.ts +1 -1
- package/models/Underwriter.model.js +1 -2
- package/models/Underwriter.model.ts +2 -3
- package/models/UploadedFile.model.d.ts +4 -4
- package/models/UploadedFile.model.js +1 -2
- package/models/UploadedFile.model.ts +2 -3
- package/models/UserLog.model.d.ts +1 -1
- package/models/UserLog.model.js +1 -2
- package/models/UserLog.model.ts +2 -3
- package/package.json +1 -1
- package/services/attached-files.service.js +1 -1
- package/services/attached-files.service.ts +1 -1
- package/services/availability.service.js +3 -4
- package/services/availability.service.ts +3 -4
- package/services/brokers.service.d.ts +2 -2
- package/services/compliance-borrowers.service.d.ts +1 -1
- package/services/compliance-borrowers.service.js +4 -4
- package/services/compliance-borrowers.service.ts +5 -5
- package/services/loan-payments.service.js +4 -4
- package/services/loan-payments.service.ts +4 -4
- package/services/loan-statement.service.d.ts +1 -1
- package/services/loan-transactions.service.d.ts +1 -1
- package/services/loan-transactions.service.js +2 -2
- package/services/loan-transactions.service.ts +2 -2
- package/services/signs.service.d.ts +1 -0
- package/services/signs.service.js +19 -2
- package/services/signs.service.ts +20 -2
- package/services/uploads.service.js +1 -1
- package/services/uploads.service.ts +1 -1
- package/services/users.service.d.ts +10 -9
- package/services/users.service.js +10 -3
- package/services/users.service.ts +21 -13
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -155,7 +155,7 @@ export declare class LoanTransactionsService {
|
|
|
155
155
|
getTransactionReport(transactionIds: string[], borrowerId: string, effectiveDate: Date): Promise<{
|
|
156
156
|
transactionIdsToMark: any[];
|
|
157
157
|
transactions: {
|
|
158
|
-
[x: string]: (string | number |
|
|
158
|
+
[x: string]: (string | number | string[] | Date)[];
|
|
159
159
|
}[];
|
|
160
160
|
}>;
|
|
161
161
|
getBorrowerIdsForFile(transactionFileId: string): Promise<{
|
|
@@ -215,7 +215,7 @@ class LoanTransactionsService {
|
|
|
215
215
|
balance: 0,
|
|
216
216
|
floatedBalance: 0,
|
|
217
217
|
effectiveDate: await this.calculateEffectiveDate(item),
|
|
218
|
-
userId
|
|
218
|
+
userId,
|
|
219
219
|
};
|
|
220
220
|
const newLoanTransaction = new LoanTransaction_model_1.LoanTransaction({
|
|
221
221
|
order: item.order,
|
|
@@ -283,7 +283,7 @@ class LoanTransactionsService {
|
|
|
283
283
|
transaction.amount = new decimal_js_1.default(transaction.amount).abs().neg().toNumber();
|
|
284
284
|
break;
|
|
285
285
|
}
|
|
286
|
-
transaction.userId =
|
|
286
|
+
transaction.userId = userId;
|
|
287
287
|
return transaction;
|
|
288
288
|
}
|
|
289
289
|
async createLoanTransaction(transaction) {
|
|
@@ -264,7 +264,7 @@ export class LoanTransactionsService {
|
|
|
264
264
|
balance: 0,
|
|
265
265
|
floatedBalance: 0,
|
|
266
266
|
effectiveDate: await this.calculateEffectiveDate(item),
|
|
267
|
-
userId
|
|
267
|
+
userId,
|
|
268
268
|
};
|
|
269
269
|
const newLoanTransaction = new LoanTransaction({
|
|
270
270
|
order: item.order,
|
|
@@ -337,7 +337,7 @@ export class LoanTransactionsService {
|
|
|
337
337
|
transaction.amount = new Decimal(transaction.amount).abs().neg().toNumber();
|
|
338
338
|
break;
|
|
339
339
|
}
|
|
340
|
-
transaction.userId =
|
|
340
|
+
transaction.userId = userId;
|
|
341
341
|
return transaction;
|
|
342
342
|
}
|
|
343
343
|
|
|
@@ -51,6 +51,7 @@ export declare class SignsService {
|
|
|
51
51
|
users: IUser[];
|
|
52
52
|
fulfillUserList(): Promise<void>;
|
|
53
53
|
clearUserList(): void;
|
|
54
|
+
getAvailabilitiesSigns(bbcDateIds: string[]): Promise<IAvailabilitySignView[]>;
|
|
54
55
|
getAvailabilitySigns(bbcDateId: string): Promise<IAvailabilitySignView>;
|
|
55
56
|
revokeAvailability(bbcDateId: string, userId: string, userIdRevoked: string): Promise<void>;
|
|
56
57
|
signAvailability(bbcDateId: string, user: IUser): Promise<IResult>;
|
|
@@ -39,8 +39,25 @@ class SignsService {
|
|
|
39
39
|
clearUserList() {
|
|
40
40
|
this.users = null;
|
|
41
41
|
}
|
|
42
|
+
async getAvailabilitiesSigns(bbcDateIds) {
|
|
43
|
+
const availabilitySigns = await (0, availability_db_1.getAvailabilitySigns)(bbcDateIds);
|
|
44
|
+
const users = await this.usersService.getUserList();
|
|
45
|
+
const usersMap = users.reduce((acc, user) => {
|
|
46
|
+
return { ...acc, [user.id]: user };
|
|
47
|
+
}, {});
|
|
48
|
+
return availabilitySigns.map((availabilitySign) => {
|
|
49
|
+
return {
|
|
50
|
+
...availabilitySign,
|
|
51
|
+
signs: availabilitySign.signs.map((sign) => ({
|
|
52
|
+
...sign,
|
|
53
|
+
userSigned: usersMap[sign.userSignedId],
|
|
54
|
+
userRevoked: usersMap[sign.userRevokedId],
|
|
55
|
+
}))
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
42
59
|
async getAvailabilitySigns(bbcDateId) {
|
|
43
|
-
const availabilitiesSigns = await
|
|
60
|
+
const availabilitiesSigns = await this.getAvailabilitiesSigns([bbcDateId]);
|
|
44
61
|
if (!availabilitiesSigns.length) {
|
|
45
62
|
return {
|
|
46
63
|
_id: null,
|
|
@@ -202,7 +219,7 @@ class SignsService {
|
|
|
202
219
|
},
|
|
203
220
|
...(0, collaterals_db_1.ITEMS_PAGINATION)(paginatorOptions),
|
|
204
221
|
]);
|
|
205
|
-
const availabilitiesSigns = await
|
|
222
|
+
const availabilitiesSigns = await this.getAvailabilitiesSigns(BBCDates.map((bbcDate) => bbcDate._id.toString()));
|
|
206
223
|
await Promise.all(BBCDates.slice().map(async (bbcDate) => {
|
|
207
224
|
const foundAvailabilitySigns = availabilitiesSigns.find((aSigns) => aSigns.bbcDateId.toString() === bbcDate._id.toString());
|
|
208
225
|
if (!foundAvailabilitySigns) {
|
|
@@ -60,8 +60,26 @@ export class SignsService {
|
|
|
60
60
|
this.users = null;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
async getAvailabilitiesSigns(bbcDateIds: string[]): Promise<IAvailabilitySignView[]> {
|
|
64
|
+
const availabilitySigns = await getAvailabilitySigns(bbcDateIds);
|
|
65
|
+
const users = await this.usersService.getUserList();
|
|
66
|
+
const usersMap = users.reduce((acc, user) => {
|
|
67
|
+
return { ...acc, [user.id]: user };
|
|
68
|
+
}, <Record<string, IUser>>{});
|
|
69
|
+
return availabilitySigns.map((availabilitySign) => {
|
|
70
|
+
return {
|
|
71
|
+
...availabilitySign,
|
|
72
|
+
signs: availabilitySign.signs.map((sign) => ({
|
|
73
|
+
...sign,
|
|
74
|
+
userSigned: usersMap[sign.userSignedId],
|
|
75
|
+
userRevoked: usersMap[sign.userRevokedId],
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
78
|
+
}) as unknown as IAvailabilitySignView[];
|
|
79
|
+
}
|
|
80
|
+
|
|
63
81
|
async getAvailabilitySigns(bbcDateId: string): Promise<IAvailabilitySignView> {
|
|
64
|
-
const availabilitiesSigns = await
|
|
82
|
+
const availabilitiesSigns = await this.getAvailabilitiesSigns([bbcDateId]);
|
|
65
83
|
if (!availabilitiesSigns.length) {
|
|
66
84
|
return <IAvailabilitySignView>{
|
|
67
85
|
_id: null,
|
|
@@ -233,7 +251,7 @@ export class SignsService {
|
|
|
233
251
|
...ITEMS_PAGINATION(paginatorOptions),
|
|
234
252
|
]);
|
|
235
253
|
|
|
236
|
-
const availabilitiesSigns = await
|
|
254
|
+
const availabilitiesSigns = await this.getAvailabilitiesSigns(BBCDates.map((bbcDate) => bbcDate._id.toString()));
|
|
237
255
|
await Promise.all(BBCDates.slice().map(async (bbcDate) => {
|
|
238
256
|
const foundAvailabilitySigns = availabilitiesSigns.find((aSigns) => aSigns.bbcDateId.toString() ===bbcDate._id.toString());
|
|
239
257
|
if (!foundAvailabilitySigns) {
|
|
@@ -118,7 +118,7 @@ class UploadsService {
|
|
|
118
118
|
borrowerId: borrowerIdToWrite,
|
|
119
119
|
filename: file.filename,
|
|
120
120
|
originalName: file.originalname,
|
|
121
|
-
userId
|
|
121
|
+
userId,
|
|
122
122
|
type: uploadType,
|
|
123
123
|
};
|
|
124
124
|
return await UploadedFile_model_1.default.create(newFile);
|
|
@@ -139,7 +139,7 @@ export class UploadsService {
|
|
|
139
139
|
borrowerId: borrowerIdToWrite,
|
|
140
140
|
filename: file.filename,
|
|
141
141
|
originalName: file.originalname,
|
|
142
|
-
userId
|
|
142
|
+
userId,
|
|
143
143
|
type: uploadType,
|
|
144
144
|
};
|
|
145
145
|
return await UploadedFile.create(newFile);
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
/// <reference types="mongoose/types/utility" />
|
|
22
22
|
/// <reference types="mongoose/types/validation" />
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose" />
|
|
24
25
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
26
|
import express from 'express';
|
|
26
|
-
import
|
|
27
|
-
import { IUser } from '../interfaces/auth-user.interface';
|
|
27
|
+
import { IRole, IUser } from '../interfaces/auth-user.interface';
|
|
28
28
|
interface IKeycloakConfig {
|
|
29
29
|
keycloakHost: string;
|
|
30
30
|
realm: string;
|
|
@@ -36,12 +36,13 @@ export declare class UsersService {
|
|
|
36
36
|
private readonly config;
|
|
37
37
|
constructor(config: IKeycloakConfig);
|
|
38
38
|
getUserAccessByRequest(req: express.Request): Promise<IUser | null>;
|
|
39
|
-
getUserById(userId: string): Promise<IUser
|
|
40
|
-
getUserByUsername(username: string): Promise<IUser
|
|
41
|
-
getUserByToken(req: express.Request): Promise<IUser
|
|
42
|
-
getUserIdByToken(req: express.Request): Promise<string
|
|
39
|
+
getUserById(userId: string): Promise<IUser>;
|
|
40
|
+
getUserByUsername(username: string): Promise<IUser>;
|
|
41
|
+
getUserByToken(req: express.Request): Promise<IUser>;
|
|
42
|
+
getUserIdByToken(req: express.Request): Promise<string>;
|
|
43
43
|
getUserList(): Promise<IUser[]>;
|
|
44
|
-
|
|
44
|
+
getAllRoles(): Promise<IRole[]>;
|
|
45
|
+
getUserRoles(userId: string): Promise<string[]>;
|
|
45
46
|
updateMobileUser(userId: string, keyValue: {
|
|
46
47
|
[key: string]: string | number | boolean;
|
|
47
48
|
}): Promise<void>;
|
|
@@ -53,8 +54,8 @@ export declare class UsersService {
|
|
|
53
54
|
}[];
|
|
54
55
|
}>;
|
|
55
56
|
createUserLoginLog(): Promise<void>;
|
|
56
|
-
getUserLogByDate(userId: string, date: Date): Promise<mongoose.FlattenMaps<import("../models/UserLog.model").IUserLog> & Required<{
|
|
57
|
-
_id: mongoose.Types.ObjectId;
|
|
57
|
+
getUserLogByDate(userId: string, date: Date): Promise<import("mongoose").FlattenMaps<import("../models/UserLog.model").IUserLog> & Required<{
|
|
58
|
+
_id: import("mongoose").Types.ObjectId;
|
|
58
59
|
}>>;
|
|
59
60
|
}
|
|
60
61
|
export {};
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.UsersService = void 0;
|
|
7
7
|
const jwt_decode_1 = require("jwt-decode");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
9
|
const BorrowerCompliance_model_1 = require("../models/BorrowerCompliance.model");
|
|
11
10
|
const UserMobileAccess_model_1 = require("../models/UserMobileAccess.model");
|
|
12
11
|
const UserLog_model_1 = require("../models/UserLog.model");
|
|
@@ -54,9 +53,17 @@ class UsersService {
|
|
|
54
53
|
const { data } = await axios_1.default.get(`${this.config.baseUrl}/users/users`);
|
|
55
54
|
return data ?? null;
|
|
56
55
|
}
|
|
56
|
+
async getAllRoles() {
|
|
57
|
+
const { data } = await axios_1.default.get(`${this.config.baseUrl}/users/roles`);
|
|
58
|
+
return data ?? null;
|
|
59
|
+
}
|
|
57
60
|
async getUserRoles(userId) {
|
|
58
61
|
const user = await this.getUserById(userId);
|
|
59
|
-
|
|
62
|
+
const roles = await this.getAllRoles();
|
|
63
|
+
const userRoleIds = Object.values(user.roles).reduce((acc, roleIds) => [...acc, ...roleIds], []);
|
|
64
|
+
return roles
|
|
65
|
+
.filter((role) => userRoleIds.includes(role.id))
|
|
66
|
+
.map((role) => role.name);
|
|
60
67
|
}
|
|
61
68
|
async updateMobileUser(userId, keyValue) {
|
|
62
69
|
await UserMobileAccess_model_1.UserMobileAccess.findOneAndUpdate({ keycloakUserId: userId }, keyValue, { upsert: true });
|
|
@@ -121,7 +128,7 @@ class UsersService {
|
|
|
121
128
|
// }
|
|
122
129
|
}
|
|
123
130
|
async getUserLogByDate(userId, date) {
|
|
124
|
-
return UserLog_model_1.UserLog.findOne({ userId
|
|
131
|
+
return UserLog_model_1.UserLog.findOne({ userId, timestamp: date }).lean();
|
|
125
132
|
}
|
|
126
133
|
}
|
|
127
134
|
exports.UsersService = UsersService;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { jwtDecode } from 'jwt-decode';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
-
import mongoose from 'mongoose';
|
|
5
4
|
|
|
6
5
|
import { BorrowerCompliance } from '../models/BorrowerCompliance.model';
|
|
7
6
|
import { UserMobileAccess } from '../models/UserMobileAccess.model';
|
|
8
7
|
import { UserLog } from '../models/UserLog.model';
|
|
9
|
-
import { IUser } from '../interfaces/auth-user.interface';
|
|
8
|
+
import { IRole, IUser } from '../interfaces/auth-user.interface';
|
|
10
9
|
|
|
11
10
|
interface IKeycloakConfig {
|
|
12
11
|
keycloakHost: string;
|
|
@@ -36,17 +35,17 @@ export class UsersService {
|
|
|
36
35
|
return user;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
async getUserById(userId: string)
|
|
40
|
-
const { data } = await axios.get(`${this.config.baseUrl}/users/by-id/${userId}`);
|
|
38
|
+
async getUserById(userId: string) {
|
|
39
|
+
const { data } = await axios.get<IUser>(`${this.config.baseUrl}/users/by-id/${userId}`);
|
|
41
40
|
return data ?? null;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
async getUserByUsername(username: string)
|
|
45
|
-
const { data } = await axios.get(`${this.config.baseUrl}/users/by-username/${username}`);
|
|
43
|
+
async getUserByUsername(username: string) {
|
|
44
|
+
const { data } = await axios.get<IUser>(`${this.config.baseUrl}/users/by-username/${username}`);
|
|
46
45
|
return data ?? null;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
async getUserByToken(req: express.Request)
|
|
48
|
+
async getUserByToken(req: express.Request) {
|
|
50
49
|
const authorization = req.get('Authorization');
|
|
51
50
|
if (!authorization) {
|
|
52
51
|
return null;
|
|
@@ -55,7 +54,7 @@ export class UsersService {
|
|
|
55
54
|
return this.getUserById(keycloakUserId);
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
async getUserIdByToken(req: express.Request)
|
|
57
|
+
async getUserIdByToken(req: express.Request) {
|
|
59
58
|
const user = await this.getUserByToken(req);
|
|
60
59
|
if (user) {
|
|
61
60
|
return user.id;
|
|
@@ -63,14 +62,23 @@ export class UsersService {
|
|
|
63
62
|
return null;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
async getUserList()
|
|
67
|
-
const { data } = await axios.get(`${this.config.baseUrl}/users/users`);
|
|
65
|
+
async getUserList() {
|
|
66
|
+
const { data } = await axios.get<IUser[]>(`${this.config.baseUrl}/users/users`);
|
|
68
67
|
return data ?? null;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
async
|
|
70
|
+
async getAllRoles() {
|
|
71
|
+
const { data } = await axios.get<IRole[]>(`${this.config.baseUrl}/users/roles`);
|
|
72
|
+
return data ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getUserRoles(userId: string) {
|
|
72
76
|
const user = await this.getUserById(userId);
|
|
73
|
-
|
|
77
|
+
const roles = await this.getAllRoles();
|
|
78
|
+
const userRoleIds = Object.values(user.roles).reduce((acc, roleIds) => [...acc, ...roleIds], []);
|
|
79
|
+
return roles
|
|
80
|
+
.filter((role) => userRoleIds.includes(role.id))
|
|
81
|
+
.map((role) => role.name);
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
async updateMobileUser(userId: string, keyValue: { [key: string]: string | number | boolean }) {
|
|
@@ -140,6 +148,6 @@ export class UsersService {
|
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
async getUserLogByDate(userId: string, date: Date) {
|
|
143
|
-
return UserLog.findOne({ userId
|
|
151
|
+
return UserLog.findOne({ userId, timestamp: date }).lean();
|
|
144
152
|
}
|
|
145
153
|
}
|