@nmxjs/app 1.0.46 → 1.0.48

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.
@@ -0,0 +1,21 @@
1
+ /// <reference types="types" />
2
+ import { ListResponseDto } from '@nmxjs/types';
3
+ import { ICrudListOptions, ICrudUpdateOptions } from './interfaces';
4
+ import type { ExtraRepository } from './ExtraRepository';
5
+ export declare class CrudService<E extends object, D extends object> {
6
+ protected readonly repository: ExtraRepository<E, D>;
7
+ constructor(repository: ExtraRepository<E, D>);
8
+ create: (options: Partial<E>) => Promise<{
9
+ id: string;
10
+ }>;
11
+ update({ id, payload }: ICrudUpdateOptions<E>): Promise<{
12
+ ok: boolean;
13
+ }>;
14
+ getOne: (id: string) => Promise<{
15
+ item: D;
16
+ }>;
17
+ delete: (ids: string[]) => Promise<{
18
+ ok: boolean;
19
+ }>;
20
+ list(options: ICrudListOptions<E>): Promise<ListResponseDto<D>>;
21
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CrudService = void 0;
4
+ const utils_1 = require("@nmxjs/utils");
5
+ const types_1 = require("@nmxjs/types");
6
+ const typeorm_1 = require("typeorm");
7
+ class CrudService {
8
+ constructor(repository) {
9
+ this.repository = repository;
10
+ this.create = (options) => this.repository
11
+ .createQueryBuilder()
12
+ .insert()
13
+ .values(options)
14
+ .returning(['id'])
15
+ .execute()
16
+ .then(res => ({
17
+ id: res.raw[0].id,
18
+ }));
19
+ this.getOne = (id) => this.repository
20
+ .createQueryBuilder()
21
+ .where({ id })
22
+ .getOne()
23
+ .then(res => ({
24
+ item: this.repository.entityToDto(res),
25
+ }));
26
+ this.delete = (ids) => this.repository
27
+ .createQueryBuilder()
28
+ .where({ id: (0, typeorm_1.In)(ids) })
29
+ .execute()
30
+ .then(res => ({
31
+ ok: res.affected > 0,
32
+ }));
33
+ }
34
+ async update({ id, payload }) {
35
+ if (!Object.values(payload).length) {
36
+ return {
37
+ ok: false,
38
+ };
39
+ }
40
+ const ok = await this.repository
41
+ .createQueryBuilder()
42
+ .update()
43
+ .where({
44
+ id,
45
+ })
46
+ .set(payload)
47
+ .execute()
48
+ .then(res => res.affected > 0);
49
+ return {
50
+ ok,
51
+ };
52
+ }
53
+ async list(options) {
54
+ var _a, _b, _c, _d;
55
+ const filters = options.filters || [];
56
+ const relations = options.relations || [];
57
+ const builder = this.repository.createQueryBuilder(this.repository.metadata.tableName);
58
+ const hasPagination = Boolean(((_a = options.pagination) === null || _a === void 0 ? void 0 : _a.limit) && ((_b = options.pagination) === null || _b === void 0 ? void 0 : _b.page));
59
+ if ((_c = options.pagination) === null || _c === void 0 ? void 0 : _c.limit) {
60
+ builder.limit(options.pagination.limit);
61
+ }
62
+ if (hasPagination) {
63
+ builder.offset((options.pagination.page - 1) * options.pagination.limit);
64
+ }
65
+ relations.forEach(v => {
66
+ builder.leftJoinAndSelect(`${this.repository.metadata.tableName}.${v}`, v);
67
+ });
68
+ const where = filters.reduce((res, v) => {
69
+ const field = (0, utils_1.camelToSnakeCase)(v.field);
70
+ if (v.operator === types_1.FilterOperatorEnum.EQ) {
71
+ res[field] = v.values[0];
72
+ }
73
+ else if (v.operator === types_1.FilterOperatorEnum.IN) {
74
+ res[field] = (0, typeorm_1.In)(v.values);
75
+ }
76
+ else if (v.operator === types_1.FilterOperatorEnum.LESS) {
77
+ res[field] = (0, typeorm_1.LessThan)(v.values[0]);
78
+ }
79
+ else if (v.operator === types_1.FilterOperatorEnum.LESS_OR_EQ) {
80
+ res[field] = (0, typeorm_1.LessThanOrEqual)(v.values[0]);
81
+ }
82
+ else if (v.operator === types_1.FilterOperatorEnum.MORE) {
83
+ res[field] = (0, typeorm_1.MoreThan)(v.values[0]);
84
+ }
85
+ else if (v.operator === types_1.FilterOperatorEnum.MORE_OR_EQ) {
86
+ res[field] = (0, typeorm_1.MoreThanOrEqual)(v.values[0]);
87
+ }
88
+ else if (v.operator === types_1.FilterOperatorEnum.LIKE) {
89
+ res[field] = (0, typeorm_1.Like)(v.values[0]);
90
+ }
91
+ if (v.not) {
92
+ res[field] = (0, typeorm_1.Not)(res[v.field]);
93
+ }
94
+ return res;
95
+ }, {});
96
+ (_d = options.sorts) === null || _d === void 0 ? void 0 : _d.forEach((v, i) => {
97
+ if (i === 0) {
98
+ builder.orderBy(v.field, v.type);
99
+ }
100
+ else {
101
+ builder.addOrderBy(v.field, v.type);
102
+ }
103
+ });
104
+ const [totalCount, items] = await Promise.all([
105
+ this.repository.createQueryBuilder().where(where).getCount(),
106
+ builder
107
+ .where(where)
108
+ .select('*')
109
+ .execute()
110
+ .then(res => res.map(v => this.repository.entityToDto(v))),
111
+ ]);
112
+ const totalPages = hasPagination ? Math.ceil(totalCount / options.pagination.limit) : 1;
113
+ const nextPage = hasPagination ? options.pagination.page + 1 : undefined;
114
+ return {
115
+ items,
116
+ cursor: Object.assign({ totalCount,
117
+ totalPages }, (nextPage && nextPage < totalPages ? { nextPage } : {})),
118
+ };
119
+ }
120
+ }
121
+ exports.CrudService = CrudService;
122
+ //# sourceMappingURL=CrudService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudService.js","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"mappings":";;;AAAA,wCAAgD;AAChD,wCAAmE;AACnE,qCAA8F;AAI9F,MAAa,WAAW;IACtB,YAA+B,UAAiC;QAAjC,eAAU,GAAV,UAAU,CAAuB;QAEzD,WAAM,GAAG,CAAC,OAAmB,EAAE,EAAE,CACtC,IAAI,CAAC,UAAU;aACZ,kBAAkB,EAAE;aACpB,MAAM,EAAE;aACR,MAAM,CAAM,OAAO,CAAC;aACpB,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;aACjB,OAAO,EAAE;aACT,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACZ,EAAE,EAAU,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;SAC1B,CAAC,CAAC,CAAC;Q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C3D;SACF,CAAC;IACJ,CAAC;CACF;AA9HD,kCA8HC"}
@@ -1,8 +1,7 @@
1
- /// <reference types="types" />
2
- import { ListResponseDto } from '@nmxjs/types';
3
1
  import { DataSource, Repository, EntityTarget } from 'typeorm';
4
- import { IRepositoryListOptions } from './interfaces';
5
- export declare class ExtraRepository<T extends object> extends Repository<T> {
6
- constructor(entity: EntityTarget<T>, dataSource: DataSource);
7
- list(options: IRepositoryListOptions<T>): Promise<ListResponseDto<T>>;
2
+ import { CrudService } from './CrudService';
3
+ export declare abstract class ExtraRepository<E extends object, D extends object> extends Repository<E> {
4
+ readonly crud: CrudService<E, D>;
5
+ constructor(entity: EntityTarget<E>, dataSource: DataSource);
6
+ abstract entityToDto(entity: E): D;
8
7
  }
@@ -1,72 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExtraRepository = void 0;
4
- const utils_1 = require("@nmxjs/utils");
5
- const types_1 = require("@nmxjs/types");
6
4
  const typeorm_1 = require("typeorm");
5
+ const CrudService_1 = require("./CrudService");
7
6
  class ExtraRepository extends typeorm_1.Repository {
8
7
  constructor(entity, dataSource) {
9
8
  super(entity, dataSource.createEntityManager());
10
- }
11
- async list(options) {
12
- var _a, _b, _c, _d;
13
- const filters = options.filters || [];
14
- const relations = options.relations || [];
15
- const builder = this.createQueryBuilder(this.metadata.tableName);
16
- const hasPagination = Boolean(((_a = options.pagination) === null || _a === void 0 ? void 0 : _a.limit) && ((_b = options.pagination) === null || _b === void 0 ? void 0 : _b.page));
17
- if ((_c = options.pagination) === null || _c === void 0 ? void 0 : _c.limit) {
18
- builder.limit(options.pagination.limit);
19
- }
20
- if (hasPagination) {
21
- builder.offset((options.pagination.page - 1) * options.pagination.limit);
22
- }
23
- relations.forEach(v => {
24
- builder.leftJoinAndSelect(`${this.metadata.tableName}.${v}`, v);
25
- });
26
- const where = filters.reduce((res, v) => {
27
- const field = (0, utils_1.camelToSnakeCase)(v.field);
28
- if (v.operator === types_1.FilterOperatorEnum.EQ) {
29
- res[field] = v.values[0];
30
- }
31
- else if (v.operator === types_1.FilterOperatorEnum.IN) {
32
- res[field] = (0, typeorm_1.In)(v.values);
33
- }
34
- else if (v.operator === types_1.FilterOperatorEnum.LESS) {
35
- res[field] = (0, typeorm_1.LessThan)(v.values[0]);
36
- }
37
- else if (v.operator === types_1.FilterOperatorEnum.LESS_OR_EQ) {
38
- res[field] = (0, typeorm_1.LessThanOrEqual)(v.values[0]);
39
- }
40
- else if (v.operator === types_1.FilterOperatorEnum.MORE) {
41
- res[field] = (0, typeorm_1.MoreThan)(v.values[0]);
42
- }
43
- else if (v.operator === types_1.FilterOperatorEnum.MORE_OR_EQ) {
44
- res[field] = (0, typeorm_1.MoreThanOrEqual)(v.values[0]);
45
- }
46
- else if (v.operator === types_1.FilterOperatorEnum.LIKE) {
47
- res[field] = (0, typeorm_1.Like)(v.values[0]);
48
- }
49
- if (v.not) {
50
- res[field] = (0, typeorm_1.Not)(res[v.field]);
51
- }
52
- return res;
53
- }, {});
54
- (_d = options.sorts) === null || _d === void 0 ? void 0 : _d.forEach((v, i) => {
55
- if (i === 0) {
56
- builder.orderBy(v.field, v.type);
57
- }
58
- else {
59
- builder.addOrderBy(v.field, v.type);
60
- }
61
- });
62
- const [totalCount, items] = await Promise.all([this.createQueryBuilder().where(where).getCount(), builder.where(where).select('*').execute()]);
63
- const totalPages = hasPagination ? Math.ceil(totalCount / options.pagination.limit) : 1;
64
- const nextPage = hasPagination ? options.pagination.page + 1 : undefined;
65
- return {
66
- items,
67
- cursor: Object.assign({ totalCount,
68
- totalPages }, (nextPage && nextPage < totalPages ? { nextPage } : {})),
69
- };
9
+ this.crud = new CrudService_1.CrudService(this);
70
10
  }
71
11
  }
72
12
  exports.ExtraRepository = ExtraRepository;
@@ -1 +1 @@
1
- {"version":3,"file":"ExtraRepository.js","sourceRoot":"","sources":["../src/ExtraRepository.ts"],"names":[],"mappings":";;;AAAA,wCAAgD;AAChD,wCA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,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3D;SACF,CAAC;IACJ,CAAC;CACF;AAtED,0CAsEC"}
1
+ {"version":3,"file":"ExtraRepository.js","sourceRoot":"","sources":["../src/ExtraRepository.ts"],"names":[],"mappings":";;;AAAA,qCAA+D;AAC/D,+CAA4C;AAE5C,MAAsB,eAAoD,SAAQ,oBAAa;IAG7F,YAAY,MAAuB,EAAE,UAAsB;QACzD,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CAGF;AATD,0CASC"}
@@ -1,31 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTypeOrmModule = void 0;
4
- const typeorm_1 = require("typeorm");
5
- const utils_1 = require("@nmxjs/utils");
6
- const types_1 = require("@nmxjs/types");
7
- const typeorm_2 = require("@nestjs/typeorm");
4
+ const typeorm_1 = require("@nestjs/typeorm");
8
5
  const config_1 = require("@nmxjs/config");
9
- const getTypeOrmModule = () => typeorm_2.TypeOrmModule.forRootAsync({
10
- useFactory: (config) => {
11
- const options = Object.assign({ type: config.db.type, host: config.db.host, port: config.db.port, username: config.db.username, password: config.db.password, database: config.db.database, synchronize: true, autoLoadEntities: true }, (config.db.options ? config.db.options : {}));
12
- return (0, utils_1.getEnvironment)() !== types_1.EnvironmentEnum.PRODUCTION && options.database
13
- ? new typeorm_1.DataSource({
14
- type: options.type,
15
- host: options.host,
16
- port: options.port,
17
- username: options.username,
18
- password: options.password,
19
- })
20
- .initialize()
21
- .then(ds => ds
22
- .query(`CREATE DATABASE "${options.database}"`)
23
- .then(() => ds)
24
- .catch(() => ds))
25
- .then(ds => ds.destroy())
26
- .then(() => options)
27
- : options;
28
- },
6
+ const getTypeOrmModule = () => typeorm_1.TypeOrmModule.forRootAsync({
7
+ useFactory: (config) => (Object.assign({ type: config.db.type, host: config.db.host, port: config.db.port, username: config.db.username, password: config.db.password, database: config.db.database, synchronize: true, autoLoadEntities: true }, (config.db.options ? config.db.options : {}))),
29
8
  inject: [config_1.configKey],
30
9
  });
31
10
  exports.getTypeOrmModule = getTypeOrmModule;
@@ -1 +1 @@
1
- {"version":3,"file":"getTypeOrmModule.js","sourceRoot":"","sources":["../src/getTypeOrmModule.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,wCAA8C;AAC9C,wCAA+C;AAC/C,6CAAgD;AAChD,0CAAmD;AAE5C,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,uBAAa,CAAC,YAAY,CAAC;IACzB,UAAU,EAAE,CAAC,MAAe,EAAE,EAAE;QAC9B,MAAM,OAAO,mBACX,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EACpB,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EACpB,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EACpB,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAC5B,WAAW,EAAE,IAAI,EACjB,gBAAgB,EAAE,IAAI,IACnB,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAChD,CAAC;QACF,OAAO,IAAA,sBAAc,GAAE,KAAK,uBAAe,CAAC,UAAU,IAAI,OAAO,CAAC,QAAQ;YACxE,CAAC,CAAC,IAAI,oBAAU,CAAC;gBACb,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,OAAO,CAAC,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AC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAC/C;IACF,MAAM,EAAE,CAAC,kBAAS,CAAC;CACpB,CAAC,CAAC;AAdQ,QAAA,gBAAgB,oBAcxB"}
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './getTypeOrmModule';
5
5
  export * from './getGraphQlModule';
6
6
  export * from './createNestHttpApp';
7
7
  export * from './createTestNestApp';
8
+ export * from './CrudService';
8
9
  export * from './ExtraRepository';
9
10
  export * from './GqlExceptionFilter';
10
11
  export * from './createTestNestHttpApp';
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ __exportStar(require("./getTypeOrmModule"), exports);
21
21
  __exportStar(require("./getGraphQlModule"), exports);
22
22
  __exportStar(require("./createNestHttpApp"), exports);
23
23
  __exportStar(require("./createTestNestApp"), exports);
24
+ __exportStar(require("./CrudService"), exports);
24
25
  __exportStar(require("./ExtraRepository"), exports);
25
26
  __exportStar(require("./GqlExceptionFilter"), exports);
26
27
  __exportStar(require("./createTestNestHttpApp"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,kDAAgC;AAChC,qDAAmC;AACnC,qDAAmC;AACnC,sDAAoC;AACpC,sDAAoC;AACpC,oDAAkC;AAClC,uDAAqC;AACrC,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,kDAAgC;AAChC,qDAAmC;AACnC,qDAAmC;AACnC,sDAAoC;AACpC,sDAAoC;AACpC,gDAA8B;AAC9B,oDAAkC;AAClC,uDAAqC;AACrC,0DAAwC"}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="types" />
2
2
  import { ListRequestDto } from '@nmxjs/types';
3
- export interface IRepositoryListOptions<T extends object> extends ListRequestDto {
3
+ export interface ICrudListOptions<T extends object> extends ListRequestDto {
4
4
  relations?: Array<keyof T>;
5
5
  }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IRepositoryListOptions.js.map
3
+ //# sourceMappingURL=ICrudListOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICrudListOptions.js","sourceRoot":"","sources":["../../src/interfaces/ICrudListOptions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface ICrudUpdateOptions<E> {
2
+ id: string;
3
+ payload: E;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ICrudUpdateOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICrudUpdateOptions.js","sourceRoot":"","sources":["../../src/interfaces/ICrudUpdateOptions.ts"],"names":[],"mappings":""}
@@ -1,4 +1,5 @@
1
+ export * from './ICrudListOptions';
2
+ export * from './ICrudUpdateOptions';
1
3
  export * from './ICreateNestAppOptions';
2
- export * from './IRepositoryListOptions';
3
4
  export * from './IGetGraphQlModuleOptions';
4
5
  export * from './IGetGraphQlModuleUseFactoryResult';
@@ -14,8 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ICrudListOptions"), exports);
18
+ __exportStar(require("./ICrudUpdateOptions"), exports);
17
19
  __exportStar(require("./ICreateNestAppOptions"), exports);
18
- __exportStar(require("./IRepositoryListOptions"), exports);
19
20
  __exportStar(require("./IGetGraphQlModuleOptions"), exports);
20
21
  __exportStar(require("./IGetGraphQlModuleUseFactoryResult"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,2DAAyC;AACzC,6DAA2C;AAC3C,sEAAoD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,uDAAqC;AACrC,0DAAwC;AACxC,6DAA2C;AAC3C,sEAAoD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmxjs/app",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"file":"IRepositoryListOptions.js","sourceRoot":"","sources":["../../src/interfaces/IRepositoryListOptions.ts"],"names":[],"mappings":""}