gemcap-be-common 1.4.8 → 1.4.10

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.
@@ -5,7 +5,12 @@ export interface IUserBasic {
5
5
  firstName: string | null;
6
6
  lastName: string | null;
7
7
  }
8
- export interface IUser extends IUserBasic {
8
+ export interface IUserAccess {
9
+ allBorrowers?: boolean;
10
+ borrowersAccess?: string[];
11
+ complianceBorrowersAccess?: string[];
12
+ }
13
+ export interface IUser extends IUserBasic, IUserAccess {
9
14
  createdAt?: Date;
10
15
  updatedAt?: Date;
11
16
  passwordResetTokenHash?: string | null;
@@ -15,14 +20,15 @@ export interface IUser extends IUserBasic {
15
20
  roles?: Record<string, string[]>;
16
21
  deletedAt?: Date | null;
17
22
  isEnabled?: boolean;
18
- allBorrowers?: boolean;
19
- borrowersAccess?: string[];
20
23
  lastLogin?: Date | null;
21
24
  }
22
- export interface IRole {
25
+ export interface IUserRole {
23
26
  id: string;
24
27
  name: string;
25
28
  representation: string;
26
29
  createdAt?: Date;
27
30
  updatedAt?: Date;
28
31
  }
32
+ export interface IGroupedUserRoles {
33
+ [module: string]: IUserRole[];
34
+ }
@@ -6,7 +6,13 @@ export interface IUserBasic {
6
6
  lastName: string | null;
7
7
  }
8
8
 
9
- export interface IUser extends IUserBasic {
9
+ export interface IUserAccess {
10
+ allBorrowers?: boolean;
11
+ borrowersAccess?: string[];
12
+ complianceBorrowersAccess?: string[];
13
+ }
14
+
15
+ export interface IUser extends IUserBasic, IUserAccess {
10
16
  createdAt?: Date;
11
17
  updatedAt?: Date;
12
18
  passwordResetTokenHash?: string | null;
@@ -16,15 +22,17 @@ export interface IUser extends IUserBasic {
16
22
  roles?: Record<string, string[]>;
17
23
  deletedAt?: Date | null;
18
24
  isEnabled?: boolean;
19
- allBorrowers?: boolean;
20
- borrowersAccess?: string[];
21
25
  lastLogin?: Date | null;
22
26
  }
23
27
 
24
- export interface IRole {
28
+ export interface IUserRole {
25
29
  id: string;
26
30
  name: string;
27
31
  representation: string;
28
32
  createdAt?: Date;
29
33
  updatedAt?: Date;
30
34
  }
35
+
36
+ export interface IGroupedUserRoles {
37
+ [module: string]: IUserRole[];
38
+ }
@@ -184,49 +184,49 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
184
184
  createdAt: NativeDate;
185
185
  updatedAt: NativeDate;
186
186
  } & {
187
- bbcDateId: mongoose.Types.ObjectId;
188
187
  borrowerId: mongoose.Types.ObjectId;
188
+ bbcDateId: mongoose.Types.ObjectId;
189
189
  useManualInputs: boolean;
190
190
  __v?: number;
191
191
  summary?: {
192
192
  invoiceAmount: number;
193
- creditNotes: number;
194
- excludedCustomerDeduction: number;
195
193
  grossAR: number;
194
+ balanceAfterCrossAge: number;
196
195
  permittedOver: number;
197
- preliminaryEligibleBalance: number;
198
- creditNotesNegative: number;
196
+ creditNotes: number;
197
+ excludedCustomerDeduction: number;
199
198
  deduction: number;
200
199
  partiallyPaidDeduction: number;
201
200
  contraDeduction: number;
202
201
  crossAgeDeduction: number;
203
202
  waivedDeduction: number;
204
- balanceAfterCrossAge: number;
205
203
  finalResult: number;
206
204
  insuredComponent: number;
205
+ preliminaryEligibleBalance: number;
207
206
  uninsuredComponent: number;
208
207
  insuredAvailability: number;
209
208
  uninsuredAvailability: number;
209
+ creditNotesNegative: number;
210
210
  ARReserves: number;
211
211
  ARAvailability: number;
212
212
  };
213
- actual?: boolean;
214
213
  userCalculatedId?: string;
215
214
  calculatedAt?: Date;
215
+ actual?: boolean;
216
216
  settings?: {
217
217
  excludedCustomers: mongoose.Types.DocumentArray<{
218
218
  limit?: number;
219
219
  customer?: string;
220
220
  }>;
221
- insuredCustomers: mongoose.Types.DocumentArray<{
221
+ permittedConcentration: mongoose.Types.DocumentArray<{
222
222
  limit?: number;
223
223
  customer?: string;
224
224
  }>;
225
- permittedConcentration: mongoose.Types.DocumentArray<{
225
+ permittedExtendedARDays: mongoose.Types.DocumentArray<{
226
226
  limit?: number;
227
227
  customer?: string;
228
228
  }>;
229
- permittedExtendedARDays: mongoose.Types.DocumentArray<{
229
+ insuredCustomers: mongoose.Types.DocumentArray<{
230
230
  limit?: number;
231
231
  customer?: string;
232
232
  }>;
@@ -244,49 +244,49 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
244
244
  createdAt: NativeDate;
245
245
  updatedAt: NativeDate;
246
246
  } & {
247
- bbcDateId: mongoose.Types.ObjectId;
248
247
  borrowerId: mongoose.Types.ObjectId;
248
+ bbcDateId: mongoose.Types.ObjectId;
249
249
  useManualInputs: boolean;
250
250
  __v?: number;
251
251
  summary?: {
252
252
  invoiceAmount: number;
253
- creditNotes: number;
254
- excludedCustomerDeduction: number;
255
253
  grossAR: number;
254
+ balanceAfterCrossAge: number;
256
255
  permittedOver: number;
257
- preliminaryEligibleBalance: number;
258
- creditNotesNegative: number;
256
+ creditNotes: number;
257
+ excludedCustomerDeduction: number;
259
258
  deduction: number;
260
259
  partiallyPaidDeduction: number;
261
260
  contraDeduction: number;
262
261
  crossAgeDeduction: number;
263
262
  waivedDeduction: number;
264
- balanceAfterCrossAge: number;
265
263
  finalResult: number;
266
264
  insuredComponent: number;
265
+ preliminaryEligibleBalance: number;
267
266
  uninsuredComponent: number;
268
267
  insuredAvailability: number;
269
268
  uninsuredAvailability: number;
269
+ creditNotesNegative: number;
270
270
  ARReserves: number;
271
271
  ARAvailability: number;
272
272
  };
273
- actual?: boolean;
274
273
  userCalculatedId?: string;
275
274
  calculatedAt?: Date;
275
+ actual?: boolean;
276
276
  settings?: {
277
277
  excludedCustomers: mongoose.Types.DocumentArray<{
278
278
  limit?: number;
279
279
  customer?: string;
280
280
  }>;
281
- insuredCustomers: mongoose.Types.DocumentArray<{
281
+ permittedConcentration: mongoose.Types.DocumentArray<{
282
282
  limit?: number;
283
283
  customer?: string;
284
284
  }>;
285
- permittedConcentration: mongoose.Types.DocumentArray<{
285
+ permittedExtendedARDays: mongoose.Types.DocumentArray<{
286
286
  limit?: number;
287
287
  customer?: string;
288
288
  }>;
289
- permittedExtendedARDays: mongoose.Types.DocumentArray<{
289
+ insuredCustomers: mongoose.Types.DocumentArray<{
290
290
  limit?: number;
291
291
  customer?: string;
292
292
  }>;
@@ -304,49 +304,49 @@ export declare const AvailabilitySchema: mongoose.Schema<any, mongoose.Model<any
304
304
  createdAt: NativeDate;
305
305
  updatedAt: NativeDate;
306
306
  } & {
307
- bbcDateId: mongoose.Types.ObjectId;
308
307
  borrowerId: mongoose.Types.ObjectId;
308
+ bbcDateId: mongoose.Types.ObjectId;
309
309
  useManualInputs: boolean;
310
310
  __v?: number;
311
311
  summary?: {
312
312
  invoiceAmount: number;
313
- creditNotes: number;
314
- excludedCustomerDeduction: number;
315
313
  grossAR: number;
314
+ balanceAfterCrossAge: number;
316
315
  permittedOver: number;
317
- preliminaryEligibleBalance: number;
318
- creditNotesNegative: number;
316
+ creditNotes: number;
317
+ excludedCustomerDeduction: number;
319
318
  deduction: number;
320
319
  partiallyPaidDeduction: number;
321
320
  contraDeduction: number;
322
321
  crossAgeDeduction: number;
323
322
  waivedDeduction: number;
324
- balanceAfterCrossAge: number;
325
323
  finalResult: number;
326
324
  insuredComponent: number;
325
+ preliminaryEligibleBalance: number;
327
326
  uninsuredComponent: number;
328
327
  insuredAvailability: number;
329
328
  uninsuredAvailability: number;
329
+ creditNotesNegative: number;
330
330
  ARReserves: number;
331
331
  ARAvailability: number;
332
332
  };
333
- actual?: boolean;
334
333
  userCalculatedId?: string;
335
334
  calculatedAt?: Date;
335
+ actual?: boolean;
336
336
  settings?: {
337
337
  excludedCustomers: mongoose.Types.DocumentArray<{
338
338
  limit?: number;
339
339
  customer?: string;
340
340
  }>;
341
- insuredCustomers: mongoose.Types.DocumentArray<{
341
+ permittedConcentration: mongoose.Types.DocumentArray<{
342
342
  limit?: number;
343
343
  customer?: string;
344
344
  }>;
345
- permittedConcentration: mongoose.Types.DocumentArray<{
345
+ permittedExtendedARDays: mongoose.Types.DocumentArray<{
346
346
  limit?: number;
347
347
  customer?: string;
348
348
  }>;
349
- permittedExtendedARDays: mongoose.Types.DocumentArray<{
349
+ insuredCustomers: mongoose.Types.DocumentArray<{
350
350
  limit?: number;
351
351
  customer?: string;
352
352
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -46,9 +46,9 @@ export declare class BrokersService {
46
46
  getAllProductBrokers(): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
47
47
  _id: import("mongoose").Types.ObjectId;
48
48
  })[]>;
49
- getBorrowerBrokers(borrowerId: string): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
49
+ getBorrowerBrokers(borrowerId: string): Promise<BrokerView[] | (import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
50
50
  _id: import("mongoose").Types.ObjectId;
51
- })[] | BrokerView[]>;
51
+ })[]>;
52
52
  getProductBrokers(productId: string): Promise<import("../models/ProductBroker.model").IProductBrokerDocWithBroker[]>;
53
53
  getTotalShares(borrowerId: string, brokers: IProductBrokerView[], replaceNames?: boolean): Promise<ProductTotal>;
54
54
  getTotals(borrowerId: string): Promise<BrokerTotalView[]>;
@@ -26,14 +26,14 @@ import mongoose from 'mongoose';
26
26
  import { IEmailRecipient } from '../models/ComplianceItem.model';
27
27
  import { IGroupedEmailsUpdate } from '../interfaces/email-addresses.interface';
28
28
  import { IComplianceBorrowerDocument, IComplianceBorrowerDocumentFull } from '../models/BorrowerCompliance.model';
29
- import { IUser } from '../interfaces/auth-user.interface';
29
+ import { IUser, IUserAccess } from '../interfaces/auth-user.interface';
30
30
  import { FileManagerService } from './file-manager.service';
31
31
  import { UploadsService } from './uploads.service';
32
32
  export declare class ComplianceBorrowersService {
33
33
  private readonly _fileManagerService;
34
34
  private readonly _uploadsService;
35
35
  constructor(_fileManagerService: FileManagerService, _uploadsService: UploadsService);
36
- isComplianceBorrowerAllowed(userAccess: any, requestedBorrowerId: any): boolean;
36
+ isComplianceBorrowerAllowed(userAccess: IUserAccess, requestedBorrowerId: string): boolean;
37
37
  calculateInstanceStatuses(instance: any, item: any): {
38
38
  progress: {
39
39
  text: string;
@@ -45,7 +45,7 @@ export declare class ComplianceBorrowersService {
45
45
  };
46
46
  };
47
47
  getFullComplianceBorrowerById(complianceBorrowerId: string): Promise<any>;
48
- getAllBorrowersShortened(userAccess: any): Promise<(Pick<IComplianceBorrowerDocument, "borrower" | "fundingStatus" | "items"> | {
48
+ getAllBorrowersShortened(userAccess: any): Promise<(Pick<IComplianceBorrowerDocument, "items" | "borrower" | "fundingStatus"> | {
49
49
  items: {
50
50
  instances: any[];
51
51
  item: import("../models/ComplianceItem.model").IComplianceItemDocument;
@@ -33,7 +33,7 @@ class ComplianceBorrowersService {
33
33
  this._uploadsService = _uploadsService;
34
34
  }
35
35
  isComplianceBorrowerAllowed(userAccess, requestedBorrowerId) {
36
- const allowedBorrower = userAccess.complianceBorrowersAccess.some((b) => b.borrower === requestedBorrowerId);
36
+ const allowedBorrower = userAccess.complianceBorrowersAccess.includes(requestedBorrowerId);
37
37
  if (!allowedBorrower) {
38
38
  throw new Error('Non allowed compliance borrower');
39
39
  }
@@ -11,7 +11,7 @@ import {
11
11
  IComplianceBorrowerDocumentFull,
12
12
  } from '../models/BorrowerCompliance.model';
13
13
  import { BorrowerModel } from '../models/Borrower.model';
14
- import { IUser } from '../interfaces/auth-user.interface';
14
+ import { IUser, IUserAccess } from '../interfaces/auth-user.interface';
15
15
  import FinancialComplianceBorrower from '../models/FinancialComplianceBorrower.model';
16
16
  import { FileManagerService } from './file-manager.service';
17
17
  import { UploadsService } from './uploads.service';
@@ -42,8 +42,8 @@ export class ComplianceBorrowersService {
42
42
  ) {
43
43
  }
44
44
 
45
- isComplianceBorrowerAllowed(userAccess, requestedBorrowerId): boolean {
46
- const allowedBorrower = userAccess.complianceBorrowersAccess.some((b) => b.borrower === requestedBorrowerId);
45
+ isComplianceBorrowerAllowed(userAccess: IUserAccess, requestedBorrowerId: string): boolean {
46
+ const allowedBorrower = userAccess.complianceBorrowersAccess.includes(requestedBorrowerId);
47
47
  if (!allowedBorrower) {
48
48
  throw new Error('Non allowed compliance borrower');
49
49
  }
@@ -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 | Date | string[])[];
158
+ [x: string]: (string | number | string[] | Date)[];
159
159
  }[];
160
160
  }>;
161
161
  getBorrowerIdsForFile(transactionFileId: string): Promise<{
@@ -24,7 +24,7 @@
24
24
  /// <reference types="mongoose" />
25
25
  /// <reference types="mongoose/types/inferschematype" />
26
26
  import express from 'express';
27
- import { IRole, IUser } from '../interfaces/auth-user.interface';
27
+ import { IUserRole, IUser, IUserAccess } from '../interfaces/auth-user.interface';
28
28
  interface IKeycloakConfig {
29
29
  keycloakHost: string;
30
30
  realm: string;
@@ -41,18 +41,12 @@ export declare class UsersService {
41
41
  getUserByToken(req: express.Request): Promise<IUser>;
42
42
  getUserIdByToken(req: express.Request): Promise<string>;
43
43
  getUserList(): Promise<IUser[]>;
44
- getAllRoles(): Promise<IRole[]>;
44
+ getAllRoles(): Promise<IUserRole[]>;
45
45
  getUserRoles(userId: string): Promise<string[]>;
46
46
  updateMobileUser(userId: string, keyValue: {
47
47
  [key: string]: string | number | boolean;
48
48
  }): Promise<void>;
49
- getUserAccess(userId: string): Promise<{
50
- allBorrowers: boolean;
51
- borrowersAccess: string[];
52
- complianceBorrowersAccess: {
53
- borrower: any;
54
- }[];
55
- }>;
49
+ getUserAccess(userId: string): Promise<IUserAccess>;
56
50
  createUserLoginLog(): Promise<void>;
57
51
  getUserLogByDate(userId: string, date: Date): Promise<import("mongoose").FlattenMaps<import("../models/UserLog.model").IUserLog> & Required<{
58
52
  _id: import("mongoose").Types.ObjectId;
@@ -72,7 +72,7 @@ class UsersService {
72
72
  const foundUser = await this.getUserById(userId);
73
73
  const borrowersAccess = foundUser.borrowersAccess;
74
74
  const complianceBorrowersAccess = (await BorrowerCompliance_model_1.BorrowerCompliance.find({ 'borrower': { $in: borrowersAccess } }))
75
- .map((b) => ({ borrower: b._id.toString() }));
75
+ .map((b) => b._id.toString());
76
76
  return { allBorrowers: foundUser.allBorrowers, borrowersAccess, complianceBorrowersAccess };
77
77
  }
78
78
  async createUserLoginLog() {
@@ -5,7 +5,7 @@ import axios from 'axios';
5
5
  import { BorrowerCompliance } from '../models/BorrowerCompliance.model';
6
6
  import { UserMobileAccess } from '../models/UserMobileAccess.model';
7
7
  import { UserLog } from '../models/UserLog.model';
8
- import { IRole, IUser } from '../interfaces/auth-user.interface';
8
+ import { IUserRole, IUser, IUserAccess } from '../interfaces/auth-user.interface';
9
9
 
10
10
  interface IKeycloakConfig {
11
11
  keycloakHost: string;
@@ -68,7 +68,7 @@ export class UsersService {
68
68
  }
69
69
 
70
70
  async getAllRoles() {
71
- const { data } = await axios.get<IRole[]>(`${this.config.baseUrl}/users/roles`);
71
+ const { data } = await axios.get<IUserRole[]>(`${this.config.baseUrl}/users/roles`);
72
72
  return data ?? null;
73
73
  }
74
74
 
@@ -85,12 +85,12 @@ export class UsersService {
85
85
  await UserMobileAccess.findOneAndUpdate({ keycloakUserId: userId }, keyValue, { upsert: true });
86
86
  }
87
87
 
88
- async getUserAccess(userId: string) {
88
+ async getUserAccess(userId: string): Promise<IUserAccess> {
89
89
  const foundUser = await this.getUserById(userId);
90
90
  const borrowersAccess = foundUser.borrowersAccess;
91
91
  const complianceBorrowersAccess =
92
92
  (await BorrowerCompliance.find({ 'borrower': { $in: borrowersAccess } }))
93
- .map((b) => ({ borrower: b._id.toString() }));
93
+ .map((b) => b._id.toString());
94
94
  return { allBorrowers: foundUser.allBorrowers, borrowersAccess, complianceBorrowersAccess };
95
95
  }
96
96