gemcap-be-common 1.4.64 → 1.4.65

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.
@@ -26,6 +26,7 @@ import mongoose from 'mongoose';
26
26
  import Joi from 'joi';
27
27
  export type TDictionary = Record<string, string | object>;
28
28
  export declare const fieldsToUnset: string[];
29
- export declare const removeFields: <T>(document: mongoose.Document, fieldsToUnset: string[]) => T;
29
+ export declare function removeFields<T extends object>(document: T, fieldsToUnset: string[]): T;
30
+ export declare function removeFields<T extends mongoose.Document>(document: T, fieldsToUnset: string[]): T;
30
31
  export declare const replaceErrors: (error: Joi.ValidationError, dictionary: TDictionary) => string;
31
32
  export declare const getUUID: () => string;
@@ -32,14 +32,13 @@ const deepCloneAndConvertMaps = (obj) => {
32
32
  }
33
33
  return obj;
34
34
  };
35
- const removeFields = (document, fieldsToUnset) => {
36
- return document.toObject({
37
- transform: (_doc, ret) => {
38
- fieldsToUnset.forEach((field) => delete ret[field]);
39
- return deepCloneAndConvertMaps(ret);
40
- },
41
- });
42
- };
35
+ function removeFields(document, fieldsToUnset) {
36
+ const plainObject = typeof document.toObject === 'function'
37
+ ? document.toObject()
38
+ : deepCloneAndConvertMaps(document);
39
+ fieldsToUnset.forEach((field) => delete plainObject[field]);
40
+ return deepCloneAndConvertMaps(plainObject);
41
+ }
43
42
  exports.removeFields = removeFields;
