hh-contracts 0.0.24 → 0.0.25

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,123 @@
1
+ "use strict";
2
+ // import { HttpStatus } from '@nestjs/common';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.APP_ERROR = void 0;
5
+ exports.APP_ERROR = {
6
+ common: {
7
+ validation: {
8
+ statusCode: 400, // HttpStatus.BAD_REQUEST,
9
+ code: 'COMMON-01',
10
+ message: 'Validation error.',
11
+ },
12
+ unauthorized: {
13
+ statusCode: 401, // HttpStatus.UNAUTHORIZED,
14
+ code: 'COMMON-02',
15
+ message: 'Unauthorized.',
16
+ },
17
+ forbidden: {
18
+ statusCode: 403, // HttpStatus.FORBIDDEN,
19
+ code: 'COMMON-03',
20
+ message: 'You are not allowed to perform this action.',
21
+ },
22
+ requestTimeout: {
23
+ statusCode: 408, // HttpStatus.REQUEST_TIMEOUT,
24
+ code: 'COMMON-04',
25
+ message: 'Request timeout.',
26
+ },
27
+ unprocessableEntity: {
28
+ statusCode: 422, // HttpStatus.UNPROCESSABLE_ENTITY,
29
+ code: 'COMMON-05',
30
+ message: 'Unprocessable entity.',
31
+ },
32
+ internalServer: {
33
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
34
+ code: 'COMMON-06',
35
+ message: 'Internal server error.',
36
+ },
37
+ // Перенести в отдельную сущность
38
+ // hotelClientNotConnected: {
39
+ // statusCode: 503, // HttpStatus.SERVICE_UNAVAILABLE,
40
+ // code: 'COMMON-05',
41
+ // message: 'Hotel client is not connected.',
42
+ // },
43
+ // hotelClientInternalError: {
44
+ // statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
45
+ // code: 'COMMON-06',
46
+ // message: 'Hotel client internal error.',
47
+ // },
48
+ },
49
+ auth: {
50
+ wrongCredentials: {
51
+ statusCode: 401, // HttpStatus.UNAUTHORIZED,
52
+ code: 'AUTH-01',
53
+ message: 'Login or password is wrong.',
54
+ },
55
+ },
56
+ user: {
57
+ notFound: {
58
+ statusCode: 404, // HttpStatus.NOT_FOUND,
59
+ code: 'USER-01',
60
+ message: 'User not found.',
61
+ },
62
+ alreadyExists: {
63
+ statusCode: 409, // HttpStatus.CONFLICT,
64
+ code: 'USER-02',
65
+ message: 'User already exists.',
66
+ },
67
+ },
68
+ role: {
69
+ notFound: {
70
+ statusCode: 404, // HttpStatus.NOT_FOUND,
71
+ code: 'ROLE-01',
72
+ message: 'Role not found.',
73
+ },
74
+ alreadyExists: {
75
+ statusCode: 409, // HttpStatus.CONFLICT,
76
+ code: 'ROLE-02',
77
+ message: 'Role already exists.',
78
+ },
79
+ },
80
+ permission: {
81
+ notFound: {
82
+ statusCode: 404, // HttpStatus.NOT_FOUND,
83
+ code: 'PERMISSION-01',
84
+ message: 'Permission not found.',
85
+ },
86
+ alreadyExists: {
87
+ statusCode: 409, // HttpStatus.CONFLICT,
88
+ code: 'PERMISSION-02',
89
+ message: 'Permission already exists.',
90
+ },
91
+ },
92
+ hotel: {
93
+ notFound: {
94
+ statusCode: 404, // HttpStatus.NOT_FOUND,
95
+ code: 'HOTEL-01',
96
+ message: 'Hotel not found.',
97
+ },
98
+ alreadyExists: {
99
+ statusCode: 409, // HttpStatus.CONFLICT,
100
+ code: 'HOTEL-02',
101
+ message: 'Hotel already exists.',
102
+ },
103
+ },
104
+ roomCategory: {
105
+ notFound: {
106
+ statusCode: 404, // HttpStatus.NOT_FOUND,
107
+ code: 'ROOM-CATEGORY-01',
108
+ message: 'Room category not found.',
109
+ },
110
+ alreadyExists: {
111
+ statusCode: 409, // HttpStatus.CONFLICT,
112
+ code: 'ROOM-CATEGORY-02',
113
+ message: 'Room category already exists.',
114
+ },
115
+ },
116
+ room: {
117
+ not: {
118
+ statusCode: 404, // HttpStatus.NOT_FOUND,
119
+ code: 'ROOM-01',
120
+ message: 'Room not found.',
121
+ },
122
+ },
123
+ };
@@ -21,3 +21,4 @@ __exportStar(require("./icon-key.constant"), exports);
21
21
  __exportStar(require("./navigation-item-type.constant"), exports);
