gemcap-be-common 1.5.127 → 1.5.128

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;
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.128",
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[]>;