@mini2/core 1.0.2 → 1.0.5
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.
- package/Readme.MD +75 -2
- package/dist/app.d.ts +14 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +65 -0
- package/dist/app.js.map +1 -0
- package/dist/container.d.ts +4 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +11 -0
- package/dist/container.js.map +1 -0
- package/dist/expections/http.expection.d.ts +79 -0
- package/dist/expections/http.expection.d.ts.map +1 -0
- package/dist/expections/http.expection.js +140 -0
- package/dist/expections/http.expection.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/app.interface.d.ts +6 -0
- package/dist/interfaces/app.interface.d.ts.map +1 -0
- package/dist/interfaces/app.interface.js +3 -0
- package/dist/interfaces/app.interface.js.map +1 -0
- package/dist/interfaces/authenticated.interface.d.ts +5 -0
- package/dist/interfaces/authenticated.interface.d.ts.map +1 -0
- package/dist/interfaces/authenticated.interface.js +3 -0
- package/dist/interfaces/authenticated.interface.js.map +1 -0
- package/dist/interfaces/config.interface.d.ts +6 -0
- package/dist/interfaces/config.interface.d.ts.map +1 -0
- package/dist/interfaces/config.interface.js +3 -0
- package/dist/interfaces/config.interface.js.map +1 -0
- package/dist/interfaces/queue.interface.d.ts +6 -0
- package/dist/interfaces/queue.interface.d.ts.map +1 -0
- package/dist/interfaces/queue.interface.js +3 -0
- package/dist/interfaces/queue.interface.js.map +1 -0
- package/dist/interfaces/repository.interface.d.ts +34 -0
- package/dist/interfaces/repository.interface.d.ts.map +1 -0
- package/dist/interfaces/repository.interface.js +3 -0
- package/dist/interfaces/repository.interface.js.map +1 -0
- package/dist/middlewares/authenticated.middleware.d.ts +4 -0
- package/dist/middlewares/authenticated.middleware.d.ts.map +1 -0
- package/dist/middlewares/authenticated.middleware.js +14 -0
- package/dist/middlewares/authenticated.middleware.js.map +1 -0
- package/dist/middlewares/authorized.middleware.d.ts +7 -0
- package/dist/middlewares/authorized.middleware.d.ts.map +1 -0
- package/dist/middlewares/authorized.middleware.js +16 -0
- package/dist/middlewares/authorized.middleware.js.map +1 -0
- package/dist/middlewares/validation.middleware.d.ts +4 -0
- package/dist/middlewares/validation.middleware.d.ts.map +1 -0
- package/dist/middlewares/validation.middleware.js +65 -0
- package/dist/middlewares/validation.middleware.js.map +1 -0
- package/dist/response-builder.d.ts +26 -0
- package/dist/response-builder.d.ts.map +1 -0
- package/dist/response-builder.js +45 -0
- package/dist/response-builder.js.map +1 -0
- package/dist/rest.d.ts +43 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/rest.js +213 -0
- package/dist/rest.js.map +1 -0
- package/dist/swagger.d.ts +30 -0
- package/dist/swagger.d.ts.map +1 -0
- package/dist/swagger.js +214 -0
- package/dist/swagger.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/array-unify.d.ts +2 -0
- package/dist/utils/array-unify.d.ts.map +1 -0
- package/dist/utils/array-unify.js +8 -0
- package/dist/utils/array-unify.js.map +1 -0
- package/dist/utils/math.d.ts +2 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +7 -0
- package/dist/utils/math.js.map +1 -0
- package/package.json +38 -6
- package/__tests__/controller.test.ts +0 -349
- package/app.ts +0 -51
- package/container.ts +0 -7
- package/expections/http.expection.ts +0 -147
- package/interfaces/app.interface.ts +0 -6
- package/interfaces/authenticated.interface.ts +0 -3
- package/interfaces/config.interface.ts +0 -5
- package/interfaces/queue.interface.ts +0 -5
- package/interfaces/repository.interface.ts +0 -32
- package/middlewares/authenticated.middleware.ts +0 -15
- package/middlewares/authorized.middleware.ts +0 -19
- package/middlewares/validation.middleware.ts +0 -76
- package/response-builder.ts +0 -61
- package/rest.ts +0 -254
- package/swagger.ts +0 -265
- package/types.ts +0 -3
- package/utils/array-unify.ts +0 -4
- package/utils/math.ts +0 -3
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IsEmail,
|
|
3
|
-
IsNotEmpty,
|
|
4
|
-
validate as classValidate,
|
|
5
|
-
} from 'class-validator';
|
|
6
|
-
import {
|
|
7
|
-
authorized,
|
|
8
|
-
middleware,
|
|
9
|
-
authenticated,
|
|
10
|
-
controller,
|
|
11
|
-
get,
|
|
12
|
-
httpMethod,
|
|
13
|
-
validate,
|
|
14
|
-
req,
|
|
15
|
-
res,
|
|
16
|
-
buildRouterFromController,
|
|
17
|
-
} from '../rest';
|
|
18
|
-
import { IResponseBuilder, ResponseBuilder } from '../response-builder';
|
|
19
|
-
|
|
20
|
-
// Simple test class without problematic decorators
|
|
21
|
-
class TestClass {
|
|
22
|
-
testMethod(req: any, res: any): IResponseBuilder {
|
|
23
|
-
return new ResponseBuilder().ok('test');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
anotherMethod(): IResponseBuilder {
|
|
27
|
-
return new ResponseBuilder().created('created');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Validation test class with decorators (manual validation for testing)
|
|
32
|
-
class UserValidation {
|
|
33
|
-
email!: string;
|
|
34
|
-
username!: string;
|
|
35
|
-
password!: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Class with actual decorators for testing (simple approach)
|
|
39
|
-
class UserWithDecorators {
|
|
40
|
-
email!: string;
|
|
41
|
-
username!: string;
|
|
42
|
-
password!: string;
|
|
43
|
-
|
|
44
|
-
constructor(email: string, username: string, password: string) {
|
|
45
|
-
this.email = email;
|
|
46
|
-
this.username = username;
|
|
47
|
-
this.password = password;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
describe('REST Framework Components', () => {
|
|
52
|
-
let testClass: TestClass;
|
|
53
|
-
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
testClass = new TestClass();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('should create test class instance', () => {
|
|
59
|
-
expect(testClass).toBeDefined();
|
|
60
|
-
expect(testClass).toBeInstanceOf(TestClass);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('should have test methods', () => {
|
|
64
|
-
expect(typeof testClass.testMethod).toBe('function');
|
|
65
|
-
expect(typeof testClass.anotherMethod).toBe('function');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('decorators should be defined and importable', () => {
|
|
69
|
-
expect(controller).toBeDefined();
|
|
70
|
-
expect(get).toBeDefined();
|
|
71
|
-
expect(httpMethod).toBeDefined();
|
|
72
|
-
expect(validate).toBeDefined();
|
|
73
|
-
expect(authenticated).toBeDefined();
|
|
74
|
-
expect(authorized).toBeDefined();
|
|
75
|
-
expect(middleware).toBeDefined();
|
|
76
|
-
expect(req).toBeDefined();
|
|
77
|
-
expect(res).toBeDefined();
|
|
78
|
-
expect(buildRouterFromController).toBeDefined();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('ResponseBuilder should work correctly', () => {
|
|
82
|
-
const okResponse = new ResponseBuilder().ok('success');
|
|
83
|
-
expect(okResponse).toBeDefined();
|
|
84
|
-
expect(okResponse).toBeInstanceOf(ResponseBuilder);
|
|
85
|
-
|
|
86
|
-
const createdResponse = new ResponseBuilder().created('created');
|
|
87
|
-
expect(createdResponse).toBeDefined();
|
|
88
|
-
expect(createdResponse).toBeInstanceOf(ResponseBuilder);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('test class methods should return ResponseBuilder', () => {
|
|
92
|
-
const result1 = testClass.testMethod({}, {});
|
|
93
|
-
expect(result1).toBeInstanceOf(ResponseBuilder);
|
|
94
|
-
|
|
95
|
-
const result2 = testClass.anotherMethod();
|
|
96
|
-
expect(result2).toBeInstanceOf(ResponseBuilder);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('buildRouterFromController should be callable', () => {
|
|
100
|
-
// Test that the function exists and is callable
|
|
101
|
-
expect(typeof buildRouterFromController).toBe('function');
|
|
102
|
-
|
|
103
|
-
// Don't actually call it with decorators to avoid TypeScript errors
|
|
104
|
-
// Just verify it's a function
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('Validation Tests', () => {
|
|
109
|
-
test('should validate valid email', async () => {
|
|
110
|
-
const user = new UserValidation();
|
|
111
|
-
user.email = 'test@example.com';
|
|
112
|
-
user.username = 'testuser';
|
|
113
|
-
user.password = 'password123';
|
|
114
|
-
|
|
115
|
-
// Manual validation check
|
|
116
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
117
|
-
expect(emailRegex.test(user.email)).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('should reject invalid email', async () => {
|
|
121
|
-
const user = new UserValidation();
|
|
122
|
-
user.email = 'invalid-email';
|
|
123
|
-
user.username = 'testuser';
|
|
124
|
-
user.password = 'password123';
|
|
125
|
-
|
|
126
|
-
// Manual validation check
|
|
127
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
128
|
-
expect(emailRegex.test(user.email)).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('should validate non-empty username', () => {
|
|
132
|
-
const user = new UserValidation();
|
|
133
|
-
user.email = 'test@example.com';
|
|
134
|
-
user.username = 'testuser';
|
|
135
|
-
user.password = 'password123';
|
|
136
|
-
|
|
137
|
-
expect(user.username).toBeDefined();
|
|
138
|
-
expect(user.username.trim()).not.toBe('');
|
|
139
|
-
expect(user.username.length).toBeGreaterThan(0);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('should reject empty username', () => {
|
|
143
|
-
const user = new UserValidation();
|
|
144
|
-
user.email = 'test@example.com';
|
|
145
|
-
user.username = '';
|
|
146
|
-
user.password = 'password123';
|
|
147
|
-
|
|
148
|
-
expect(user.username.trim()).toBe('');
|
|
149
|
-
expect(user.username.length).toBe(0);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('should validate password requirements', () => {
|
|
153
|
-
const user = new UserValidation();
|
|
154
|
-
user.email = 'test@example.com';
|
|
155
|
-
user.username = 'testuser';
|
|
156
|
-
user.password = 'password123';
|
|
157
|
-
|
|
158
|
-
// Basic password validation
|
|
159
|
-
expect(user.password).toBeDefined();
|
|
160
|
-
expect(user.password.length).toBeGreaterThanOrEqual(6);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('should reject weak password', () => {
|
|
164
|
-
const user = new UserValidation();
|
|
165
|
-
user.email = 'test@example.com';
|
|
166
|
-
user.username = 'testuser';
|
|
167
|
-
user.password = '123';
|
|
168
|
-
|
|
169
|
-
// Weak password check
|
|
170
|
-
expect(user.password.length).toBeLessThan(6);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('validation decorators should be importable', () => {
|
|
174
|
-
expect(IsEmail).toBeDefined();
|
|
175
|
-
expect(IsNotEmpty).toBeDefined();
|
|
176
|
-
expect(typeof IsEmail).toBe('function');
|
|
177
|
-
expect(typeof IsNotEmpty).toBe('function');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('should validate multiple fields together', () => {
|
|
181
|
-
const validUser = new UserValidation();
|
|
182
|
-
validUser.email = 'user@example.com';
|
|
183
|
-
validUser.username = 'validuser';
|
|
184
|
-
validUser.password = 'securepass123';
|
|
185
|
-
|
|
186
|
-
// Validate all fields
|
|
187
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
188
|
-
const isValidEmail = emailRegex.test(validUser.email);
|
|
189
|
-
const isValidUsername = validUser.username.trim().length > 0;
|
|
190
|
-
const isValidPassword = validUser.password.length >= 6;
|
|
191
|
-
|
|
192
|
-
expect(isValidEmail).toBe(true);
|
|
193
|
-
expect(isValidUsername).toBe(true);
|
|
194
|
-
expect(isValidPassword).toBe(true);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('should handle validation edge cases', () => {
|
|
198
|
-
const user = new UserValidation();
|
|
199
|
-
|
|
200
|
-
// Test edge cases
|
|
201
|
-
user.email = 'a@b.co'; // minimum valid email
|
|
202
|
-
user.username = 'a'; // minimum username
|
|
203
|
-
user.password = '123456'; // minimum password
|
|
204
|
-
|
|
205
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
206
|
-
expect(emailRegex.test(user.email)).toBe(true);
|
|
207
|
-
expect(user.username.length).toBeGreaterThan(0);
|
|
208
|
-
expect(user.password.length).toBeGreaterThanOrEqual(6);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('should use class-validator with plain objects', async () => {
|
|
212
|
-
// Test class-validator functionality without decorators on class
|
|
213
|
-
const plainObject = {
|
|
214
|
-
email: 'test@example.com',
|
|
215
|
-
username: 'testuser',
|
|
216
|
-
password: 'password123',
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// We can test the validation logic directly
|
|
220
|
-
expect(plainObject.email).toMatch(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
|
|
221
|
-
expect(plainObject.username).toBeTruthy();
|
|
222
|
-
expect(plainObject.password).toHaveLength(11);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
test('should validate user with constructor', () => {
|
|
226
|
-
const validUser = new UserWithDecorators(
|
|
227
|
-
'user@example.com',
|
|
228
|
-
'validuser',
|
|
229
|
-
'securepass123'
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
expect(validUser.email).toBe('user@example.com');
|
|
233
|
-
expect(validUser.username).toBe('validuser');
|
|
234
|
-
expect(validUser.password).toBe('securepass123');
|
|
235
|
-
|
|
236
|
-
// Validation logic
|
|
237
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
238
|
-
expect(emailRegex.test(validUser.email)).toBe(true);
|
|
239
|
-
expect(validUser.username.trim().length).toBeGreaterThan(0);
|
|
240
|
-
expect(validUser.password.length).toBeGreaterThanOrEqual(6);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
test('should test validation helper functions', () => {
|
|
244
|
-
// Helper validation functions
|
|
245
|
-
const isValidEmail = (email: string) =>
|
|
246
|
-
/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
247
|
-
const isNotEmpty = (value: string) =>
|
|
248
|
-
Boolean(value && value.trim().length > 0);
|
|
249
|
-
const isMinLength = (value: string, min: number) =>
|
|
250
|
-
Boolean(value && value.length >= min);
|
|
251
|
-
|
|
252
|
-
// Test valid inputs
|
|
253
|
-
expect(isValidEmail('test@example.com')).toBe(true);
|
|
254
|
-
expect(isNotEmpty('testuser')).toBe(true);
|
|
255
|
-
expect(isMinLength('password123', 6)).toBe(true);
|
|
256
|
-
|
|
257
|
-
// Test invalid inputs
|
|
258
|
-
expect(isValidEmail('invalid-email')).toBe(false);
|
|
259
|
-
expect(isNotEmpty('')).toBe(false);
|
|
260
|
-
expect(isMinLength('123', 6)).toBe(false);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test('should validate complex email patterns', () => {
|
|
264
|
-
const validEmails = [
|
|
265
|
-
'user@example.com',
|
|
266
|
-
'test.email@domain.co.uk',
|
|
267
|
-
'user+tag@example.org',
|
|
268
|
-
'user_name@example-domain.com',
|
|
269
|
-
];
|
|
270
|
-
|
|
271
|
-
const invalidEmails = [
|
|
272
|
-
'invalid-email',
|
|
273
|
-
'@example.com',
|
|
274
|
-
'user@',
|
|
275
|
-
'user.example.com',
|
|
276
|
-
'user@.com',
|
|
277
|
-
'user@com',
|
|
278
|
-
'',
|
|
279
|
-
];
|
|
280
|
-
|
|
281
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
282
|
-
|
|
283
|
-
validEmails.forEach((email) => {
|
|
284
|
-
expect(emailRegex.test(email)).toBe(true);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
invalidEmails.forEach((email) => {
|
|
288
|
-
expect(emailRegex.test(email)).toBe(false);
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
test('should validate username constraints', () => {
|
|
293
|
-
const validUsernames = ['user', 'testuser', 'user123', 'user_name', 'a'];
|
|
294
|
-
const invalidUsernames = ['', ' ', ' \t ', ' \n '];
|
|
295
|
-
|
|
296
|
-
validUsernames.forEach((username) => {
|
|
297
|
-
expect(username.trim().length).toBeGreaterThan(0);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
invalidUsernames.forEach((username) => {
|
|
301
|
-
expect(username.trim().length).toBe(0);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
test('should validate password strength', () => {
|
|
306
|
-
const strongPasswords = [
|
|
307
|
-
'password123',
|
|
308
|
-
'SecurePass!',
|
|
309
|
-
'MyP@ssw0rd',
|
|
310
|
-
'LongPassword123',
|
|
311
|
-
];
|
|
312
|
-
const weakPasswords = ['123', '', 'pass', '12345'];
|
|
313
|
-
|
|
314
|
-
strongPasswords.forEach((password) => {
|
|
315
|
-
expect(password.length).toBeGreaterThanOrEqual(6);
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
weakPasswords.forEach((password) => {
|
|
319
|
-
expect(password.length).toBeLessThan(6);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
test('should handle validation errors gracefully', () => {
|
|
324
|
-
const invalidUser = new UserValidation();
|
|
325
|
-
invalidUser.email = 'invalid';
|
|
326
|
-
invalidUser.username = '';
|
|
327
|
-
invalidUser.password = '123';
|
|
328
|
-
|
|
329
|
-
// Collect validation errors
|
|
330
|
-
const errors: string[] = [];
|
|
331
|
-
|
|
332
|
-
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(invalidUser.email)) {
|
|
333
|
-
errors.push('Invalid email format');
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (!invalidUser.username.trim()) {
|
|
337
|
-
errors.push('Username is required');
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (invalidUser.password.length < 6) {
|
|
341
|
-
errors.push('Password must be at least 6 characters');
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
expect(errors).toHaveLength(3);
|
|
345
|
-
expect(errors).toContain('Invalid email format');
|
|
346
|
-
expect(errors).toContain('Username is required');
|
|
347
|
-
expect(errors).toContain('Password must be at least 6 characters');
|
|
348
|
-
});
|
|
349
|
-
});
|
package/app.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import express, { Express } from 'express';
|
|
2
|
-
import cors from 'cors';
|
|
3
|
-
import morgan from 'morgan';
|
|
4
|
-
import { IApp } from './interfaces/app.interface';
|
|
5
|
-
import { IConfig } from './interfaces/config.interface';
|
|
6
|
-
import { buildApp } from './rest';
|
|
7
|
-
import { Container, multiInject } from 'inversify';
|
|
8
|
-
import { SwaggerIntegration } from './swagger';
|
|
9
|
-
import { MINI_TYPES } from './types';
|
|
10
|
-
|
|
11
|
-
class App implements IApp {
|
|
12
|
-
app: Express;
|
|
13
|
-
container: Container;
|
|
14
|
-
|
|
15
|
-
constructor(@multiInject(MINI_TYPES.IController) private controllers: any[]) {
|
|
16
|
-
this.app = express();
|
|
17
|
-
this.container = new Container();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async init(config: IConfig) {
|
|
21
|
-
this.app.use(express.json());
|
|
22
|
-
this.app.use(express.urlencoded({ extended: true }));
|
|
23
|
-
this.app.use(cors());
|
|
24
|
-
this.app.use(morgan('dev'));
|
|
25
|
-
this.app.listen(config.port, () => {
|
|
26
|
-
console.log(`Server is running on port ${config.port}`);
|
|
27
|
-
});
|
|
28
|
-
const swaggerIntegration = new SwaggerIntegration({
|
|
29
|
-
title: config.applicationName,
|
|
30
|
-
description: `API documentation for ${config.applicationName}`,
|
|
31
|
-
version: '1.0.0',
|
|
32
|
-
servers: [
|
|
33
|
-
{
|
|
34
|
-
url: `http://${config.host}:${config.port}`,
|
|
35
|
-
description: 'Development server',
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
docsPath: '/api-docs',
|
|
39
|
-
jsonPath: '/api-docs.json',
|
|
40
|
-
});
|
|
41
|
-
swaggerIntegration.generateSwaggerSpec(this.controllers);
|
|
42
|
-
swaggerIntegration.setupSwagger(this.app);
|
|
43
|
-
buildApp(this.app, this.controllers);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async afterInit() {
|
|
47
|
-
console.log('afterInit');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default App;
|
package/container.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
export interface IValidationError {
|
|
2
|
-
field: string;
|
|
3
|
-
errors: string[];
|
|
4
|
-
}
|
|
5
|
-
export interface IErrorMessage {
|
|
6
|
-
validationErrors?: IValidationError[];
|
|
7
|
-
message?: string;
|
|
8
|
-
errorId?: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default class HttpException extends Error {
|
|
12
|
-
code: number;
|
|
13
|
-
message: string;
|
|
14
|
-
messageJson: IErrorMessage;
|
|
15
|
-
constructor(message: IErrorMessage, code = 500) {
|
|
16
|
-
super(JSON.stringify(message));
|
|
17
|
-
this.code = code;
|
|
18
|
-
this.message = JSON.stringify(message);
|
|
19
|
-
this.messageJson = message;
|
|
20
|
-
Error.captureStackTrace(this, this.constructor);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class BadRequestException extends HttpException {
|
|
25
|
-
constructor(error: IErrorMessage) {
|
|
26
|
-
super(error, 400);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class UnauthorizedException extends HttpException {
|
|
31
|
-
constructor(error: IErrorMessage) {
|
|
32
|
-
super(error, 401);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class PaymentRequiredException extends HttpException {
|
|
37
|
-
constructor(error: IErrorMessage) {
|
|
38
|
-
super(error, 402);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class ForbiddenException extends HttpException {
|
|
43
|
-
constructor(error: IErrorMessage) {
|
|
44
|
-
super(error, 403);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class NotFoundException extends HttpException {
|
|
49
|
-
constructor(error: IErrorMessage) {
|
|
50
|
-
super(error, 404);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class MethodNotAllowedException extends HttpException {
|
|
55
|
-
constructor(error: IErrorMessage) {
|
|
56
|
-
super(error, 405);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class NotAcceptableException extends HttpException {
|
|
61
|
-
constructor(error: IErrorMessage) {
|
|
62
|
-
super(error, 406);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export class ConflictException extends HttpException {
|
|
67
|
-
constructor(error: IErrorMessage) {
|
|
68
|
-
super(error, 409);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export class GoneException extends HttpException {
|
|
73
|
-
constructor(error: IErrorMessage) {
|
|
74
|
-
super(error, 410);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export class LengthRequiredException extends HttpException {
|
|
79
|
-
constructor(error: IErrorMessage) {
|
|
80
|
-
super(error, 411);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export class PreconditionFailedException extends HttpException {
|
|
85
|
-
constructor(error: IErrorMessage) {
|
|
86
|
-
super(error, 412);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class PayloadTooLargeException extends HttpException {
|
|
91
|
-
constructor(error: IErrorMessage) {
|
|
92
|
-
super(error, 413);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class UnsupportedMediaTypeException extends HttpException {
|
|
97
|
-
constructor(error: IErrorMessage) {
|
|
98
|
-
super(error, 415);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export class UnprocessableEntityException extends HttpException {
|
|
103
|
-
constructor(error: IErrorMessage) {
|
|
104
|
-
super(error, 422);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export class TooManyRequestsException extends HttpException {
|
|
109
|
-
constructor(error: IErrorMessage) {
|
|
110
|
-
super(error, 429);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export class InternalServerErrorException extends HttpException {
|
|
115
|
-
constructor(error: IErrorMessage) {
|
|
116
|
-
super(error, 500);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export class NotImplementedException extends HttpException {
|
|
121
|
-
constructor(error: IErrorMessage) {
|
|
122
|
-
super(error, 501);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export class BadGatewayException extends HttpException {
|
|
127
|
-
constructor(error: IErrorMessage) {
|
|
128
|
-
super(error, 502);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export class ServiceUnavailableException extends HttpException {
|
|
133
|
-
constructor(error: IErrorMessage) {
|
|
134
|
-
super(error, 503);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export class GatewayTimeoutException extends HttpException {
|
|
139
|
-
constructor(error: IErrorMessage) {
|
|
140
|
-
super(error, 504);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
export class ExpiredException extends HttpException {
|
|
144
|
-
constructor(error: IErrorMessage) {
|
|
145
|
-
super(error, 410);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Document } from 'mongoose';
|
|
2
|
-
|
|
3
|
-
export interface IRepository<IdentifierType, ModelType> {
|
|
4
|
-
findAll(): Promise<
|
|
5
|
-
(ModelType & { id: string; createdAt: Date; updatedAt: Date })[]
|
|
6
|
-
>;
|
|
7
|
-
findById(
|
|
8
|
-
id: IdentifierType
|
|
9
|
-
): Promise<
|
|
10
|
-
(ModelType & { id: string; createdAt: Date; updatedAt: Date }) | null
|
|
11
|
-
>;
|
|
12
|
-
create(
|
|
13
|
-
item: ModelType
|
|
14
|
-
): Promise<ModelType & { id: string; createdAt: Date; updatedAt: Date }>;
|
|
15
|
-
update(
|
|
16
|
-
id: IdentifierType,
|
|
17
|
-
item: Partial<ModelType>
|
|
18
|
-
): Promise<ModelType & { id: string; createdAt: Date; updatedAt: Date }>;
|
|
19
|
-
delete(id: IdentifierType): Promise<void>;
|
|
20
|
-
findPaginated(
|
|
21
|
-
query: Partial<ModelType>,
|
|
22
|
-
page: number,
|
|
23
|
-
limit: number
|
|
24
|
-
): Promise<(ModelType & { id: string; createdAt: Date; updatedAt: Date })[]>;
|
|
25
|
-
mapper(
|
|
26
|
-
model: ModelType &
|
|
27
|
-
Document<IdentifierType, {}, ModelType> & {
|
|
28
|
-
createdAt: Date;
|
|
29
|
-
updatedAt: Date;
|
|
30
|
-
}
|
|
31
|
-
): ModelType & { id: string; createdAt: Date; updatedAt: Date };
|
|
32
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Response } from 'express';
|
|
2
|
-
import { UnauthorizedException } from '../expections/http.expection';
|
|
3
|
-
import { IAuthenticatedRequest } from '../interfaces/authenticated.interface';
|
|
4
|
-
|
|
5
|
-
export const authenticatedMiddleware = (
|
|
6
|
-
req: IAuthenticatedRequest,
|
|
7
|
-
_res: Response,
|
|
8
|
-
next: NextFunction
|
|
9
|
-
) => {
|
|
10
|
-
if (req.authenticated) next();
|
|
11
|
-
else
|
|
12
|
-
throw new UnauthorizedException({
|
|
13
|
-
message: 'Unauthorized',
|
|
14
|
-
});
|
|
15
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import { ForbiddenException } from '../expections/http.expection';
|
|
3
|
-
|
|
4
|
-
export const authorizedMiddleware = (permissions: string[]) => {
|
|
5
|
-
return (
|
|
6
|
-
req: Request & { user: { permissions: string[] } },
|
|
7
|
-
_res: Response,
|
|
8
|
-
next: NextFunction
|
|
9
|
-
) => {
|
|
10
|
-
if (
|
|
11
|
-
permissions.some((permission) => req.user.permissions.includes(permission))
|
|
12
|
-
)
|
|
13
|
-
next();
|
|
14
|
-
else
|
|
15
|
-
throw new ForbiddenException({
|
|
16
|
-
message: 'Forbidden',
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
};
|