22
22
  __exportStar(require("./order-direction.constant"), exports);
23
23
  __exportStar(require("./route-component-key.constants"), exports);
24
+ __exportStar(require("./app-error.constant"), exports);
@@ -5,6 +5,7 @@ const zod_1 = require("zod");
5
5
  const common_1 = require("../../common");
6
6
  const permissions_api_1 = require("../permissions.api");
7
7
  const permission_model_1 = require("../permission.model");
8
+ const permission_response_schema_1 = require("../permission.response.schema");
8
9
  const CreatePermissionContractRequestSchema = permission_model_1.PermissionSchema.omit({
9
10
  id: true,
10
11
  createdAt: true,
@@ -32,9 +33,5 @@ var CreatePermissionContract;
32
33
  CreatePermissionContract.endpoint = permissions_api_1.PERMISSIONS_CONTROLLER.endpoints.create;
33
34
  CreatePermissionContract.httpMethod = common_1.HTTP_METHOD.post;
34
35
  CreatePermissionContract.RequestSchema = CreatePermissionContractRequestSchema;
35
- CreatePermissionContract.ResponseSchema = permission_model_1.PermissionSchema.transform(data => {
36
- return {
37
- privet: 'Hello',
38
- };
39
- });
36
+ CreatePermissionContract.ResponseSchema = permission_response_schema_1.PermissionResponseSchema;
40
37
  })(CreatePermissionContract || (exports.CreatePermissionContract = CreatePermissionContract = {}));
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PermissionResponseSchema = void 0;
4
+ const permission_model_1 = require("./permission.model");
5
+ exports.PermissionResponseSchema = permission_model_1.PermissionSchema.transform(({ conditions, ...rest }) => ({
6
+ ...rest,
7
+ conditions: conditions ? JSON.parse(conditions) : undefined,
8
+ }));
@@ -0,0 +1,145 @@
1
+ // import { HttpStatus } from '@nestjs/common';
2
+
3
+ export const APP_ERROR = {
4
+ common: {
5
+ validation: {
6
+ statusCode: 400, // HttpStatus.BAD_REQUEST,
7
+ code: 'COMMON-01',
8
+ message: 'Validation error.',
9
+ },
10
+ unauthorized: {
11
+ statusCode: 401, // HttpStatus.UNAUTHORIZED,
12
+ code: 'COMMON-02',
13
+ message: 'Unauthorized.',
14
+ },
15
+ forbidden: {
16
+ statusCode: 403, // HttpStatus.FORBIDDEN,
17
+ code: 'COMMON-03',
18
+ message: 'You are not allowed to perform this action.',
19
+ },
20
+ requestTimeout: {
21
+ statusCode: 408, // HttpStatus.REQUEST_TIMEOUT,
22
+ code: 'COMMON-04',
23
+ message: 'Request timeout.',
24
+ },
25
+ unprocessableEntity: {
26
+ statusCode: 422, // HttpStatus.UNPROCESSABLE_ENTITY,
27
+ code: 'COMMON-05',
28
+ message: 'Unprocessable entity.',
29
+ },
30
+ internalServer: {
31
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
32
+ code: 'COMMON-06',
33
+ message: 'Internal server error.',
34
+ },
35
+ // Перенести в отдельную сущность
36
+ // hotelClientNotConnected: {
37
+ // statusCode: 503, // HttpStatus.SERVICE_UNAVAILABLE,
38
+ // code: 'COMMON-05',
39
+ // message: 'Hotel client is not connected.',
40
+ // },
41
+ // hotelClientInternalError: {
42
+ // statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
43
+ // code: 'COMMON-06',
44
+ // message: 'Hotel client internal error.',
45
+ // },
46
+ },
47
+ auth: {
48
+ wrongCredentials: {
49
+ statusCode: 401, // HttpStatus.UNAUTHORIZED,
50
+ code: 'AUTH-01',
51
+ message: 'Login or password is wrong.',
52
+ },
53
+ },
54
+ user: {
55
+ notFound: {
56
+ statusCode: 404, // HttpStatus.NOT_FOUND,
57
+ code: 'USER-01',
58
+ message: 'User not found.',
59
+ },
60
+ alreadyExists: {
61
+ statusCode: 409, // HttpStatus.CONFLICT,
62
+ code: 'USER-02',
63
+ message: 'User already exists.',
64
+ },
65
+ },
66
+ role: {
67
+ notFound: {
68
+ statusCode: 404, // HttpStatus.NOT_FOUND,
69
+ code: 'ROLE-01',
70
+ message: 'Role not found.',
71
+ },
72
+ alreadyExists: {
73
+ statusCode: 409, // HttpStatus.CONFLICT,
74
+ code: 'ROLE-02',
75
+ message: 'Role already exists.',
76
+ },
77
+ },
78
+ permission: {
79
+ notFound: {
80
+ statusCode: 404, // HttpStatus.NOT_FOUND,
81
+ code: 'PERMISSION-01',
82
+ message: 'Permission not found.',
83
+ },
84
+ alreadyExists: {
85
+ statusCode: 409, // HttpStatus.CONFLICT,
86
+ code: 'PERMISSION-02',
87
+ message: 'Permission already exists.',
88
+ },
89
+ },
90
+ hotel: {
91
+ notFound: {
92
+ statusCode: 404, // HttpStatus.NOT_FOUND,
93
+ code: 'HOTEL-01',
94
+ message: 'Hotel not found.',
95
+ },
96
+ alreadyExists: {
97
+ statusCode: 409, // HttpStatus.CONFLICT,
98
+ code: 'HOTEL-02',
99
+ message: 'Hotel already exists.',
100
+ },
101
+ },
102
+ roomCategory: {
103
+ notFound: {
104
+ statusCode: 404, // HttpStatus.NOT_FOUND,
105
+ code: 'ROOM-CATEGORY-01',
106
+ message: 'Room category not found.',
107
+ },
108
+ alreadyExists: {
109
+ statusCode: 409, // HttpStatus.CONFLICT,
110
+ code: 'ROOM-CATEGORY-02',
111
+ message: 'Room category already exists.',
112
+ },
113
+ },
114
+ room: {
115
+ not: {
116
+ statusCode: 404, // HttpStatus.NOT_FOUND,
117
+ code: 'ROOM-01',
118
+ message: 'Room not found.',
119
+ },
120
+ },
121
+ } as const;
122
+
123
+ interface IError {
124
+ statusCode: number;
125
+ code: string;
126
+ message: string;
127
+ }
128
+
129
+ type TMappedErrors<T extends Record<string, unknown>> = {
130
+ [k in keyof T]: T[k] extends Record<string, unknown>
131
+ ? T[k] extends IError
132
+ ? T[k]
133
+ : TMappedErrors<T[k]>
134
+ : never;
135
+ }[keyof T];
136
+ export type TAppError = TMappedErrors<typeof APP_ERROR>;
137
+ export type TAppErrorCodes = TAppError['code'];
138
+ export type TAppErrorMessages = TAppError['message'];
139
+
140
+ interface IErrorDetails {
141
+ type?: string;
142
+ message: string;
143
+ }
144
+ export type TAppErrorDetails = Record<string, IErrorDetails>;
145
+ export type TAppErrorWithDetails = TAppError & { details?: TAppErrorDetails };
@@ -5,3 +5,4 @@ export * from './icon-key.constant';
5
5
  export * from './navigation-item-type.constant';
