express-generator-typescript 2.3.2 → 2.3.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.
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
Creates a new express application similar to the _express-generator_ module. Except this new
|
|
13
13
|
application is configured to use TypeScript instead of plain JavaScript.
|
|
14
14
|
|
|
15
|
+
This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
## Why express-generator-typescript?
|
|
17
19
|
|
|
@@ -50,7 +50,7 @@ describe('AuthRouter', () => {
|
|
|
50
50
|
// ** Test login ** //
|
|
51
51
|
describe(`"POST:${Login}"`, () => {
|
|
52
52
|
|
|
53
|
-
const EMAIL_NOT_FOUND_ERR = Errors.
|
|
53
|
+
const EMAIL_NOT_FOUND_ERR = Errors.EmailNotFound(LoginCreds.email);
|
|
54
54
|
|
|
55
55
|
const callApi = (reqBody: TReqBody) =>
|
|
56
56
|
agent
|
|
@@ -13,7 +13,9 @@ import { IUser } from '@src/models/User';
|
|
|
13
13
|
// Errors
|
|
14
14
|
export const Errors = {
|
|
15
15
|
Unauth: 'Unauthorized',
|
|
16
|
-
|
|
16
|
+
EmailNotFound(email: string) {
|
|
17
|
+
return `User with email "${email}" not found`;
|
|
18
|
+
},
|
|
17
19
|
} as const;
|
|
18
20
|
|
|
19
21
|
|
|
@@ -28,7 +30,7 @@ async function login(email: string, password: string): Promise<IUser> {
|
|
|
28
30
|
if (!user) {
|
|
29
31
|
throw new RouteError(
|
|
30
32
|
HttpStatusCodes.UNAUTHORIZED,
|
|
31
|
-
Errors.
|
|
33
|
+
Errors.EmailNotFound(email),
|
|
32
34
|
);
|
|
33
35
|
}
|
|
34
36
|
// Check password
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"express-generator-typescript": "node bin/cli.js",
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
2
|
-
|
|
3
|
-
import userService from '@src/services/user-service';
|
|
4
|
-
import { IUser } from '@src/models/User';
|
|
5
|
-
import { IReq, IRes } from './shared/types';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// **** Variables **** //
|
|
9
|
-
|
|
10
|
-
// Paths
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// **** Functions **** //
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Get all users.
|
|
18
|
-
*/
|
|
19
|
-
async function getAll(_: IReq, res: IRes) {
|
|
20
|
-
const users = await userService.getAll();
|
|
21
|
-
return res.status(HttpStatusCodes.OK).json({ users });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Add one user.
|
|
26
|
-
*/
|
|
27
|
-
async function add(req: IReq<{user: IUser}>, res: IRes) {
|
|
28
|
-
const { user } = req.body;
|
|
29
|
-
await userService.addOne(user);
|
|
30
|
-
return res.status(HttpStatusCodes.CREATED).end();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Update one user.
|
|
35
|
-
*/
|
|
36
|
-
async function update(req: IReq<{user: IUser}>, res: IRes) {
|
|
37
|
-
const { user } = req.body;
|
|
38
|
-
await userService.updateOne(user);
|
|
39
|
-
return res.status(HttpStatusCodes.OK).end();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Delete one user.
|
|
44
|
-
*/
|
|
45
|
-
async function _delete(req: IReq, res: IRes) {
|
|
46
|
-
const id = +req.params.id;
|
|
47
|
-
await userService.delete(id);
|
|
48
|
-
return res.status(HttpStatusCodes.OK).end();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// **** Export default **** //
|
|
53
|
-
|
|
54
|
-
export default {
|
|
55
|
-
paths,
|
|
56
|
-
getAll,
|
|
57
|
-
add,
|
|
58
|
-
update,
|
|
59
|
-
delete: _delete,
|
|
60
|
-
} as const;
|