gemcap-be-common 1.5.127 → 1.5.129

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.
@@ -27,5 +27,6 @@ import Joi from 'joi';
27
27
  export type TDictionary = Record<string, string | object>;
28
28
  export declare const fieldsToUnset: string[];
29
29
  export declare const removeFields: <T>(document: mongoose.Document, fieldsToUnset: string[]) => T;
30
+ export declare const sanitizePlainObject: <T extends object>(object: T, fieldsToUnset?: string[]) => T;
30
31
  export declare const replaceErrors: (error: Joi.ValidationError, dictionary: TDictionary) => string;
31
32
  export declare const getUUID: () => string;
@@ -3,7 +3,7 @@ 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.getUUID = exports.replaceErrors = exports.removeFields = exports.fieldsToUnset = void 0;
6
+ exports.getUUID = exports.replaceErrors = exports.sanitizePlainObject = exports.removeFields = exports.fieldsToUnset = void 0;
7
7
  const mongoose_1 = __importDefault(require("mongoose"));
8
8
  const uuid_1 = require("uuid");
9
9
  exports.fieldsToUnset = ['__v', 'createdAt', 'updatedAt'];
@@ -41,6 +41,14 @@ const removeFields = (document, fieldsToUnset) => {
41
41
  });
42
42
  };
43
43
  exports.removeFields = removeFields;
44
+ const sanitizePlainObject = (object, fieldsToUnset = []) => {
45
+ const clone = deepCloneAndConvertMaps(object);
46
+ fieldsToUnset.forEach((field) => {
47
+ delete clone[field];
48
+ });
49
+ return clone;
50
+ };
51
+ exports.sanitizePlainObject = sanitizePlainObject;
44
52
  const replaceErrors = (error, dictionary) => {
45
53
  const getValue = (d, keys) => {
46
54
  let currentValue = d;
@@ -41,6 +41,16 @@ export const removeFields = <T>(document: mongoose.Document, fieldsToUnset: stri
41
41
  });
42
42
  };
43
43
 
