@saihu/common 1.1.1 → 1.1.3

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,14 @@
1
1
  export interface ActiveMenuResDto {
2
- id: string;
2
+ id: number;
3
+ name: string;
4
+ items: FoodItemDto[];
5
+ }
6
+ export interface FoodItemDto {
7
+ id: number;
3
8
  name: string;
4
9
  price: string;
5
10
  unit_name: string;
6
11
  big_pic_url: string;
12
+ category_id: number;
7
13
  }
8
14
  //# sourceMappingURL=active-menu-res.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"active-menu-res.dto.d.ts","sourceRoot":"","sources":["../../../src/dto/basic-data-service/active-menu-res.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB"}
1
+ {"version":3,"file":"active-menu-res.dto.d.ts","sourceRoot":"","sources":["../../../src/dto/basic-data-service/active-menu-res.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,7 @@
1
+ import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
2
+ import { BaseError } from '../dto/base-res.dto';
3
+ export declare class BaseErrorFilter implements ExceptionFilter {
4
+ catch(exception: BaseError, host: ArgumentsHost): void;
5
+ private mapErrorCodeToHttpStatus;
6
+ }
7
+ //# sourceMappingURL=base-error.filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-error.filter.d.ts","sourceRoot":"","sources":["../../src/filters/base-error.filter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EAEf,aAAa,EAEd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,qBACa,eAAgB,YAAW,eAAe;IACrD,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa;IAe/C,OAAO,CAAC,wBAAwB;CAiBjC"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.BaseErrorFilter = void 0;
42
+ // src/filters/base-error.filter.ts in @saihu/common
43
+ const common_1 = require("@nestjs/common");
44
+ const base_res_dto_1 = require("../dto/base-res.dto");
45
+ const base_res_dto_2 = require("../dto/base-res.dto");
46
+ let BaseErrorFilter = (() => {
47
+ let _classDecorators = [(0, common_1.Catch)(base_res_dto_1.BaseError)];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ var BaseErrorFilter = _classThis = class {
52
+ catch(exception, host) {
53
+ const ctx = host.switchToHttp();
54
+ const response = ctx.getResponse();
55
+ // Map your BaseError code to an appropriate HTTP status code
56
+ const statusCode = this.mapErrorCodeToHttpStatus(exception.code);
57
+ // Return the response in your standard format
58
+ response.status(statusCode).json({
59
+ code: exception.code,
60
+ msg: exception.message,
61
+ data: exception.data,
62
+ });
63
+ }
64
+ mapErrorCodeToHttpStatus(errorCode) {
65
+ // Map your custom error codes to HTTP status codes
66
+ switch (errorCode) {
67
+ case base_res_dto_2.BaseResponseDto.CODE_NOT_FOUND:
68
+ return common_1.HttpStatus.NOT_FOUND;
69
+ case base_res_dto_2.BaseResponseDto.CODE_UNAUTHORIZED:
70
+ return common_1.HttpStatus.UNAUTHORIZED;
71
+ case base_res_dto_2.BaseResponseDto.CODE_FORBIDDEN:
72
+ return common_1.HttpStatus.FORBIDDEN;
73
+ case base_res_dto_2.BaseResponseDto.CODE_BAD_REQUEST:
74
+ return common_1.HttpStatus.BAD_REQUEST;
75
+ case base_res_dto_2.BaseResponseDto.CODE_SERVER_ERROR:
76
+ return common_1.HttpStatus.INTERNAL_SERVER_ERROR;
77
+ default:
78
+ return common_1.HttpStatus.INTERNAL_SERVER_ERROR;
79
+ }
80
+ }
81
+ };
82
+ __setFunctionName(_classThis, "BaseErrorFilter");
83
+ (() => {
84
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
85
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
86
+ BaseErrorFilter = _classThis = _classDescriptor.value;
87
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
88
+ __runInitializers(_classThis, _classExtraInitializers);
89
+ })();
90
+ return BaseErrorFilter = _classThis;
91
+ })();
92
+ exports.BaseErrorFilter = BaseErrorFilter;
@@ -0,0 +1,2 @@
1
+ export * from './base-error.filter';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base-error.filter"), exports);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './dto';
2
2
  export * from './interceptors';
3
+ export * from './filters';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./dto"), exports);
18
18
  __exportStar(require("./interceptors"), exports);
19
+ __exportStar(require("./filters"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,11 @@
23
23
  "rxjs": "^7.0.0"
24
24
  },
25
25
  "devDependencies": {
26
+ "@types/express": "^5.0.1",
26
27
  "@types/node": "^22.14.1",
27
28
  "typescript": "^5.8.3"
29
+ },
30
+ "dependencies": {
31
+ "express": "^5.1.0"
28
32
  }
29
33
  }