@mondart/nestjs-common-module 1.1.33 → 1.1.35

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.
@@ -1,8 +1,6 @@
1
1
  import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
2
  import { Response } from 'express';
3
- import { ConfigService } from '@nestjs/config';
4
3
  export declare class GlobalExceptionFilter implements ExceptionFilter {
5
- private readonly configService;
6
- constructor(configService: ConfigService);
4
+ constructor();
7
5
  catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<never> | Response<any, Record<string, any>>;
8
6
  }
@@ -11,26 +11,27 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GlobalExceptionFilter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
- const config_1 = require("@nestjs/config");
15
14
  const rxjs_1 = require("rxjs");
16
15
  const dto_1 = require("../dto");
17
16
  const enums_1 = require("../enums");
18
17
  const helpers_1 = require("../helpers");
19
18
  let GlobalExceptionFilter = class GlobalExceptionFilter {
20
- constructor(configService) {
21
- this.configService = configService;
22
- }
19
+ constructor() { }
23
20
  catch(exception, host) {
24
21
  const context = host.switchToHttp();
25
22
  const logger = new common_1.Logger('GlobalExceptionFilter', { timestamp: true });
26
23
  const type = host?.getType();
27
24
  if (type === 'rpc') {
28
25
  try {
29
- logger.error(exception ?? exception?.message);
30
- return (0, rxjs_1.throwError)(() => exception ?? exception?.message);
26
+ logger.error(typeof exception, JSON.stringify(exception) ??
27
+ exception?.message ??
28
+ 'Unknown exception occurred.');
29
+ return (0, rxjs_1.throwError)(() => JSON.stringify(exception) ??
30
+ exception?.message ??
31
+ 'Unknown exception occurred.');
31
32
  }
32
33
  catch (err) {
33
- return (0, rxjs_1.throwError)(() => JSON.stringify(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR)));
34
+ return (0, rxjs_1.throwError)(() => JSON.stringify(new common_1.InternalServerErrorException(enums_1.SharedMessages.INTERNAL_SERVER_ERROR)));
34
35
  }
35
36
  }
36
37
  if (type === 'http') {
@@ -72,5 +73,5 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
72
73
  exports.GlobalExceptionFilter = GlobalExceptionFilter;
73
74
  exports.GlobalExceptionFilter = GlobalExceptionFilter = __decorate([
74
75
  (0, common_1.Catch)(),
75
- __metadata("design:paramtypes", [config_1.ConfigService])
76
+ __metadata("design:paramtypes", [])
76
77
  ], GlobalExceptionFilter);
@@ -22,6 +22,8 @@ export declare abstract class CoreCrudService<T extends BaseModelEntity, CreateD
22
22
  update(id: number, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CrudServiceOption<T>): Promise<UpdateResult>;
23
23
  softDelete(query: FindOptionsWhere<T>, options?: CrudServiceOption<T>): Promise<UpdateResult>;
24
24
  softDeleteById(id: string | string[] | number | number[], options?: CrudServiceOption<T>): Promise<UpdateResult>;
25
+ restore(query: FindOptionsWhere<T>, options?: CrudServiceOption<T>): Promise<UpdateResult>;
26
+ restoreById(id: string | string[] | number | number[], options?: CrudServiceOption<T>): Promise<UpdateResult>;
25
27
  delete(query: FindOptionsWhere<T>, options?: CrudServiceOption<T>): Promise<DeleteResult>;
26
28
  deleteById(id: string | string[] | number | number[], options?: CrudServiceOption<T>): Promise<DeleteResult>;
27
29
  private relatedPropertyTransformer;
@@ -210,6 +210,23 @@ class CoreCrudService {
210
210
  return await this.repository.softDelete(id);
211
211
  }
212
212
  }
213
+ async restore(query, options) {
214
+ const formatedQuery = this.whereQueryTransformer(query) ?? undefined;
215
+ if (options?.entityManager) {
216
+ return await options?.entityManager.restore(this.repository.target, formatedQuery);
217
+ }
218
+ else {
219
+ return await this.repository.restore(formatedQuery);
220
+ }
221
+ }
222
+ async restoreById(id, options) {
223
+ if (options?.entityManager) {
224
+ return await options?.entityManager.restore(this.repository.target, id);
225
+ }
226
+ else {
227
+ return await this.repository.restore(id);
228
+ }
229
+ }
213
230
  async delete(query, options) {
214
231
  const formatedQuery = this.whereQueryTransformer(query) ?? undefined;
215
232
  if (options?.entityManager) {