express-generator-typescript 2.7.10 → 2.7.12
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/lib/express-generator-typescript.js +44 -11
- package/lib/project-files/.prettierignore +12 -0
- package/lib/project-files/.prettierrc.json +15 -0
- package/lib/project-files/README.md +58 -65
- package/lib/project-files/config/.env.development +3 -3
- package/lib/project-files/config/.env.production +3 -3
- package/lib/project-files/config/.env.test +3 -3
- package/lib/project-files/config.ts +20 -22
- package/lib/project-files/eslint.config.ts +46 -100
- package/lib/project-files/package.json +59 -56
- package/lib/project-files/scripts/build.ts +23 -28
- package/lib/project-files/scripts/common/utils.ts +11 -11
- package/lib/project-files/src/common/constants/HttpStatusCodes.ts +393 -0
- package/lib/project-files/src/common/constants/{PATHS.ts → Paths.ts} +15 -15
- package/lib/project-files/src/common/constants/{ENV.ts → env.ts} +28 -19
- package/lib/project-files/src/common/{util/misc.ts → utils/number-utils.ts} +10 -11
- package/lib/project-files/src/common/{util → utils}/route-errors.ts +35 -38
- package/lib/project-files/src/common/{util → utils}/validators.ts +14 -14
- package/lib/project-files/src/{index.ts → main.ts} +24 -27
- package/lib/project-files/src/models/User.ts +69 -70
- package/lib/project-files/src/models/common/{types.ts → IModel.ts} +4 -5
- package/lib/project-files/src/public/stylesheets/users.css +50 -48
- package/lib/project-files/src/repos/MockOrm.ts +57 -63
- package/lib/project-files/src/repos/UserRepo.ts +133 -133
- package/lib/project-files/src/repos/common/database.test.json +22 -0
- package/lib/project-files/src/routes/UserRoutes.ts +77 -69
- package/lib/project-files/src/routes/{index.ts → apiRouter.ts} +28 -31
- package/lib/project-files/src/routes/common/express-types.ts +9 -0
- package/lib/project-files/src/routes/common/{util/index.ts → parseReq.ts} +19 -16
- package/lib/project-files/src/server.ts +79 -86
- package/lib/project-files/src/services/UserService.ts +64 -70
- package/lib/project-files/src/views/users.html +118 -132
- package/lib/project-files/tests/common/{utils.ts → comparators.ts} +38 -55
- package/lib/project-files/tests/common/error-utils.ts +25 -0
- package/lib/project-files/tests/common/{types.ts → supertest-types.ts} +15 -16
- package/lib/project-files/tests/{aux/setup.ts → support/agent.ts} +23 -26
- package/lib/project-files/tests/users.test.ts +131 -123
- package/lib/project-files/tsconfig.json +30 -35
- package/lib/project-files/tsconfig.prod.json +27 -30
- package/lib/project-files/vitest.config.mts +18 -18
- package/package.json +1 -1
- package/lib/project-files/src/common/constants/HTTP_STATUS_CODES.ts +0 -81
- package/lib/project-files/src/common/constants/index.ts +0 -11
- package/lib/project-files/src/repos/database.test.json +0 -1
- package/lib/project-files/src/routes/common/types/index.ts +0 -10
- /package/lib/project-files/src/repos/{database.json → common/database.json} +0 -0
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import orm from './MockOrm';
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Functions
|
|
8
|
-
******************************************************************************/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get one user.
|
|
12
|
-
*/
|
|
13
|
-
async function getOne(email: string): Promise<IUser | null> {
|
|
14
|
-
const db = await orm.openDb();
|
|
15
|
-
for (const user of db.users) {
|
|
16
|
-
if (user.email === email) {
|
|
17
|
-
return user;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* See if a user with the given id exists.
|
|
25
|
-
*/
|
|
26
|
-
async function persists(id: number): Promise<boolean> {
|
|
27
|
-
const db = await orm.openDb();
|
|
28
|
-
for (const user of db.users) {
|
|
29
|
-
if (user.id === id) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get all users.
|
|
38
|
-
*/
|
|
39
|
-
async function getAll(): Promise<IUser[]> {
|
|
40
|
-
const db = await orm.openDb();
|
|
41
|
-
return db.users;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Add one user.
|
|
46
|
-
*/
|
|
47
|
-
async function add(user: IUser): Promise<void> {
|
|
48
|
-
const db = await orm.openDb();
|
|
49
|
-
user.id = getRandomInt();
|
|
50
|
-
db.users.push(user);
|
|
51
|
-
return orm.saveDb(db);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Update a user.
|
|
56
|
-
*/
|
|
57
|
-
async function update(user: IUser): Promise<void> {
|
|
58
|
-
const db = await orm.openDb();
|
|
59
|
-
for (let i = 0; i < db.users.length; i++) {
|
|
60
|
-
if (db.users[i].id === user.id) {
|
|
61
|
-
const dbUser = db.users[i];
|
|
62
|
-
db.users[i] = {
|
|
63
|
-
...dbUser,
|
|
64
|
-
name: user.name,
|
|
65
|
-
email: user.email,
|
|
66
|
-
};
|
|
67
|
-
return orm.saveDb(db);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Delete one user.
|
|
74
|
-
*/
|
|
75
|
-
async function __delete__(id: number): Promise<void> {
|
|
76
|
-
const db = await orm.openDb();
|
|
77
|
-
for (let i = 0; i < db.users.length; i++) {
|
|
78
|
-
if (db.users[i].id === id) {
|
|
79
|
-
db.users.splice(i, 1);
|
|
80
|
-
return orm.saveDb(db);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// **** Unit-Tests Only **** //
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Delete every user record.
|
|
89
|
-
*
|
|
90
|
-
* @internal
|
|
91
|
-
* Test-only helper. Do not use in production code.
|
|
92
|
-
*/
|
|
93
|
-
async function deleteAllUsers(): Promise<void> {
|
|
94
|
-
const db = await orm.openDb();
|
|
95
|
-
db.users = [];
|
|
96
|
-
return orm.saveDb(db);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Insert multiple users. Can't do multiple at once cause using a plain file
|
|
101
|
-
* for now.
|
|
102
|
-
*
|
|
103
|
-
* @internal
|
|
104
|
-
* Test-only helper. Do not use in production code.
|
|
105
|
-
*/
|
|
106
|
-
async function insertMultiple(
|
|
107
|
-
users: IUser[] | readonly IUser[],
|
|
108
|
-
): Promise<IUser[]> {
|
|
109
|
-
const db = await orm.openDb(),
|
|
110
|
-
usersF = [
|
|
111
|
-
for (const user of usersF) {
|
|
112
|
-
user.id = getRandomInt();
|
|
113
|
-
user.created = new Date();
|
|
114
|
-
}
|
|
115
|
-
db.users = [
|
|
116
|
-
await orm.saveDb(db);
|
|
117
|
-
return usersF;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/******************************************************************************
|
|
121
|
-
Export default
|
|
122
|
-
******************************************************************************/
|
|
123
|
-
|
|
124
|
-
export default {
|
|
125
|
-
getOne,
|
|
126
|
-
persists,
|
|
127
|
-
getAll,
|
|
128
|
-
add,
|
|
129
|
-
update,
|
|
130
|
-
delete: __delete__,
|
|
131
|
-
deleteAllUsers,
|
|
132
|
-
insertMultiple,
|
|
133
|
-
} as const;
|
|
1
|
+
import { getRandomInt } from '@src/common/utils/number-utils';
|
|
2
|
+
import { IUser } from '@src/models/User';
|
|
3
|
+
|
|
4
|
+
import orm from './MockOrm';
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Functions
|
|
8
|
+
******************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get one user.
|
|
12
|
+
*/
|
|
13
|
+
async function getOne(email: string): Promise<IUser | null> {
|
|
14
|
+
const db = await orm.openDb();
|
|
15
|
+
for (const user of db.users) {
|
|
16
|
+
if (user.email === email) {
|
|
17
|
+
return user;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* See if a user with the given id exists.
|
|
25
|
+
*/
|
|
26
|
+
async function persists(id: number): Promise<boolean> {
|
|
27
|
+
const db = await orm.openDb();
|
|
28
|
+
for (const user of db.users) {
|
|
29
|
+
if (user.id === id) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get all users.
|
|
38
|
+
*/
|
|
39
|
+
async function getAll(): Promise<IUser[]> {
|
|
40
|
+
const db = await orm.openDb();
|
|
41
|
+
return db.users;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Add one user.
|
|
46
|
+
*/
|
|
47
|
+
async function add(user: IUser): Promise<void> {
|
|
48
|
+
const db = await orm.openDb();
|
|
49
|
+
user.id = getRandomInt();
|
|
50
|
+
db.users.push(user);
|
|
51
|
+
return orm.saveDb(db);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Update a user.
|
|
56
|
+
*/
|
|
57
|
+
async function update(user: IUser): Promise<void> {
|
|
58
|
+
const db = await orm.openDb();
|
|
59
|
+
for (let i = 0; i < db.users.length; i++) {
|
|
60
|
+
if (db.users[i].id === user.id) {
|
|
61
|
+
const dbUser = db.users[i];
|
|
62
|
+
db.users[i] = {
|
|
63
|
+
...dbUser,
|
|
64
|
+
name: user.name,
|
|
65
|
+
email: user.email,
|
|
66
|
+
};
|
|
67
|
+
return orm.saveDb(db);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Delete one user.
|
|
74
|
+
*/
|
|
75
|
+
async function __delete__(id: number): Promise<void> {
|
|
76
|
+
const db = await orm.openDb();
|
|
77
|
+
for (let i = 0; i < db.users.length; i++) {
|
|
78
|
+
if (db.users[i].id === id) {
|
|
79
|
+
db.users.splice(i, 1);
|
|
80
|
+
return orm.saveDb(db);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// **** Unit-Tests Only **** //
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Delete every user record.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
* Test-only helper. Do not use in production code.
|
|
92
|
+
*/
|
|
93
|
+
async function deleteAllUsers(): Promise<void> {
|
|
94
|
+
const db = await orm.openDb();
|
|
95
|
+
db.users = [];
|
|
96
|
+
return orm.saveDb(db);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Insert multiple users. Can't do multiple at once cause using a plain file
|
|
101
|
+
* for now.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
* Test-only helper. Do not use in production code.
|
|
105
|
+
*/
|
|
106
|
+
async function insertMultiple(
|
|
107
|
+
users: IUser[] | readonly IUser[],
|
|
108
|
+
): Promise<IUser[]> {
|
|
109
|
+
const db = await orm.openDb(),
|
|
110
|
+
usersF = [...users];
|
|
111
|
+
for (const user of usersF) {
|
|
112
|
+
user.id = getRandomInt();
|
|
113
|
+
user.created = new Date();
|
|
114
|
+
}
|
|
115
|
+
db.users = [...db.users, ...users];
|
|
116
|
+
await orm.saveDb(db);
|
|
117
|
+
return usersF;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/******************************************************************************
|
|
121
|
+
Export default
|
|
122
|
+
******************************************************************************/
|
|
123
|
+
|
|
124
|
+
export default {
|
|
125
|
+
getOne,
|
|
126
|
+
persists,
|
|
127
|
+
getAll,
|
|
128
|
+
add,
|
|
129
|
+
update,
|
|
130
|
+
delete: __delete__,
|
|
131
|
+
deleteAllUsers,
|
|
132
|
+
insertMultiple,
|
|
133
|
+
} as const;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"users": [
|
|
3
|
+
{
|
|
4
|
+
"id": 547317739445,
|
|
5
|
+
"name": "Bill",
|
|
6
|
+
"email": "sean.maxwell@gmail.com",
|
|
7
|
+
"created": "2026-01-10T04:06:20.291Z"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": 332906029656,
|
|
11
|
+
"name": "John Smith",
|
|
12
|
+
"email": "john.smith@gmail.com",
|
|
13
|
+
"created": "2026-01-10T04:06:20.291Z"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": 421195709596,
|
|
17
|
+
"name": "Gordan Freeman",
|
|
18
|
+
"email": "gordan.freeman@gmail.com",
|
|
19
|
+
"created": "2026-01-10T04:06:20.291Z"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -1,69 +1,77 @@
|
|
|
1
|
-
import { isNumber } from 'jet-validators';
|
|
2
|
-
import { transform } from 'jet-validators/utils';
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import { IReq, IRes } from './common/types';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
/******************************************************************************
|
|
12
|
-
Constants
|
|
13
|
-
******************************************************************************/
|
|
14
|
-
|
|
15
|
-
const Validators = {
|
|
16
|
-
add: parseReq({ user: User.
|
|
17
|
-
update: parseReq({ user: User.
|
|
18
|
-
delete: parseReq({ id: transform(Number, isNumber) }),
|
|
19
|
-
} as const;
|
|
20
|
-
|
|
21
|
-
/******************************************************************************
|
|
22
|
-
Functions
|
|
23
|
-
******************************************************************************/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get all users.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
import { isNumber } from 'jet-validators';
|
|
2
|
+
import { transform } from 'jet-validators/utils';
|
|
3
|
+
|
|
4
|
+
import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
|
|
5
|
+
import User from '@src/models/User';
|
|
6
|
+
import UserService from '@src/services/UserService';
|
|
7
|
+
|
|
8
|
+
import { IReq, IRes } from './common/express-types';
|
|
9
|
+
import parseReq from './common/parseReq';
|
|
10
|
+
|
|
11
|
+
/******************************************************************************
|
|
12
|
+
Constants
|
|
13
|
+
******************************************************************************/
|
|
14
|
+
|
|
15
|
+
const Validators = {
|
|
16
|
+
add: parseReq({ user: User.isComplete }),
|
|
17
|
+
update: parseReq({ user: User.isComplete }),
|
|
18
|
+
delete: parseReq({ id: transform(Number, isNumber) }),
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
/******************************************************************************
|
|
22
|
+
Functions
|
|
23
|
+
******************************************************************************/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get all users.
|
|
27
|
+
*
|
|
28
|
+
* @route GET /api/users/all
|
|
29
|
+
*/
|
|
30
|
+
async function getAll(_: IReq, res: IRes) {
|
|
31
|
+
const users = await UserService.getAll();
|
|
32
|
+
res.status(HttpStatusCodes.OK).json({ users });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Add one user.
|
|
37
|
+
*
|
|
38
|
+
* @route POST /api/users/add
|
|
39
|
+
*/
|
|
40
|
+
async function add(req: IReq, res: IRes) {
|
|
41
|
+
const { user } = Validators.add(req.body);
|
|
42
|
+
await UserService.addOne(user);
|
|
43
|
+
res.status(HttpStatusCodes.CREATED).end();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Update one user.
|
|
48
|
+
*
|
|
49
|
+
* @route PUT /api/users/update
|
|
50
|
+
*/
|
|
51
|
+
async function update(req: IReq, res: IRes) {
|
|
52
|
+
const { user } = Validators.update(req.body);
|
|
53
|
+
await UserService.updateOne(user);
|
|
54
|
+
res.status(HttpStatusCodes.OK).end();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Delete one user.
|
|
59
|
+
*
|
|
60
|
+
* @route DELETE /api/users/delete/:id
|
|
61
|
+
*/
|
|
62
|
+
async function __delete__(req: IReq, res: IRes) {
|
|
63
|
+
const { id } = Validators.delete(req.params);
|
|
64
|
+
await UserService.delete(id);
|
|
65
|
+
res.status(HttpStatusCodes.OK).end();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/******************************************************************************
|
|
69
|
+
Export default
|
|
70
|
+
******************************************************************************/
|
|
71
|
+
|
|
72
|
+
export default {
|
|
73
|
+
getAll,
|
|
74
|
+
add,
|
|
75
|
+
update,
|
|
76
|
+
delete: __delete__,
|
|
77
|
+
} as const;
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
userRouter.
|
|
20
|
-
userRouter.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
******************************************************************************/
|
|
30
|
-
|
|
31
|
-
export default apiRouter;
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
|
|
3
|
+
import Paths from '@src/common/constants/Paths';
|
|
4
|
+
|
|
5
|
+
import UserRoutes from './UserRoutes';
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Setup
|
|
9
|
+
******************************************************************************/
|
|
10
|
+
|
|
11
|
+
const apiRouter = Router();
|
|
12
|
+
|
|
13
|
+
// ----------------------- Add UserRouter ---------------------------------- //
|
|
14
|
+
|
|
15
|
+
const userRouter = Router();
|
|
16
|
+
|
|
17
|
+
userRouter.get(Paths.Users.Get, UserRoutes.getAll);
|
|
18
|
+
userRouter.post(Paths.Users.Add, UserRoutes.add);
|
|
19
|
+
userRouter.put(Paths.Users.Update, UserRoutes.update);
|
|
20
|
+
userRouter.delete(Paths.Users.Delete, UserRoutes.delete);
|
|
21
|
+
|
|
22
|
+
apiRouter.use(Paths.Users._, userRouter);
|
|
23
|
+
|
|
24
|
+
/******************************************************************************
|
|
25
|
+
Export default
|
|
26
|
+
******************************************************************************/
|
|
27
|
+
|
|
28
|
+
export default apiRouter;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { PlainObject } from 'jet-validators';
|
|
3
|
+
|
|
4
|
+
/******************************************************************************
|
|
5
|
+
Types
|
|
6
|
+
******************************************************************************/
|
|
7
|
+
|
|
8
|
+
export type IReq = Request<PlainObject, void, PlainObject, PlainObject>;
|
|
9
|
+
export type IRes = Response<unknown, PlainObject>;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { parseObject, Schema } from 'jet-validators/utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* "ParseObjError"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
import { parseObject, Schema } from 'jet-validators/utils';
|
|
2
|
+
|
|
3
|
+
import { ValidationError } from '@src/common/utils/route-errors';
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Functions
|
|
7
|
+
******************************************************************************/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Throw a "ParseObjError" when "parseObject" fails. Also extract a nested
|
|
11
|
+
* "ParseObjError" and add it to the nestedErrors array.
|
|
12
|
+
*/
|
|
13
|
+
function parseReq<U extends Schema>(schema: U) {
|
|
14
|
+
return parseObject(schema, (errors) => {
|
|
15
|
+
throw new ValidationError(errors);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default parseReq;
|