44
43
  const replaceErrors = (error, dictionary) => {
45
44
  const getValue = (d, keys) => {
@@ -32,14 +32,18 @@ const deepCloneAndConvertMaps = <T>(obj: T): T => {
32
32
  return obj;
33
33
  };
34
34
 
35
- export const removeFields = <T>(document: mongoose.Document, fieldsToUnset: string[]): T => {
36
- return document.toObject({
37
- transform: (_doc, ret) => {
38
- fieldsToUnset.forEach((field) => delete ret[field]);
39
- return deepCloneAndConvertMaps(ret) as Omit<T, keyof T>;
40
- },
41
- });
42
- };
35
+ export function removeFields<T extends object>(document: T, fieldsToUnset: string[]): T;
36
+ export function removeFields<T extends mongoose.Document>(document: T, fieldsToUnset: string[]): T;
37
+ export function removeFields<T>(document: any, fieldsToUnset: string[]): T {
38
+ const plainObject =
39
+ typeof document.toObject === 'function'
40
+ ? document.toObject()
41
+ : deepCloneAndConvertMaps(document);
42
+
43
+ fieldsToUnset.forEach((field) => delete plainObject[field]);
44
+
45
+ return deepCloneAndConvertMaps(plainObject) as T;
46
+ }
43
47
 
44
48
  export const replaceErrors = (error: Joi.ValidationError, dictionary: TDictionary) => {
45
49
  const getValue = (d: TDictionary, keys: string[]): string => {
@@ -24,15 +24,26 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Model } from 'mongoose';
26
26
  export interface ICompany {
27
- _id?: mongoose.Types.ObjectId;
28
27
  name: string;
28
+ isDeleted?: boolean;
29
29
  }
30
- export type ICompanyStringified = {
31
- [K in keyof ICompany]: K extends '_id' | 'productId' ? string : ICompany[K];
32
- };
33
- type CompanyModel = Model<ICompany>;
34
- export declare const CompanySchema: mongoose.Schema<ICompany, CompanyModel, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, ICompany, mongoose.Document<unknown, {}, mongoose.FlatRecord<ICompany>> & mongoose.FlatRecord<ICompany> & Required<{
30
+ export interface ICompanyDoc extends ICompany, Document {
35
31
  _id: mongoose.Types.ObjectId;
36
- }>>;
32
+ createdAt: Date;
33
+ updatedAt: Date;
34
+ }
35
+ export interface ICompanyLean extends ICompany {
36
+ _id: mongoose.Types.ObjectId;
37
+ createdAt: Date;
38
+ updatedAt: Date;
39
+ }
40
+ export interface ICompanyPlain extends ICompany {
41
+ _id: string;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ }
45
+ export type CompanyModel = Model<ICompany>;
46
+ export declare const CompanySchema: mongoose.Schema<ICompany, CompanyModel, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, ICompany, mongoose.Document<unknown, {}, mongoose.FlatRecord<ICompany>> & mongoose.FlatRecord<ICompany> & {
47
+ _id: mongoose.Types.ObjectId;
48
+ }>;
37
49
  export declare const Company: CompanyModel;
38
- export {};
@@ -12,6 +12,9 @@ exports.CompanySchema = new mongoose_1.default.Schema({
12
12
  required: true,
13
13
  trim: true,
14
14
  },
15
+ isDeleted: {
16
+ type: Boolean,
17
+ },
15
18
  }, {
16
19
  timestamps: { createdAt: true, updatedAt: false },
17
20
  });
@@ -3,15 +3,29 @@ import mongoose, { Model } from 'mongoose';
3
3
  import { MODEL_NAMES } from './_models';
4
4
 
5
5
  export interface ICompany {
6
- _id?: mongoose.Types.ObjectId;
7
6
  name: string;
7
+ isDeleted?: boolean;
8
8
  }
9
9
 
10
- export type ICompanyStringified = {
11
- [K in keyof ICompany]: K extends '_id' | 'productId' ? string : ICompany[K];
12
- };
10
+ export interface ICompanyDoc extends ICompany, Document {
11
+ _id: mongoose.Types.ObjectId;
12
+ createdAt: Date;
13
+ updatedAt: Date;
14
+ }
15
+
16
+ export interface ICompanyLean extends ICompany {
17
+ _id: mongoose.Types.ObjectId;
18
+ createdAt: Date;
19
+ updatedAt: Date;
20
+ }
13
21
 
14
- type CompanyModel = Model<ICompany>;
22
+ export interface ICompanyPlain extends ICompany {
23
+ _id: string;
24
+ createdAt: Date;
25
+ updatedAt: Date;
26
+ }
27
+
28
+ export type CompanyModel = Model<ICompany>;
15
29
 
16
30
  export const CompanySchema = new mongoose.Schema<ICompany, CompanyModel>(
17
31
  {
@@ -20,6 +34,9 @@ export const CompanySchema = new mongoose.Schema<ICompany, CompanyModel>(
20
34
  required: true,
21
35
  trim: true,
22
36
  },
37
+ isDeleted: {
38
+ type: Boolean,
39
+ },
23
40
  },
24
41
  {
25
42
  timestamps: { createdAt: true, updatedAt: false },
@@ -31,10 +31,10 @@ export declare const allSchemas: {
31
31
  createdAt: NativeDate;
32
32
  updatedAt: NativeDate;
33
33
  } & {
34
- bbcSheetId: import("mongoose").Types.ObjectId;
35
34
  order: number;
36
- apDate: Date;
37
35
  amount: number;
36
+ bbcSheetId: import("mongoose").Types.ObjectId;
37
+ apDate: Date;
38
38
  __v?: number;
39
39
  poNumber?: string;
40
40
  customerName?: string;
@@ -45,10 +45,10 @@ export declare const allSchemas: {
45
45
  createdAt: NativeDate;
46
46
  updatedAt: NativeDate;
47
47
  } & {
48
- bbcSheetId: import("mongoose").Types.ObjectId;
49
48
  order: number;
50
- apDate: Date;
51
49
  amount: number;
50
+ bbcSheetId: import("mongoose").Types.ObjectId;
51
+ apDate: Date;
52
52
  __v?: number;
53
53
  poNumber?: string;
54
54
  customerName?: string;
@@ -59,10 +59,10 @@ export declare const allSchemas: {
59
59
  createdAt: NativeDate;
60
60
  updatedAt: NativeDate;
61
61
  } & {
62
- bbcSheetId: import("mongoose").Types.ObjectId;
63
62
  order: number;
64
- apDate: Date;
65
63
  amount: number;
64
+ bbcSheetId: import("mongoose").Types.ObjectId;
65
+ apDate: Date;
66
66
  __v?: number;
67
67
  poNumber?: string;
68
68
  customerName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.64",
3
+ "version": "1.4.65",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,4 @@
1
- import { ICompany } from '../models/Company.model';
1
+ import { ICompanyLean } from '../models/Company.model';
2
2
  export declare class CompaniesService {
3
- getCompanies(): Promise<ICompany[]>;
4
- createCompanies(): Promise<void>;
3
+ getCompanies(): Promise<ICompanyLean[]>;
5
4
  }
@@ -5,17 +5,12 @@ const Company_model_1 = require("../models/Company.model");
5
5
  const main_helper_1 = require("../helpers/main.helper");
6
6
  class CompaniesService {
7
7
  async getCompanies() {
8
- const companies = await Company_model_1.Company.find().sort({ name: 1 });
8
+ const companies = await Company_model_1.Company
9
+ .find({ iisDeleted: { $ne: true } })
10
+ .sort({ name: 1 })
11
+ .lean()
12
+ .exec();
9
13
  return companies.map((i) => (0, main_helper_1.removeFields)(i, main_helper_1.fieldsToUnset));
10
14
  }
11
- async createCompanies() {
12
- const companies = [
13
- { name: 'AssetCo' },
14
- { name: 'OpCo' },
15
- ];
16
- await Promise.all(companies.map(async (company) => {
17
- await Company_model_1.Company.findOneAndUpdate({ name: company.name }, { $setOnInsert: { name: company.name } }, { upsert: true, new: true });
18
- }));
19
- }
20
15
  }
21
16
  exports.CompaniesService = CompaniesService;
@@ -1,23 +1,13 @@
1
- import { Company, ICompany } from '../models/Company.model';
1
+ import { Company, ICompanyLean } from '../models/Company.model';
2
2
  import { fieldsToUnset, removeFields } from '../helpers/main.helper';
3
3
 
4
4
  export class CompaniesService {
5
5
  async getCompanies() {
6
- const companies = await Company.find().sort({ name: 1 });
7
- return companies.map((i) => removeFields<ICompany>(i, fieldsToUnset));
8
- }
9
-
10
- async createCompanies() {
11
- const companies: ICompany[] = [
12
- { name: 'AssetCo' },
13
- { name: 'OpCo' },
14
- ];
15
- await Promise.all(companies.map(async (company) => {
16
- await Company.findOneAndUpdate(
17
- { name: company.name },
18
- { $setOnInsert: { name: company.name } },
19
- { upsert: true, new: true },
20
- );
21
- }));
6
+ const companies = await Company
7
+ .find({ iisDeleted: { $ne: true } })
8
+ .sort({ name: 1 })
9
+ .lean<ICompanyLean[]>()
10
+ .exec();
11
+ return companies.map((i) => removeFields(i, fieldsToUnset));
22
12
  }
23
13
  }
@@ -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<{