6
6
  export * from './order-direction.constant';
7
7
  export * from './route-component-key.constants';
8
+ export * from './app-error.constant';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -1,7 +1,8 @@
1
1
  import { z } from 'zod';
2
- import { HTTP_METHOD, JsonSchema } from '../../common';
2
+ import { HTTP_METHOD } from '../../common';
3
3
  import { PERMISSIONS_API, PERMISSIONS_CONTROLLER } from '../permissions.api';
4
4
  import { PermissionSchema } from '../permission.model';
5
+ import { PermissionResponseSchema } from '../permission.response.schema';
5
6
 
6
7
  const CreatePermissionContractRequestSchema = PermissionSchema.omit({
7
8
  id: true,
@@ -34,10 +35,6 @@ export namespace CreatePermissionContract {
34
35
  export const RequestSchema = CreatePermissionContractRequestSchema;
35
36
  export type TRequest = z.infer<typeof RequestSchema>;
36
37
 
37
- export const ResponseSchema = PermissionSchema.transform(data => {
38
- return {
39
- privet: 'Hello',
40
- };
41
- });
38
+ export const ResponseSchema = PermissionResponseSchema;
42
39
  export type TResponse = z.infer<typeof ResponseSchema>;
43
40
  }
@@ -0,0 +1,6 @@
1
+ import { PermissionSchema } from './permission.model';
2
+
3
+ export const PermissionResponseSchema = PermissionSchema.transform(({ conditions, ...rest }) => ({
4
+ ...rest,
5
+ conditions: conditions ? JSON.parse(conditions) : undefined,
6
+ }));