44
+ export const sanitizePlainObject = <T extends object>(object: T, fieldsToUnset: string[] = []): T => {
45
+ const clone = deepCloneAndConvertMaps(object);
46
+
47
+ fieldsToUnset.forEach((field) => {
48
+ delete (clone as Record<string, unknown>)[field];
49
+ });
50
+
51
+ return clone;
52
+ };
53
+
44
54
  export const replaceErrors = (error: Joi.ValidationError, dictionary: TDictionary) => {
45
55
  const getValue = (d: TDictionary, keys: string[]): string => {
46
56
  let currentValue: TDictionary | string = d;
@@ -31,6 +31,8 @@ import mongoose from 'mongoose';
31
31
  import { TModelName } from './_models';
32
32
  import { TTaskStatus } from '../interfaces/task.interface';
33
33
  export declare const AI_JOBS_FOLDER = "AI_jobs";
34
+ export declare const AI_JOB_TYPES: readonly ["loan-memo-excel", "approval-memo", "email-summary"];
35
+ export type TAIJobType = (typeof AI_JOB_TYPES)[number];
34
36
  export interface IAIJobResponseChunk {
35
37
  type: 'text' | 'thinking' | 'tool' | 'status';
36
38
  timestamp: Date;
@@ -68,6 +70,7 @@ export interface IAIJobTarget {
68
70
  export interface IAIJob {
69
71
  taskId: string;
70
72
  userId: string;
73
+ taskType: TAIJobType;
71
74
  status: TTaskStatus;
72
75
  target: IAIJobTarget;
73
76
  context: unknown;
@@ -3,10 +3,15 @@ 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.AIJob = exports.AIJobSchema = exports.AI_JOBS_FOLDER = void 0;
6
+ exports.AIJob = exports.AIJobSchema = exports.AI_JOB_TYPES = exports.AI_JOBS_FOLDER = void 0;
7
7
  const mongoose_1 = __importDefault(require("mongoose"));
8
8
  const _models_1 = require("./_models");
9
9
  exports.AI_JOBS_FOLDER = 'AI_jobs';
10
+ exports.AI_JOB_TYPES = [
11
+ 'loan-memo-excel',
12
+ 'approval-memo',
13
+ 'email-summary',
14
+ ];
10
15
  exports.AIJobSchema = new mongoose_1.default.Schema({
11
16
  taskId: {
12
17
  type: String,
@@ -16,6 +21,12 @@ exports.AIJobSchema = new mongoose_1.default.Schema({
16
21
  type: 'String',
17
22
  required: true,
18
23
  },
24
+ taskType: {
25
+ type: String,
26
+ enum: exports.AI_JOB_TYPES,
27
+ required: true,
28
+ index: true,
29
+ },
19
30
  status: {
20
31
  type: String,
21
32
  required: true,
@@ -119,5 +130,10 @@ exports.AIJobSchema = new mongoose_1.default.Schema({
119
130
  timestamps: { createdAt: true, updatedAt: true },
120
131
  versionKey: false,
121
132
  });
133
+ exports.AIJobSchema.index({
134
+ userId: 1,
135
+ taskType: 1,
136
+ createdAt: -1,
137
+ });
122
138
  exports.AIJobSchema.index({ taskId: 1, userId: 1, status: 1 }, { unique: true });
123
139
  exports.AIJob = mongoose_1.default.model(_models_1.MODEL_NAMES.AIJobs, exports.AIJobSchema);
@@ -5,6 +5,14 @@ import { TTaskStatus } from '../interfaces/task.interface';
5
5
 
6
6
  export const AI_JOBS_FOLDER = 'AI_jobs';
7
7
 
8
+ export const AI_JOB_TYPES = [
9
+ 'loan-memo-excel',
10
+ 'approval-memo',
11
+ 'email-summary',
12
+ ] as const;
13
+
14
+ export type TAIJobType = (typeof AI_JOB_TYPES)[number];
15
+
8
16
  export interface IAIJobResponseChunk {
9
17
  type: 'text' | 'thinking' | 'tool' | 'status';
10
18
  timestamp: Date;
@@ -51,6 +59,8 @@ export interface IAIJob {
51
59
  taskId: string;
52
60
  userId: string;
53
61
 
62
+ taskType: TAIJobType;
63
+
54
64
  status: TTaskStatus;
55
65
 
56
66
  target: IAIJobTarget;
@@ -109,6 +119,12 @@ export const AIJobSchema = new mongoose.Schema<IAIJob, TAIJobModel>(
109
119
  type: 'String',
110
120
  required: true,
111
121
  },
122
+ taskType: {
123
+ type: String,
124
+ enum: AI_JOB_TYPES,
125
+ required: true,
126
+ index: true,
127
+ },
112
128
  status: {
113
129
  type: String,
114
130
  required: true,
@@ -221,6 +237,12 @@ export const AIJobSchema = new mongoose.Schema<IAIJob, TAIJobModel>(
221
237
  },
222
238
  );
223
239
 
240
+ AIJobSchema.index({
241
+ userId: 1,
242
+ taskType: 1,
243
+ createdAt: -1,
244
+ });
245
+
224
246
  AIJobSchema.index(
225
247
  { taskId: 1, userId: 1, status: 1 },
226
248
  { unique: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.5.127",
3
+ "version": "1.5.129",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -56,9 +56,9 @@ export declare class BrokersService {
56
56
  getAllProductBrokers(): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & Required<{
57
57
  _id: import("mongoose").Types.ObjectId;
58
58
  }>)[]>;
59
- getBorrowerBrokers(borrowerId: string): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & Required<{
59
+ getBorrowerBrokers(borrowerId: string): Promise<BrokerView[] | (import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & Required<{
60
60
  _id: import("mongoose").Types.ObjectId;
61
- }>)[] | BrokerView[]>;
61
+ }>)[]>;
62
62
  getProductBrokers(productId: string): Promise<import("../models/ProductBroker.model").IProductBrokerDocWithBroker[]>;
63
63
  getTotalShares(borrowerId: string, brokers: IProductBrokerView[], replaceNames?: boolean): Promise<ProductTotal>;
64
64
  getTotals(borrowerId: string): Promise<BrokerTotalView[]>;