gemcap-be-common 1.4.65 → 1.4.67

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,7 +26,6 @@ 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 function removeFields<T extends object>(document: T, fieldsToUnset: string[]): T;
30
- export declare function removeFields<T extends mongoose.Document>(document: T, fieldsToUnset: string[]): T;
29
+ export declare const removeFields: <T>(document: mongoose.Document, fieldsToUnset: string[]) => T;
31
30
  export declare const replaceErrors: (error: Joi.ValidationError, dictionary: TDictionary) => string;
32
31
  export declare const getUUID: () => string;
@@ -32,13 +32,14 @@ const deepCloneAndConvertMaps = (obj) => {
32
32
  }
33
33
  return obj;
34
34
  };
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
- }
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
+ };
42
43
  exports.removeFields = removeFields;
43
44
  const replaceErrors = (error, dictionary) => {
44
45
  const getValue = (d, keys) => {
@@ -32,18 +32,14 @@ const deepCloneAndConvertMaps = <T>(obj: T): T => {
32
32
  return obj;
33
33
  };
34
34
 
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
- }
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
+ };
47
43
 
48
44
  export const replaceErrors = (error: Joi.ValidationError, dictionary: TDictionary) => {
49
45
  const getValue = (d: TDictionary, keys: string[]): string => {
@@ -25,6 +25,7 @@
25
25
  import mongoose, { Model } from 'mongoose';
26
26
  export interface ICompany {
27
27
  name: string;
28
+ order: number;
28
29
  isDeleted?: boolean;
29
30
  }
30
31
  export interface ICompanyDoc extends ICompany, Document {
@@ -12,6 +12,10 @@ exports.CompanySchema = new mongoose_1.default.Schema({
12
12
  required: true,
13
13
  trim: true,
14
14
  },
15
+ order: {
16
+ type: Number,
17
+ required: true,
18
+ },
15
19
  isDeleted: {
16
20
  type: Boolean,
17
21
  },
@@ -4,6 +4,7 @@ import { MODEL_NAMES } from './_models';
4
4
 
5
5
  export interface ICompany {
6
6
  name: string;
7
+ order: number;
7
8
  isDeleted?: boolean;
8
9
  }
9
10
 
@@ -34,6 +35,10 @@ export const CompanySchema = new mongoose.Schema<ICompany, CompanyModel>(
34
35
  required: true,
35
36
  trim: true,
36
37
  },
38
+ order: {
39
+ type: Number,
40
+ required: true,
41
+ },
37
42
  isDeleted: {
38
43
  type: Boolean,
39
44
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.65",
3
+ "version": "1.4.67",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,15 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CompaniesService = void 0;
4
4
  const Company_model_1 = require("../models/Company.model");
5
- const main_helper_1 = require("../helpers/main.helper");
6
5
  class CompaniesService {
7
6
  async getCompanies() {
8
- const companies = await Company_model_1.Company
9
- .find({ iisDeleted: { $ne: true } })
10
- .sort({ name: 1 })
7
+ return Company_model_1.Company
8
+ .find({ isDeleted: { $ne: true } })
9
+ .sort({ order: 1, name: 1 })
11
10
  .lean()
12
11
  .exec();
13
- return companies.map((i) => (0, main_helper_1.removeFields)(i, main_helper_1.fieldsToUnset));
14
12
  }
15
13
  }
16
14
  exports.CompaniesService = CompaniesService;
@@ -3,11 +3,10 @@ import { fieldsToUnset, removeFields } from '../helpers/main.helper';
3
3
 
4
4
  export class CompaniesService {
5
5
  async getCompanies() {
6
- const companies = await Company
7
- .find({ iisDeleted: { $ne: true } })
8
- .sort({ name: 1 })
6
+ return Company
7
+ .find({ isDeleted: { $ne: true } })
8
+ .sort({ order: 1, name: 1 })
9
9
  .lean<ICompanyLean[]>()
10
10
  .exec();
11
- return companies.map((i) => removeFields(i, fieldsToUnset));
12
11
  }
13
12
  }