hh-contracts 0.0.50 → 0.0.52

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.
@@ -7,32 +7,32 @@ exports.APP_ERRORS = {
7
7
  validation: {
8
8
  statusCode: 400, // HttpStatus.BAD_REQUEST,
9
9
  code: 'COMMON-01',
10
- message: 'Validation error.',
10
+ messageKey: 'errors.common.validation',
11
11
  },
12
12
  unauthorized: {
13
13
  statusCode: 401, // HttpStatus.UNAUTHORIZED,
14
14
  code: 'COMMON-02',
15
- message: 'Unauthorized.',
15
+ messageKey: 'errors.common.unauthorized',
16
16
  },
17
17
  forbidden: {
18
18
  statusCode: 403, // HttpStatus.FORBIDDEN,
19
19
  code: 'COMMON-03',
20
- message: 'You are not allowed to perform this action.',
20
+ messageKey: 'errors.common.forbidden',
21
21
  },
22
22
  requestTimeout: {
23
23
  statusCode: 408, // HttpStatus.REQUEST_TIMEOUT,
24
24
  code: 'COMMON-04',
25
- message: 'Request timeout.',
25
+ messageKey: 'errors.common.requestTimeout',
26
26
  },
27
27
  unprocessableEntity: {
28
28
  statusCode: 422, // HttpStatus.UNPROCESSABLE_ENTITY,
29
29
  code: 'COMMON-05',
30
- message: 'Unprocessable entity.',
30
+ messageKey: 'errors.common.unprocessableEntity',
31
31
  },
32
32
  internalServer: {
33
33
  statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
34
34
  code: 'COMMON-06',
35
- message: 'Internal server error.',
35
+ messageKey: 'errors.common.internalServer',
36
36
  },
37
37
  // Перенести в отдельную сущность
38
38
  // hotelClientNotConnected: {
@@ -50,74 +50,111 @@ exports.APP_ERRORS = {
50
50
  wrongCredentials: {
51
51
  statusCode: 401, // HttpStatus.UNAUTHORIZED,
52
52
  code: 'AUTH-01',
53
- message: 'Login or password is wrong.',
53
+ messageKey: 'errors.auth.wrongCredentials',
54
+ },
55
+ },
56
+ translation: {
57
+ alreadyExists: {
58
+ statusCode: 409, // HttpStatus.CONFLICT,
59
+ code: 'TRANSLATION-02',
60
+ messageKey: 'errors.translation.alreadyExists',
61
+ },
62
+ entityFieldExists: {
63
+ statusCode: 409, // HttpStatus.CONFLICT,
64
+ code: 'TRANSLATION-03',
65
+ messageKey: 'errors.translation.entityFieldExists',
66
+ },
67
+ createFailed: {
68
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
69
+ code: 'TRANSLATION-04',
70
+ messageKey: 'errors.translation.createFailed',
71
+ },
72
+ updateFailed: {
73
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
74
+ code: 'TRANSLATION-05',
75
+ messageKey: 'errors.translation.updateFailed',
76
+ },
77
+ deletFailed: {
78
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
79
+ code: 'TRANSLATION-06',
80
+ messageKey: 'errors.translation.deleteFailed',
81
+ },
82
+ findFailed: {
83
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
84
+ code: 'TRANSLATION-07',
85
+ messageKey: 'errors.translation.findFailed',
86
+ },
87
+ required: {
88
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
89
+ code: 'TRANSLATION-08',
90
+ messageKey: 'errors.translation.required',
54
91
  },
55
92
  },
56
93
  user: {
57
94
  notFound: {
58
95
  statusCode: 404, // HttpStatus.NOT_FOUND,
59
96
  code: 'USER-01',
60
- message: 'User not found.',
97
+ messageKey: 'errors.user.notFound',
61
98
  },
62
99
  alreadyExists: {
63
100
  statusCode: 409, // HttpStatus.CONFLICT,
64
101
  code: 'USER-02',
65
- message: 'User already exists.',
102
+ messageKey: 'errors.user.alreadyExists',
66
103
  },
67
104
  },
68
105
  role: {
69
106
  notFound: {
70
107
  statusCode: 404, // HttpStatus.NOT_FOUND,
71
108
  code: 'ROLE-01',
72
- message: 'Role not found.',
109
+ messageKey: 'errors.role.notFound',
73
110
  },
74
111
  alreadyExists: {
75
112
  statusCode: 409, // HttpStatus.CONFLICT,
76
113
  code: 'ROLE-02',
77
- message: 'Role already exists.',
114
+ messageKey: 'errors.role.alreadyExists',
78
115
  },
79
116
  },
80
117
  permission: {
81
118
  notFound: {
82
119
  statusCode: 404, // HttpStatus.NOT_FOUND,
83
120
  code: 'PERMISSION-01',
84
- message: 'Permission not found.',
121
+ messageKey: 'errors.permission.notFound',
85
122
  },
86
123
  alreadyExists: {
87
124
  statusCode: 409, // HttpStatus.CONFLICT,
88
125
  code: 'PERMISSION-02',
89
- message: 'Permission already exists.',
126
+ messageKey: 'errors.permission.alreadyExists',
90
127
  },
91
128
  },
92
129
  hotel: {
93
130
  notFound: {
94
131
  statusCode: 404, // HttpStatus.NOT_FOUND,
95
132
  code: 'HOTEL-01',
96
- message: 'Hotel not found.',
133
+ messageKey: 'errors.hotel.notFound',
97
134
  },
98
135
  alreadyExists: {
99
136
  statusCode: 409, // HttpStatus.CONFLICT,
100
137
  code: 'HOTEL-02',
101
- message: 'Hotel already exists.',
138
+ messageKey: 'errors.hotel.alreadyExists',
102
139
  },
103
140
  },
104
141
  roomCategory: {
105
142
  notFound: {
106
143
  statusCode: 404, // HttpStatus.NOT_FOUND,
107
144
  code: 'ROOM-CATEGORY-01',
108
- message: 'Room category not found.',
145
+ messageKey: 'errors.roomCategory.notFound',
109
146
  },
110
147
  alreadyExists: {
111
148
  statusCode: 409, // HttpStatus.CONFLICT,
112
149
  code: 'ROOM-CATEGORY-02',
113
- message: 'Room category already exists.',
150
+ messageKey: 'errors.roomCategory.alreadyExists',
114
151
  },
115
152
  },
116
153
  room: {
117
- not: {
154
+ notFound: {
118
155
  statusCode: 404, // HttpStatus.NOT_FOUND,
119
156
  code: 'ROOM-01',
120
- message: 'Room not found.',
157
+ messageKey: 'errors.room.notFound',
121
158
  },
122
159
  },
123
160
  };
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./app-ability.constant"), exports);
18
- __exportStar(require("./app-error.constant"), exports);
18
+ __exportStar(require("./app-errors.constant"), exports);
19
19
  __exportStar(require("./locales.constant"), exports);
20
20
  __exportStar(require("./default-pagination-config.constant"), exports);
21
21
  __exportStar(require("./http-method.constant"), exports);
@@ -25,3 +25,4 @@ __exportStar(require("./navigation-item-type.constant"), exports);
25
25
  __exportStar(require("./order-direction.constant"), exports);
26
26
  __exportStar(require("./route-component-key.constants"), exports);
27
27
  __exportStar(require("./translatable-field.constant"), exports);
28
+ __exportStar(require("./zod-error-mapping.constant"), exports);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZOD_ERROR_MAPPING = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.ZOD_ERROR_MAPPING = {
6
+ [zod_1.ZodIssueCode.invalid_type]: 'errors.validation.invalidType',
7
+ [zod_1.ZodIssueCode.invalid_literal]: 'errors.validation.invalidLiteral',
8
+ [zod_1.ZodIssueCode.custom]: 'errors.validation.custom',
9
+ [zod_1.ZodIssueCode.invalid_union]: 'errors.validation.invalidUnion',
10
+ [zod_1.ZodIssueCode.invalid_union_discriminator]: 'errors.validation.invalidUnionDiscriminator',
11
+ [zod_1.ZodIssueCode.invalid_enum_value]: 'errors.validation.invalidEnumValue',
12
+ [zod_1.ZodIssueCode.unrecognized_keys]: 'errors.validation.unrecognizedKeys',
13
+ [zod_1.ZodIssueCode.invalid_arguments]: 'errors.validation.invalidArguments',
14
+ [zod_1.ZodIssueCode.invalid_return_type]: 'errors.validation.invalidReturnType',
15
+ [zod_1.ZodIssueCode.invalid_date]: 'errors.validation.invalidDate',
16
+ [zod_1.ZodIssueCode.invalid_string]: 'errors.validation.invalidString',
17
+ [zod_1.ZodIssueCode.too_small]: 'errors.validation.tooSmall',
18
+ [zod_1.ZodIssueCode.too_big]: 'errors.validation.tooBig',
19
+ [zod_1.ZodIssueCode.invalid_intersection_types]: 'errors.validation.invalidIntersectionTypes',
20
+ [zod_1.ZodIssueCode.not_multiple_of]: 'errors.validation.notMultipleOf',
21
+ [zod_1.ZodIssueCode.not_finite]: 'errors.validation.notFinite',
22
+ };
@@ -10,7 +10,7 @@ exports.TranslationPersistedSchema = zod_1.z.object({
10
10
  entityId: zod_1.z.string(),
11
11
  lang: language_keys_schema_1.LanguageKeysSchema,
12
12
  field: zod_1.z.enum(translatable_field_constant_1.TRANSLATABLE_FIELD_VALUES),
13
- text: zod_1.z.string().min(1, { message: 'translationRequired' }),
13
+ text: zod_1.z.string().min(1),
14
14
  });
15
15
  exports.TranslationItemSchema = exports.TranslationPersistedSchema.omit({
16
16
  entityId: true,
@@ -19,13 +19,11 @@ exports.TranslationItemSchema = exports.TranslationPersistedSchema.omit({
19
19
  });
20
20
  exports.TranslationsArraySchema = zod_1.z
21
21
  .array(exports.TranslationItemSchema)
22
- .min(1, { message: 'translationAtLeastOneMustBeExists' })
22
+ .min(1)
23
23
  .refine(items => {
24
24
  const langs = items.map(item => item.lang);
25
25
  const uniqueLangs = new Set(langs);
26
26
  return langs.length === uniqueLangs.size;
27
- }, {
28
- message: 'duplicateLanguagesNotAllowed',
29
27
  });
30
28
  exports.TranslationsSchema = zod_1.z.object({
31
29
  name: exports.TranslationsArraySchema,
@@ -18,18 +18,12 @@ exports.JsonConditionsSchema = zod_1.z
18
18
  catch {
19
19
  return false;
20
20
  }
21
- }, { message: 'invalidJson' });
21
+ });
22
22
  exports.PermissionPersistedSchema = zod_1.z
23
23
  .object({
24
- id: zod_1.z.string().uuid({ message: 'idInvalidUuid' }),
25
- action: zod_1.z.nativeEnum(common_1.AppAbility.ACTIONS, {
26
- invalid_type_error: 'actionInvalid',
27
- required_error: 'actionRequired',
28
- }),
29
- subject: zod_1.z.nativeEnum(common_1.AppAbility.SUBJECTS, {
30
- invalid_type_error: 'subjectInvalid',
31
- required_error: 'subjectRequired',
32
- }),
24
+ id: zod_1.z.string().uuid(),
25
+ action: zod_1.z.nativeEnum(common_1.AppAbility.ACTIONS),
26
+ subject: zod_1.z.nativeEnum(common_1.AppAbility.SUBJECTS),
33
27
  conditions: exports.JsonConditionsSchema,
34
28
  })
35
29
  .merge(common_1.TimestampSchema);
@@ -0,0 +1,207 @@
1
+ // import { HttpStatus } from '@nestjs/common';
2
+
3
+ import { TZodErorrKey } from './zod-error-mapping.constant';
4
+
5
+ export const APP_ERRORS = {
6
+ common: {
7
+ validation: {
8
+ statusCode: 400, // HttpStatus.BAD_REQUEST,
9
+ code: 'COMMON-01',
10
+ messageKey: 'errors.common.validation',
11
+ },
12
+ unauthorized: {
13
+ statusCode: 401, // HttpStatus.UNAUTHORIZED,
14
+ code: 'COMMON-02',
15
+ messageKey: 'errors.common.unauthorized',
16
+ },
17
+ forbidden: {
18
+ statusCode: 403, // HttpStatus.FORBIDDEN,
19
+ code: 'COMMON-03',
20
+ messageKey: 'errors.common.forbidden',
21
+ },
22
+ requestTimeout: {
23
+ statusCode: 408, // HttpStatus.REQUEST_TIMEOUT,
24
+ code: 'COMMON-04',
25
+ messageKey: 'errors.common.requestTimeout',
26
+ },
27
+ unprocessableEntity: {
28
+ statusCode: 422, // HttpStatus.UNPROCESSABLE_ENTITY,
29
+ code: 'COMMON-05',
30
+ messageKey: 'errors.common.unprocessableEntity',
31
+ },
32
+ internalServer: {
33
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
34
+ code: 'COMMON-06',
35
+ messageKey: 'errors.common.internalServer',
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
+ messageKey: 'errors.auth.wrongCredentials',
54
+ },
55
+ },
56
+
57
+ translation: {
58
+ alreadyExists: {
59
+ statusCode: 409, // HttpStatus.CONFLICT,
60
+ code: 'TRANSLATION-02',
61
+ messageKey: 'errors.translation.alreadyExists',
62
+ },
63
+ entityFieldExists: {
64
+ statusCode: 409, // HttpStatus.CONFLICT,
65
+ code: 'TRANSLATION-03',
66
+ messageKey: 'errors.translation.entityFieldExists',
67
+ },
68
+ createFailed: {
69
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
70
+ code: 'TRANSLATION-04',
71
+ messageKey: 'errors.translation.createFailed',
72
+ },
73
+ updateFailed: {
74
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
75
+ code: 'TRANSLATION-05',
76
+ messageKey: 'errors.translation.updateFailed',
77
+ },
78
+ deletFailed: {
79
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
80
+ code: 'TRANSLATION-06',
81
+ messageKey: 'errors.translation.deleteFailed',
82
+ },
83
+ findFailed: {
84
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
85
+ code: 'TRANSLATION-07',
86
+ messageKey: 'errors.translation.findFailed',
87
+ },
88
+ required: {
89
+ statusCode: 500, // HttpStatus.INTERNAL_SERVER_ERROR,
90
+ code: 'TRANSLATION-08',
91
+ messageKey: 'errors.translation.required',
92
+ },
93
+ },
94
+
95
+ user: {
96
+ notFound: {
97
+ statusCode: 404, // HttpStatus.NOT_FOUND,
98
+ code: 'USER-01',
99
+ messageKey: 'errors.user.notFound',
100
+ },
101
+ alreadyExists: {
102
+ statusCode: 409, // HttpStatus.CONFLICT,
103
+ code: 'USER-02',
104
+ messageKey: 'errors.user.alreadyExists',
105
+ },
106
+ },
107
+ role: {
108
+ notFound: {
109
+ statusCode: 404, // HttpStatus.NOT_FOUND,
110
+ code: 'ROLE-01',
111
+ messageKey: 'errors.role.notFound',
112
+ },
113
+ alreadyExists: {
114
+ statusCode: 409, // HttpStatus.CONFLICT,
115
+ code: 'ROLE-02',
116
+ messageKey: 'errors.role.alreadyExists',
117
+ },
118
+ },
119
+ permission: {
120
+ notFound: {
121
+ statusCode: 404, // HttpStatus.NOT_FOUND,
122
+ code: 'PERMISSION-01',
123
+ messageKey: 'errors.permission.notFound',
124
+ },
125
+ alreadyExists: {
126
+ statusCode: 409, // HttpStatus.CONFLICT,
127
+ code: 'PERMISSION-02',
128
+ messageKey: 'errors.permission.alreadyExists',
129
+ },
130
+ },
131
+ hotel: {
132
+ notFound: {
133
+ statusCode: 404, // HttpStatus.NOT_FOUND,
134
+ code: 'HOTEL-01',
135
+ messageKey: 'errors.hotel.notFound',
136
+ },
137
+ alreadyExists: {
138
+ statusCode: 409, // HttpStatus.CONFLICT,
139
+ code: 'HOTEL-02',
140
+ messageKey: 'errors.hotel.alreadyExists',
141
+ },
142
+ },
143
+ roomCategory: {
144
+ notFound: {
145
+ statusCode: 404, // HttpStatus.NOT_FOUND,
146
+ code: 'ROOM-CATEGORY-01',
147
+ messageKey: 'errors.roomCategory.notFound',
148
+ },
149
+ alreadyExists: {
150
+ statusCode: 409, // HttpStatus.CONFLICT,
151
+ code: 'ROOM-CATEGORY-02',
152
+ messageKey: 'errors.roomCategory.alreadyExists',
153
+ },
154
+ },
155
+ room: {
156
+ notFound: {
157
+ statusCode: 404, // HttpStatus.NOT_FOUND,
158
+ code: 'ROOM-01',
159
+ messageKey: 'errors.room.notFound',
160
+ },
161
+ },
162
+ } as const;
163
+
164
+ interface IError {
165
+ statusCode: number;
166
+ code: string;
167
+ messageKey: string;
168
+ }
169
+
170
+ type TMappedErrors<T extends Record<string, unknown>> = {
171
+ [k in keyof T]: T[k] extends Record<string, unknown>
172
+ ? T[k] extends IError
173
+ ? T[k]
174
+ : TMappedErrors<T[k]>
175
+ : never;
176
+ }[keyof T];
177
+ export type TAppError = TMappedErrors<typeof APP_ERRORS>;
178
+ export type TAppErrorCode = TAppError['code'];
179
+ export type TAppErrorMessageKey = TAppError['messageKey'] | TZodErorrKey;
180
+
181
+ // type StringLeafPaths<T, K extends keyof T = keyof T> = K extends string
182
+ // ? T[K] extends string
183
+ // ? K
184
+ // : T[K] extends Record<string, any>
185
+ // ? `${K}.${StringLeafPaths<T[K]>}`
186
+ // : never
187
+ // : never;
188
+
189
+ // export type I18nStringPath = StringLeafPaths<I18nTranslations>;
190
+
191
+ export interface IBaseErrorDetails {
192
+ type?: string;
193
+ message?: string;
194
+ messageKey?: TAppErrorMessageKey; // Вместо I18nPath
195
+ directMessage?: string;
196
+ params?: Record<string, unknown>;
197
+ }
198
+
199
+ export interface IErrorDetails extends IBaseErrorDetails {
200
+ [key: string]: string | IErrorDetails | IErrorDetails[] | Record<string, unknown> | undefined;
201
+ }
202
+ export type TAppErrorDetails = Record<string, IErrorDetails | IErrorDetails[]>;
203
+
204
+ export type TAppErrorWithDetails = TAppError & {
205
+ message?: string;
206
+ details?: TAppErrorDetails;
207
+ };
@@ -1,5 +1,5 @@
1
1
  export * from './app-ability.constant';
2
- export * from './app-error.constant';
2
+ export * from './app-errors.constant';
3
3
  export * from './locales.constant';
4
4
  export * from './default-pagination-config.constant';
5
5
  export * from './http-method.constant';
@@ -9,3 +9,4 @@ export * from './navigation-item-type.constant';
9
9
  export * from './order-direction.constant';
10
10
  export * from './route-component-key.constants';
11
11
  export * from './translatable-field.constant';
12
+ export * from './zod-error-mapping.constant';
@@ -0,0 +1,22 @@
1
+ import { ZodIssueCode } from 'zod';
2
+
3
+ export const ZOD_ERROR_MAPPING = {
4
+ [ZodIssueCode.invalid_type]: 'errors.validation.invalidType',
5
+ [ZodIssueCode.invalid_literal]: 'errors.validation.invalidLiteral',
6
+ [ZodIssueCode.custom]: 'errors.validation.custom',
7
+ [ZodIssueCode.invalid_union]: 'errors.validation.invalidUnion',
8
+ [ZodIssueCode.invalid_union_discriminator]: 'errors.validation.invalidUnionDiscriminator',
9
+ [ZodIssueCode.invalid_enum_value]: 'errors.validation.invalidEnumValue',
10
+ [ZodIssueCode.unrecognized_keys]: 'errors.validation.unrecognizedKeys',
11
+ [ZodIssueCode.invalid_arguments]: 'errors.validation.invalidArguments',
12
+ [ZodIssueCode.invalid_return_type]: 'errors.validation.invalidReturnType',
13
+ [ZodIssueCode.invalid_date]: 'errors.validation.invalidDate',
14
+ [ZodIssueCode.invalid_string]: 'errors.validation.invalidString',
15
+ [ZodIssueCode.too_small]: 'errors.validation.tooSmall',
16
+ [ZodIssueCode.too_big]: 'errors.validation.tooBig',
17
+ [ZodIssueCode.invalid_intersection_types]: 'errors.validation.invalidIntersectionTypes',
18
+ [ZodIssueCode.not_multiple_of]: 'errors.validation.notMultipleOf',
19
+ [ZodIssueCode.not_finite]: 'errors.validation.notFinite',
20
+ } as const satisfies Record<ZodIssueCode, string>;
21
+
22
+ export type TZodErorrKey = (typeof ZOD_ERROR_MAPPING)[keyof typeof ZOD_ERROR_MAPPING];
@@ -8,7 +8,7 @@ export const TranslationPersistedSchema = z.object({
8
8
  entityId: z.string(),
9
9
  lang: LanguageKeysSchema,
10
10
  field: z.enum(TRANSLATABLE_FIELD_VALUES),
11
- text: z.string().min(1, { message: 'translationRequired' }),
11
+ text: z.string().min(1),
12
12
  });
13
13
  export type TTranslationPersisted = z.infer<typeof TranslationPersistedSchema>;
14
14
 
@@ -21,16 +21,16 @@ export type TTranslationItem = z.infer<typeof TranslationItemSchema>;
21
21
 
22
22
  export const TranslationsArraySchema = z
23
23
  .array(TranslationItemSchema)
24
- .min(1, { message: 'translationAtLeastOneMustBeExists' })
24
+ .min(1)
25
25
  .refine(
26
26
  items => {
27
27
  const langs = items.map(item => item.lang);
28
28
  const uniqueLangs = new Set(langs);
29
29
  return langs.length === uniqueLangs.size;
30
30
  },
31
- {
32
- message: 'duplicateLanguagesNotAllowed',
33
- },
31
+ // {
32
+ // message: 'duplicateLanguagesNotAllowed',
33
+ // },
34
34
  );
35
35
  export type TTranslationsArray = z.infer<typeof TranslationsArraySchema>;
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -16,21 +16,15 @@ export const JsonConditionsSchema = z
16
16
  return false;
17
17
  }
18
18
  },
19
- { message: 'invalidJson' },
19
+ // { message: 'invalidJson' },
20
20
  );
21
21
 
22
22
  export const PermissionPersistedSchema = z
23
23
  .object({
24
- id: z.string().uuid({ message: 'idInvalidUuid' }),
24
+ id: z.string().uuid(),
25
25
 
26
- action: z.nativeEnum(AppAbility.ACTIONS, {
27
- invalid_type_error: 'actionInvalid',
28
- required_error: 'actionRequired',
29
- }),
30
- subject: z.nativeEnum(AppAbility.SUBJECTS, {
31
- invalid_type_error: 'subjectInvalid',
32
- required_error: 'subjectRequired',
33
- }),
26
+ action: z.nativeEnum(AppAbility.ACTIONS),
27
+ subject: z.nativeEnum(AppAbility.SUBJECTS),
34
28
  conditions: JsonConditionsSchema,
35
29
  })
36
30
  .merge(TimestampSchema);
@@ -1,145 +0,0 @@
1
- // import { HttpStatus } from '@nestjs/common';
2
-
3
- export const APP_ERRORS = {
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_ERRORS>;
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 };