@steroidsjs/nest 1.0.13 → 1.1.1

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.
Files changed (92) hide show
  1. package/infrastructure/base/DatabaseNamingStrategy.d.ts +4 -0
  2. package/infrastructure/base/DatabaseNamingStrategy.js +12 -0
  3. package/infrastructure/base/DatabaseNamingStrategy.js.map +1 -0
  4. package/infrastructure/commands/dbml/dbml2code.js +5 -3
  5. package/infrastructure/commands/dbml/dbml2code.js.map +1 -1
  6. package/infrastructure/commands/dbml/templates.js +1 -1
  7. package/infrastructure/commands/dbml/templates.js.map +1 -1
  8. package/infrastructure/commands/generate/index.js +32 -10
  9. package/infrastructure/commands/generate/index.js.map +1 -1
  10. package/infrastructure/decorators/SteroidsSchema.d.ts +6 -0
  11. package/infrastructure/decorators/SteroidsSchema.js +11 -0
  12. package/infrastructure/decorators/SteroidsSchema.js.map +1 -0
  13. package/infrastructure/decorators/TableFromModel.js.map +1 -1
  14. package/infrastructure/decorators/fields/BaseField.d.ts +13 -3
  15. package/infrastructure/decorators/fields/BaseField.js +18 -15
  16. package/infrastructure/decorators/fields/BaseField.js.map +1 -1
  17. package/infrastructure/decorators/fields/BooleanField.js +5 -1
  18. package/infrastructure/decorators/fields/BooleanField.js.map +1 -1
  19. package/infrastructure/decorators/fields/CoordinateField.d.ts +1 -2
  20. package/infrastructure/decorators/fields/CoordinateField.js +5 -1
  21. package/infrastructure/decorators/fields/CoordinateField.js.map +1 -1
  22. package/infrastructure/decorators/fields/CreateTimeField.js +5 -1
  23. package/infrastructure/decorators/fields/CreateTimeField.js.map +1 -1
  24. package/infrastructure/decorators/fields/DateField.js +5 -1
  25. package/infrastructure/decorators/fields/DateField.js.map +1 -1
  26. package/infrastructure/decorators/fields/DateTimeField.js +5 -1
  27. package/infrastructure/decorators/fields/DateTimeField.js.map +1 -1
  28. package/infrastructure/decorators/fields/DecimalField.d.ts +1 -2
  29. package/infrastructure/decorators/fields/DecimalField.js +5 -1
  30. package/infrastructure/decorators/fields/DecimalField.js.map +1 -1
  31. package/infrastructure/decorators/fields/EmailField.js +5 -1
  32. package/infrastructure/decorators/fields/EmailField.js.map +1 -1
  33. package/infrastructure/decorators/fields/EnumField.d.ts +2 -3
  34. package/infrastructure/decorators/fields/EnumField.js +5 -1
  35. package/infrastructure/decorators/fields/EnumField.js.map +1 -1
  36. package/infrastructure/decorators/fields/ExtendField.js +18 -5
  37. package/infrastructure/decorators/fields/ExtendField.js.map +1 -1
  38. package/infrastructure/decorators/fields/FileField.d.ts +4 -1
  39. package/infrastructure/decorators/fields/FileField.js +7 -3
  40. package/infrastructure/decorators/fields/FileField.js.map +1 -1
  41. package/infrastructure/decorators/fields/HtmlField.js +5 -1
  42. package/infrastructure/decorators/fields/HtmlField.js.map +1 -1
  43. package/infrastructure/decorators/fields/IntegerField.js +5 -1
  44. package/infrastructure/decorators/fields/IntegerField.js.map +1 -1
  45. package/infrastructure/decorators/fields/PasswordField.js +5 -1
  46. package/infrastructure/decorators/fields/PasswordField.js.map +1 -1
  47. package/infrastructure/decorators/fields/PhoneField.js +5 -1
  48. package/infrastructure/decorators/fields/PhoneField.js.map +1 -1
  49. package/infrastructure/decorators/fields/PrimaryKeyField.js +5 -1
  50. package/infrastructure/decorators/fields/PrimaryKeyField.js.map +1 -1
  51. package/infrastructure/decorators/fields/RelationField.d.ts +1 -1
  52. package/infrastructure/decorators/fields/RelationField.js +6 -1
  53. package/infrastructure/decorators/fields/RelationField.js.map +1 -1
  54. package/infrastructure/decorators/fields/StringField.js +5 -1
  55. package/infrastructure/decorators/fields/StringField.js.map +1 -1
  56. package/infrastructure/decorators/fields/TextField.js +5 -1
  57. package/infrastructure/decorators/fields/TextField.js.map +1 -1
  58. package/infrastructure/decorators/fields/TimeField.js +5 -1
  59. package/infrastructure/decorators/fields/TimeField.js.map +1 -1
  60. package/infrastructure/decorators/fields/UidField.js +5 -1
  61. package/infrastructure/decorators/fields/UidField.js.map +1 -1
  62. package/infrastructure/decorators/fields/UpdateTimeField.js +5 -1
  63. package/infrastructure/decorators/fields/UpdateTimeField.js.map +1 -1
  64. package/infrastructure/decorators/fields/index.d.ts +10 -0
  65. package/infrastructure/decorators/fields/index.js.map +1 -1
  66. package/infrastructure/helpers/MetaHelper.d.ts +12 -2
  67. package/infrastructure/helpers/MetaHelper.js +50 -8
  68. package/infrastructure/helpers/MetaHelper.js.map +1 -1
  69. package/infrastructure/repositories/CrudRepository.d.ts +3 -2
  70. package/infrastructure/repositories/CrudRepository.js +6 -3
  71. package/infrastructure/repositories/CrudRepository.js.map +1 -1
  72. package/package.json +1 -1
  73. package/tsconfig.tsbuildinfo +1 -1
  74. package/usecases/base/SteroidsQuery.d.ts +13 -0
  75. package/usecases/base/SteroidsQuery.js +16 -0
  76. package/usecases/base/SteroidsQuery.js.map +1 -0
  77. package/usecases/helpers/DataMapperHelper.d.ts +1 -1
  78. package/usecases/helpers/DataMapperHelper.js +29 -4
  79. package/usecases/helpers/DataMapperHelper.js.map +1 -1
  80. package/usecases/helpers/SearchHelper.d.ts +5 -3
  81. package/usecases/helpers/SearchHelper.js +29 -8
  82. package/usecases/helpers/SearchHelper.js.map +1 -1
  83. package/usecases/helpers/ValidationHelper.d.ts +1 -1
  84. package/usecases/helpers/ValidationHelper.js +2 -2
  85. package/usecases/helpers/ValidationHelper.js.map +1 -1
  86. package/usecases/interfaces/ICrudRepository.d.ts +2 -1
  87. package/usecases/services/CrudService.d.ts +3 -3
  88. package/usecases/services/CrudService.js +12 -21
  89. package/usecases/services/CrudService.js.map +1 -1
  90. package/infrastructure/decorators/fields/ExtendFields.d.ts +0 -1
  91. package/infrastructure/decorators/fields/ExtendFields.js +0 -15
  92. package/infrastructure/decorators/fields/ExtendFields.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ export interface IQueryRelation {
2
+ name: string;
3
+ alias?: string;
4
+ isId?: boolean;
5
+ }
6
+ export default class SteroidsQuery<TDto> {
7
+ readonly dto?: TDto;
8
+ readonly select?: string[];
9
+ readonly excludeSelect?: string[];
10
+ readonly relations?: IQueryRelation[];
11
+ static create(dto?: any, SchemaClass?: any): SteroidsQuery<any>;
12
+ constructor(data?: SteroidsQuery<TDto>);
13
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const MetaHelper_1 = require("../../infrastructure/helpers/MetaHelper");
4
+ class SteroidsQuery {
5
+ constructor(data = {}) {
6
+ this.dto = data.dto;
7
+ this.select = data.select;
8
+ this.excludeSelect = data.excludeSelect;
9
+ this.relations = data.relations;
10
+ }
11
+ static create(dto = null, SchemaClass = null) {
12
+ return new SteroidsQuery(Object.assign({ dto }, MetaHelper_1.MetaHelper.getSchemaQueryData(SchemaClass)));
13
+ }
14
+ }
15
+ exports.default = SteroidsQuery;
16
+ //# sourceMappingURL=SteroidsQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SteroidsQuery.js","sourceRoot":"","sources":["../../../src/usecases/base/SteroidsQuery.ts"],"names":[],"mappings":";;AAAA,wEAAmE;AAQnE,MAAqB,aAAa;IAa9B,YAAY,OAA4B,EAAE;QACtC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IACpC,CAAC;IAZD,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI;QACxC,OAAO,IAAI,aAAa,iBACpB,GAAG,IACA,uBAAU,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAC/C,CAAC;IACP,CAAC;CAQJ;AAnBD,gCAmBC"}
@@ -1,5 +1,5 @@
1
1
  export declare class DataMapperHelper {
2
2
  static getKeys(object: any): any;
3
- static anyToModel(obj: any, ModelClass: any): any;
3
+ static anyToModel(source: any, ModelClass: any, fieldNames?: any): any;
4
4
  static applyFields(target: Record<string, unknown> | any, source: any, fields?: string[]): void;
5
5
  }
@@ -3,14 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataMapperHelper = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const BaseField_1 = require("../../infrastructure/decorators/fields/BaseField");
6
+ const MetaHelper_1 = require("../../infrastructure/helpers/MetaHelper");
6
7
  class DataMapperHelper {
7
8
  static getKeys(object) {
8
9
  return Reflect.getMetadata(BaseField_1.MODEL_FIELD_NAMES_KEY, object.prototype) || [];
9
10
  }
10
- static anyToModel(obj, ModelClass) {
11
- const result = new ModelClass();
12
- Object.assign(result, obj);
13
- return result;
11
+ static anyToModel(source, ModelClass, fieldNames = null) {
12
+ if (!fieldNames) {
13
+ fieldNames = this.getKeys(ModelClass);
14
+ }
15
+ const model = new ModelClass();
16
+ fieldNames.forEach(fieldName => {
17
+ if ((0, lodash_1.has)(source, fieldName)) {
18
+ const value = source[fieldName];
19
+ if ((0, lodash_1.isObject)(value)) {
20
+ const modelMeta = MetaHelper_1.MetaHelper.getFieldOptions(ModelClass, fieldName);
21
+ if (modelMeta.appType === 'relation') {
22
+ model[fieldName] = this.anyToModel(value, modelMeta.modelClass());
23
+ }
24
+ else {
25
+ }
26
+ }
27
+ else {
28
+ model[fieldName] = value;
29
+ }
30
+ }
31
+ else if ((0, lodash_1.has)(source, fieldName + 'Id')) {
32
+ model[fieldName + 'Id'] = source[fieldName + 'Id'];
33
+ }
34
+ else if ((0, lodash_1.has)(source, fieldName + 'Ids')) {
35
+ model[fieldName + 'Ids'] = source[fieldName + 'Ids'];
36
+ }
37
+ });
38
+ return model;
14
39
  }
15
40
  static applyFields(target, source, fields = null) {
16
41
  if ((0, lodash_1.isObject)(source)) {
@@ -1 +1 @@
1
- {"version":3,"file":"DataMapperHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/DataMapperHelper.ts"],"names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,CAAC,EAAE;gBACzB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;gBAEhC,IAAI,IAAA,iBAAS,EAAC,KAAK,CAAC,EAAE;oBAClB,MAAM,SAAS,GAAG,uBAAU,CAAC,eAAe,CAAC,UAAU,EAAE,SAAS,CAA0B,CAAC;oBAC7F,IAAI,SAAS,CAAC,OAAO,KAAK,UAAU,EAAE;wBAClC,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;qBACrE;yBAAM;qBAEN;iBACJ;qBAAM;oBACH,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;iBAC5B;aACJ;iBAAM,IAAI,IAAA,YAAI,EAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC,EAAE;gBACvC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;aACtD;iBAAM,IAAI,IAAA,YAAI,EAAC,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC,EAAE;gBACxC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;aACxD;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAqC,EAAE,MAAW,EAAE,SAAmB,IAAI;QAC1F,IAAI,IAAA,iBAAS,EAAC,MAAM,CAAC,EAAE;YACnB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SAkBjC;IACL,CAAC;CACJ;AA1DD,4CA0DC"}
@@ -1,7 +1,9 @@
1
1
  import { Repository } from 'typeorm';
2
2
  import { SelectQueryBuilder } from 'typeorm/query-builder/SelectQueryBuilder';
3
- import { SearchInputDto } from '../../usecases/dtos/SearchInputDto';
4
- import { SearchResultDto } from '../../usecases/dtos/SearchResultDto';
3
+ import { SearchInputDto } from '../dtos/SearchInputDto';
4
+ import { SearchResultDto } from '../dtos/SearchResultDto';
5
+ import SteroidsQuery from '../base/SteroidsQuery';
5
6
  export declare class SearchHelper {
6
- static search<TTable>(repository: Repository<any>, dto: SearchInputDto, prepareHandler?: (query: SelectQueryBuilder<TTable>) => void | null): Promise<SearchResultDto<TTable>>;
7
+ static prepareSelect(repository: Repository<any>, dbQuery: SelectQueryBuilder<any>, query: SteroidsQuery<SearchInputDto>): void;
8
+ static search<TTable>(repository: Repository<any>, query: SteroidsQuery<SearchInputDto>, prepareHandler?: (query: SelectQueryBuilder<TTable>) => void | null): Promise<SearchResultDto<TTable>>;
7
9
  }
@@ -1,26 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SearchHelper = void 0;
4
- const SearchResultDto_1 = require("../../usecases/dtos/SearchResultDto");
4
+ const SearchResultDto_1 = require("../dtos/SearchResultDto");
5
5
  class SearchHelper {
6
- static async search(repository, dto, prepareHandler = null) {
6
+ static prepareSelect(repository, dbQuery, query) {
7
+ const prefix = dbQuery.expressionMap.mainAlias.name + '.';
8
+ let select = query.select;
9
+ if (query.excludeSelect) {
10
+ select = repository.metadata.columns
11
+ .map(column => column.propertyName)
12
+ .filter(name => !query.excludeSelect.includes(name));
13
+ }
14
+ if (select) {
15
+ dbQuery.select(select.map(name => prefix + name));
16
+ }
17
+ (query.relations || []).forEach(relation => {
18
+ if (relation.isId) {
19
+ dbQuery.loadRelationIdAndMap(prefix + (relation.alias || relation.name), prefix + relation.name);
20
+ }
21
+ else {
22
+ dbQuery.relation(relation.name);
23
+ }
24
+ });
25
+ }
26
+ static async search(repository, query, prepareHandler = null) {
7
27
  const result = new SearchResultDto_1.SearchResultDto();
8
- dto = Object.assign({ page: 1, pageSize: 50 }, dto);
9
- const query = repository.createQueryBuilder();
28
+ const dto = Object.assign({ page: 1, pageSize: 50 }, query.dto);
29
+ const dbQuery = repository.createQueryBuilder();
30
+ this.prepareSelect(repository, dbQuery, query);
10
31
  const sort = typeof dto.sort === 'string' ? dto.sort.split(',') : (dto.sort || []);
11
32
  if (sort.length === 0) {
12
- query.orderBy(sort.reduce((obj, value) => {
33
+ dbQuery.orderBy(sort.reduce((obj, value) => {
13
34
  obj[value.replace('!', '')] = value.indexOf('!') === 0 ? 'DESC' : 'ASC';
14
35
  return obj;
15
36
  }, {}));
16
37
  }
17
38
  if (prepareHandler) {
18
- prepareHandler.call(null, query);
39
+ prepareHandler.call(null, dbQuery);
19
40
  }
20
- query
41
+ dbQuery
21
42
  .offset((dto.page - 1) * dto.pageSize)
22
43
  .limit(dto.pageSize);
23
- const [items, total] = await query.getManyAndCount();
44
+ const [items, total] = await dbQuery.getManyAndCount();
24
45
  result.items = items;
25
46
  result.total = total;
26
47
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"SearchHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/SearchHelper.ts"],"names":[],"mappings":";;;AAGA,yEAAoE;AAEpE,MAAa,YAAY;IACrB,MAAM,CAAC,KAAK,CAAC,MAAM,CACf,UAA2B,EAC3B,GAAmB,EACnB,iBAAqE,IAAI;QAEzE,MAAM,MAAM,GAAG,IAAI,iCAAe,EAAU,CAAC;QAG7C,GAAG,mBACC,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,EAAE,IACT,GAAG,CACT,CAAC;QAGF,MAAM,KAAK,GAAG,UAAU,CAAC,kBAAkB,EAAE,CAAC;QAG9C,MAAM,IAAI,GAAG,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACnB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAA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IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACnB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBACvC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;gBACxE,OAAO,GAAG,CAAC;YACf,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;SACX;QAGD,IAAI,cAAc,EAAE;YAChB,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SACtC;QAGD,OAAO;aACF,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC;aACrC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAGzB,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;QACvD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QAErB,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAhFD,oCAgFC"}
@@ -1,2 +1,2 @@
1
1
  import { ValidatorOptions } from 'class-validator';
2
- export declare function validateOrReject(model: any, validatorOptions?: ValidatorOptions): Promise<void>;
2
+ export declare function validateOrReject(dto: any, validatorOptions?: ValidatorOptions): Promise<void>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateOrReject = void 0;
4
4
  const class_validator_1 = require("class-validator");
5
5
  const ValidationException_1 = require("../exceptions/ValidationException");
6
- async function validateOrReject(model, validatorOptions) {
7
- const errors = await (0, class_validator_1.validate)(model, validatorOptions);
6
+ async function validateOrReject(dto, validatorOptions) {
7
+ const errors = await (0, class_validator_1.validate)(dto, validatorOptions);
8
8
  if (errors.length) {
9
9
  throw new ValidationException_1.ValidationException(errors);
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/ValidationHelper.ts"],"names":[],"mappings":";;;AAAA,qDAA2D;AAC3D,2EAAsE;AAE/D,KAAK,UAAU,gBAAgB,CAAC,KAAU,EAAE,gBAAmC;IAClF,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAQ,EAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,MAAM,EAAE;QACf,MAAM,IAAI,yCAAmB,CAAC,MAAM,CAAC,CAAC;KACzC;AACL,CAAC;AALD,4CAKC"}
1
+ {"version":3,"file":"ValidationHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/ValidationHelper.ts"],"names":[],"mappings":";;;AAAA,qDAA2D;AAC3D,2EAAsE;AAE/D,KAAK,UAAU,gBAAgB,CAAC,GAAQ,EAAE,gBAAmC;IAChF,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAQ,EAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IACrD,IAAI,MAAM,CAAC,MAAM,EAAE;QACf,MAAM,IAAI,yCAAmB,CAAC,MAAM,CAAC,CAAC;KACzC;AACL,CAAC;AALD,4CAKC"}
@@ -2,9 +2,10 @@ import { Repository } from 'typeorm';
2
2
  import { SearchResultDto } from '../dtos/SearchResultDto';
3
3
  import { SearchInputDto } from '../dtos/SearchInputDto';
4
4
  import { ICondition } from '../../infrastructure/helpers/ConditionHelper';
5
+ import SteroidsQuery from '../base/SteroidsQuery';
5
6
  export interface ICrudRepository<TModel> {
6
7
  dbRepository: Repository<any>;
7
- search: (dto: SearchInputDto) => Promise<SearchResultDto<TModel>>;
8
+ search: (query: SteroidsQuery<SearchInputDto>) => Promise<SearchResultDto<TModel>>;
8
9
  findOne: (condition: ICondition) => Promise<TModel>;
9
10
  create: (model: TModel) => Promise<TModel>;
10
11
  update: (id: number, model: TModel) => Promise<TModel>;
@@ -1,16 +1,16 @@
1
1
  import { ICrudRepository } from '../interfaces/ICrudRepository';
2
2
  import { ISearchInputDto } from '../dtos/SearchInputDto';
3
3
  import { SearchResultDto } from '../dtos/SearchResultDto';
4
+ import SteroidsQuery from '../base/SteroidsQuery';
4
5
  export declare class CrudService<TModel, TSearchDto = ISearchInputDto, TSaveDto = TModel> {
5
6
  protected primaryKey: string;
6
7
  protected repository: ICrudRepository<TModel>;
7
8
  protected modelClass: any;
8
9
  init(repository: ICrudRepository<TModel>, ModelClass: any): void;
9
- createModel(): TModel | any;
10
- search(dto: TSearchDto): Promise<SearchResultDto<TModel>>;
10
+ search(query: SteroidsQuery<TSearchDto>): Promise<SearchResultDto<TModel>>;
11
11
  findById(id: number | string): Promise<TModel>;
12
12
  create(dto: TSaveDto): Promise<TModel>;
13
13
  update(id: number | string, dto: TSaveDto): Promise<TModel>;
14
14
  remove(id: number | string): Promise<void>;
15
- protected dtoToModel(dto: TSaveDto): TModel;
15
+ protected dtoToModel(dto: TSaveDto): Promise<TModel>;
16
16
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CrudService = void 0;
4
4
  const lodash_1 = require("lodash");
5
+ const DataMapperHelper_1 = require("../helpers/DataMapperHelper");
5
6
  const ValidationHelper_1 = require("../helpers/ValidationHelper");
6
- const class_transformer_1 = require("class-transformer");
7
7
  class CrudService {
8
8
  constructor() {
9
9
  this.primaryKey = 'id';
@@ -12,38 +12,29 @@ class CrudService {
12
12
  this.repository = repository;
13
13
  this.modelClass = ModelClass;
14
14
  }
15
- createModel() {
16
- const ModelClass = this.modelClass;
17
- return new ModelClass();
18
- }
19
- async search(dto) {
20
- await (0, ValidationHelper_1.validateOrReject)(dto);
21
- const repositoryResult = await this.repository.search(dto);
22
- return repositoryResult;
15
+ async search(query) {
16
+ await (0, ValidationHelper_1.validateOrReject)(query.dto);
17
+ return await this.repository.search(query);
23
18
  }
24
19
  async findById(id) {
25
- const model = await this.repository.findOne({ [this.primaryKey]: (0, lodash_1.toInteger)(id) });
26
- return model;
20
+ return this.repository.findOne({ [this.primaryKey]: (0, lodash_1.toInteger)(id) });
27
21
  }
28
22
  async create(dto) {
29
23
  await (0, ValidationHelper_1.validateOrReject)(dto);
30
- let model = this.dtoToModel(dto);
31
- await (0, ValidationHelper_1.validateOrReject)(model);
32
- const tmodel = await this.repository.create(model);
33
- return tmodel;
24
+ return this.repository.create(await this.dtoToModel(dto));
34
25
  }
35
26
  async update(id, dto) {
36
27
  await (0, ValidationHelper_1.validateOrReject)(dto);
37
- let model = this.dtoToModel(dto);
38
- await (0, ValidationHelper_1.validateOrReject)(model);
39
- model = await this.repository.update((0, lodash_1.toInteger)(id), model);
40
- return model;
28
+ return this.repository.update((0, lodash_1.toInteger)(id), await this.dtoToModel(dto));
41
29
  }
42
30
  async remove(id) {
43
31
  await this.repository.remove((0, lodash_1.toInteger)(id));
44
32
  }
45
- dtoToModel(dto) {
46
- return (0, class_transformer_1.plainToInstance)(this.modelClass, dto);
33
+ async dtoToModel(dto) {
34
+ if (!this.modelClass) {
35
+ throw new Error('Property modelClass is not set in service: ' + this.constructor.name);
36
+ }
37
+ return DataMapperHelper_1.DataMapperHelper.anyToModel(dto, this.modelClass);
47
38
  }
48
39
  }
49
40
  exports.CrudService = CrudService;
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.js","sourceRoot":"","sources":["../../../src/usecases/services/CrudService.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAK/C,kEAA6D;AAC7D,yDAAkD;AAKlD,MAAa,WAAW;IAAxB;QAQc,eAAU,GAAW,IAAI,CAAC;IAsFxC,CAAC;IAvEG,IAAI,CAAC,UAAmC,EAAE,UAAU;QAChD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC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MAAM,CAAC,EAAmB,EAAE,GAAa;QAC3C,MAAM,IAAA,mCAAgB,EAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAA,kBAAU,EAAC,EAAE,CAAC,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,CAAC;IAMD,KAAK,CAAC,MAAM,CAAC,EAAmB;QAC5B,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAA,kBAAU,EAAC,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;IAOS,KAAK,CAAC,UAAU,CAAC,GAAa;QACpC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,6CAA6C,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC1F;QAED,OAAO,mCAAgB,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;CACJ;AAlFD,kCAkFC"}
@@ -1 +0,0 @@
1
- export declare function ExtendFields(modelClass: any): (object: any) => void;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExtendFields = void 0;
4
- const constants_1 = require("@nestjs/swagger/dist/constants");
5
- function ExtendFields(modelClass) {
6
- return (object) => {
7
- const properties = Reflect.getMetadata(constants_1.DECORATORS.API_MODEL_PROPERTIES_ARRAY, modelClass.prototype);
8
- (properties || []).forEach(propertyName => {
9
- propertyName = propertyName.replace(/^:/, '');
10
- console.log(11, Object.keys(object.prototype));
11
- });
12
- };
13
- }
14
- exports.ExtendFields = ExtendFields;
15
- //# sourceMappingURL=ExtendFields.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExtendFields.js","sourceRoot":"","sources":["../../../../src/infrastructure/decorators/fields/ExtendFields.ts"],"names":[],"mappings":";;;AAAA,8DAA0D;AAG1D,SAAgB,YAAY,CAAC,UAAU;IACnC,OAAO,CAAC,MAAM,EAAE,EAAE;QACd,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,sBAAU,CAAC,0BAA0B,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;QACpG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACtC,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAE9C,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAEnD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AAVD,oCAUC"}