express-generator-typescript 2.7.3 → 2.7.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.
@@ -1,7 +1,7 @@
1
1
  import { isNumber } from 'jet-validators';
2
2
  import { transform } from 'jet-validators/utils';
3
3
 
4
- import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
4
+ import HTTP_STATUS_CODES from '@src/common/constants/HTTP_STATUS_CODES';
5
5
  import UserService from '@src/services/UserService';
6
6
  import User from '@src/models/User';
7
7
 
@@ -29,7 +29,7 @@ const Validators = {
29
29
  */
30
30
  async function getAll(_: IReq, res: IRes) {
31
31
  const users = await UserService.getAll();
32
- res.status(HttpStatusCodes.OK).json({ users });
32
+ res.status(HTTP_STATUS_CODES.Ok).json({ users });
33
33
  }
34
34
 
35
35
  /**
@@ -38,7 +38,7 @@ async function getAll(_: IReq, res: IRes) {
38
38
  async function add(req: IReq, res: IRes) {
39
39
  const { user } = Validators.add(req.body);
40
40
  await UserService.addOne(user);
41
- res.status(HttpStatusCodes.CREATED).end();
41
+ res.status(HTTP_STATUS_CODES.Created).end();
42
42
  }
43
43
 
44
44
  /**
@@ -47,7 +47,7 @@ async function add(req: IReq, res: IRes) {
47
47
  async function update(req: IReq, res: IRes) {
48
48
  const { user } = Validators.update(req.body);
49
49
  await UserService.updateOne(user);
50
- res.status(HttpStatusCodes.OK).end();
50
+ res.status(HTTP_STATUS_CODES.Ok).end();
51
51
  }
52
52
 
53
53
  /**
@@ -56,7 +56,7 @@ async function update(req: IReq, res: IRes) {
56
56
  async function delete_(req: IReq, res: IRes) {
57
57
  const { id } = Validators.delete(req.params);
58
58
  await UserService.delete(id);
59
- res.status(HttpStatusCodes.OK).end();
59
+ res.status(HTTP_STATUS_CODES.Ok).end();
60
60
  }
61
61
 
62
62
 
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express';
2
2
 
3
- import Paths from '@src/common/constants/Paths';
3
+ import PATHS from '@src/common/constants/PATHS';
4
4
  import UserRoutes from './UserRoutes';
5
5
 
6
6
 
@@ -17,13 +17,13 @@ const apiRouter = Router();
17
17
  const userRouter = Router();
18
18
 
19
19
  // Get all users
20
- userRouter.get(Paths.Users.Get, UserRoutes.getAll);
21
- userRouter.post(Paths.Users.Add, UserRoutes.add);
22
- userRouter.put(Paths.Users.Update, UserRoutes.update);
23
- userRouter.delete(Paths.Users.Delete, UserRoutes.delete);
20
+ userRouter.get(PATHS.Users.Get, UserRoutes.getAll);
21
+ userRouter.post(PATHS.Users.Add, UserRoutes.add);
22
+ userRouter.put(PATHS.Users.Update, UserRoutes.update);
23
+ userRouter.delete(PATHS.Users.Delete, UserRoutes.delete);
24
24
 
25
25
  // Add UserRouter
26
- apiRouter.use(Paths.Users.Base, userRouter);
26
+ apiRouter.use(PATHS.Users.Base, userRouter);
27
27
 
28
28
 
29
29
  /******************************************************************************
@@ -6,11 +6,13 @@ import logger from 'jet-logger';
6
6
 
7
7
  import BaseRouter from '@src/routes';
8
8
 
9
- import Paths from '@src/common/constants/Paths';
9
+ import Paths from '@src/common/constants/PATHS';
10
10
  import ENV from '@src/common/constants/ENV';
11
- import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
11
+ import HTTP_STATUS_CODES, {
12
+ HttpStatusCodes,
13
+ } from '@src/common/constants/HTTP_STATUS_CODES';
12
14
  import { RouteError } from '@src/common/util/route-errors';
13
- import { NodeEnvs } from '@src/common/constants';
15
+ import { NODE_ENVS } from '@src/common/constants';
14
16
 
15
17
 
16
18
  /******************************************************************************
@@ -27,12 +29,12 @@ app.use(express.json());
27
29
  app.use(express.urlencoded({extended: true}));
28
30
 
29
31
  // Show routes called in console during development
30
- if (ENV.NodeEnv === NodeEnvs.Dev) {
32
+ if (ENV.NodeEnv === NODE_ENVS.Dev) {
31
33
  app.use(morgan('dev'));
32
34
  }
33
35
 
34
36
  // Security
35
- if (ENV.NodeEnv === NodeEnvs.Production) {
37
+ if (ENV.NodeEnv === NODE_ENVS.Production) {
36
38
  // eslint-disable-next-line n/no-process-env
37
39
  if (!process.env.DISABLE_HELMET) {
38
40
  app.use(helmet());
@@ -44,10 +46,10 @@ app.use(Paths.Base, BaseRouter);
44
46
 
45
47
  // Add error handler
46
48
  app.use((err: Error, _: Request, res: Response, next: NextFunction) => {
47
- if (ENV.NodeEnv !== NodeEnvs.Test.valueOf()) {
49
+ if (ENV.NodeEnv !== NODE_ENVS.Test.valueOf()) {
48
50
  logger.err(err, true);
49
51
  }
50
- let status = HttpStatusCodes.BAD_REQUEST;
52
+ let status: HttpStatusCodes = HTTP_STATUS_CODES.BadRequest;
51
53
  if (err instanceof RouteError) {
52
54
  status = err.status;
53
55
  res.status(status).json({ error: err.message });
@@ -1,5 +1,5 @@
1
1
  import { RouteError } from '@src/common/util/route-errors';
2
- import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
2
+ import HTTP_STATUS_CODES from '@src/common/constants/HTTP_STATUS_CODES';
3
3
 
4
4
  import UserRepo from '@src/repos/UserRepo';
5
5
  import { IUser } from '@src/models/User';
@@ -37,7 +37,7 @@ async function updateOne(user: IUser): Promise<void> {
37
37
  const persists = await UserRepo.persists(user.id);
38
38
  if (!persists) {
39
39
  throw new RouteError(
40
- HttpStatusCodes.NOT_FOUND,
40
+ HTTP_STATUS_CODES.NotFound,
41
41
  USER_NOT_FOUND_ERR,
42
42
  );
43
43
  }
@@ -52,7 +52,7 @@ async function _delete(id: number): Promise<void> {
52
52
  const persists = await UserRepo.persists(id);
53
53
  if (!persists) {
54
54
  throw new RouteError(
55
- HttpStatusCodes.NOT_FOUND,
55
+ HTTP_STATUS_CODES.NotFound,
56
56
  USER_NOT_FOUND_ERR,
57
57
  );
58
58
  }
@@ -1,5 +1,5 @@
1
1
  import jetPaths from 'jet-paths';
2
- import Paths from '@src/common/constants/Paths';
2
+ import Paths from '@src/common/constants/PATHS';
3
3
 
4
4
 
5
5
  export default jetPaths(Paths);
@@ -5,7 +5,7 @@ import UserRepo from '@src/repos/UserRepo';
5
5
  import User, { IUser } from '@src/models/User';
6
6
  import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
7
7
 
8
- import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
8
+ import HTTP_STATUS_CODES from '@src/common/constants/HTTP_STATUS_CODES';
9
9
  import { ValidationError } from '@src/common/util/route-errors';
10
10
 
11
11
  import Paths from './common/Paths';
@@ -53,9 +53,9 @@ describe('UserRouter', () => {
53
53
 
54
54
  // Success
55
55
  it('should return a JSON object with all the users and a status code ' +
56
- `of "${HttpStatusCodes.OK}" if the request was successful.`, async () => {
56
+ `of "${HTTP_STATUS_CODES.Ok}" if the request was successful.`, async () => {
57
57
  const res: TRes<{ users: IUser[]}> = await agent.get(Paths.Users.Get);
58
- expect(res.status).toBe(HttpStatusCodes.OK);
58
+ expect(res.status).toBe(HTTP_STATUS_CODES.Ok);
59
59
  expect(compareUserArrays(res.body.users, DB_USERS)).toBeTruthy();
60
60
  });
61
61
  });
@@ -64,19 +64,19 @@ describe('UserRouter', () => {
64
64
  describe(`"POST:${Paths.Users.Add}"`, () => {
65
65
 
66
66
  // Test add user success
67
- it(`should return a status code of "${HttpStatusCodes.CREATED}" if the ` +
68
- 'request was successful.', async () => {
67
+ it(`should return a status code of "${HTTP_STATUS_CODES.Created}" if ` +
68
+ 'the request was successful.', async () => {
69
69
  const user = User.new({ name: 'a', email: 'a@a.com' }),
70
70
  res = await agent.post(Paths.Users.Add).send({ user });
71
- expect(res.status).toBe(HttpStatusCodes.CREATED);
71
+ expect(res.status).toBe(HTTP_STATUS_CODES.Created);
72
72
  });
73
73
 
74
74
  // Missing param
75
75
  it('should return a JSON object with an error message of and a status ' +
76
- `code of "${HttpStatusCodes.BAD_REQUEST}" if the user param was ` +
76
+ `code of "${HTTP_STATUS_CODES.BadRequest}" if the user param was ` +
77
77
  'missing.', async () => {
78
78
  const res: TRes = await agent.post(Paths.Users.Add).send({ user: null });
79
- expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
79
+ expect(res.status).toBe(HTTP_STATUS_CODES.BadRequest);
80
80
  const errorObj = parseValidationErr(res.body.error);
81
81
  expect(errorObj.message).toBe(ValidationError.MESSAGE);
82
82
  expect(errorObj.errors[0].prop).toBe('user');
@@ -87,22 +87,22 @@ describe('UserRouter', () => {
87
87
  describe(`"PUT:${Paths.Users.Update}"`, () => {
88
88
 
89
89
  // Success
90
- it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
90
+ it(`should return a status code of "${HTTP_STATUS_CODES.Ok}" if the ` +
91
91
  'request was successful.', async () => {
92
92
  const user = DB_USERS[0];
93
93
  user.name = 'Bill';
94
94
  const res = await agent.put(Paths.Users.Update).send({ user });
95
- expect(res.status).toBe(HttpStatusCodes.OK);
95
+ expect(res.status).toBe(HTTP_STATUS_CODES.Ok);
96
96
  });
97
97
 
98
98
  // Id is the wrong data type
99
99
  it('should return a JSON object with an error message and a status code ' +
100
- `of "${HttpStatusCodes.BAD_REQUEST}" if the user param was missing`,
100
+ `of "${HTTP_STATUS_CODES.BadRequest}" if the user param was missing`,
101
101
  async () => {
102
102
  const user = User.new();
103
103
  user.id = ('5' as unknown as number);
104
104
  const res: TRes = await agent.put(Paths.Users.Update).send({ user });
105
- expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
105
+ expect(res.status).toBe(HTTP_STATUS_CODES.BadRequest);
106
106
  const errorObj = parseValidationErr(res.body.error);
107
107
  expect(errorObj.message).toBe(ValidationError.MESSAGE);
108
108
  expect(errorObj.errors[0].prop).toBe('user');
@@ -112,10 +112,10 @@ describe('UserRouter', () => {
112
112
  // User not found
113
113
  it('should return a JSON object with the error message of ' +
114
114
  `"${USER_NOT_FOUND_ERR}" and a status code of ` +
115
- `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, async () => {
115
+ `"${HTTP_STATUS_CODES.NotFound}" if the id was not found.`, async () => {
116
116
  const user = User.new({ id: 4, name: 'a', email: 'a@a.com' }),
117
117
  res: TRes = await agent.put(Paths.Users.Update).send({ user });
118
- expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
118
+ expect(res.status).toBe(HTTP_STATUS_CODES.NotFound);
119
119
  expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
120
120
  });
121
121
  });
@@ -127,19 +127,19 @@ describe('UserRouter', () => {
127
127
  { id });
128
128
 
129
129
  // Success
130
- it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
130
+ it(`should return a status code of "${HTTP_STATUS_CODES.Ok}" if the ` +
131
131
  'request was successful.', async () => {
132
132
  const id = dbUsers[0].id,
133
133
  res = await agent.delete(getPath(id));
134
- expect(res.status).toBe(HttpStatusCodes.OK);
134
+ expect(res.status).toBe(HTTP_STATUS_CODES.Ok);
135
135
  });
136
136
 
137
137
  // User not found
138
138
  it('should return a JSON object with the error message of ' +
139
139
  `"${USER_NOT_FOUND_ERR}" and a status code of ` +
140
- `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, async () => {
140
+ `"${HTTP_STATUS_CODES.NotFound}" if the id was not found.`, async () => {
141
141
  const res: TRes = await agent.delete(getPath(-1));
142
- expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
142
+ expect(res.status).toBe(HTTP_STATUS_CODES.NotFound);
143
143
  expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
144
144
  });
145
145
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.7.3",
3
+ "version": "2.7.5",
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",
package/README-npm DELETED
@@ -1,20 +0,0 @@
1
- <img alt='overnightjs' src='https://github.com/seanpmaxwell/express-generator-typescript/raw/master/express-typescript.png' border='0'>
2
-
3
- [Express](https://www.npmjs.com/package/express) with [TypeScript's](https://www.npmjs.com/package/typescript) application generator.
4
-
5
- <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/v/express-generator-typescript.svg" alt="NPM Version" /></a>
6
- <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/l/express-generator-typescript.svg" alt="Package License" /></a>
7
- <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/dm/express-generator-typescript.svg" alt="NPM Downloads" /></a>
8
-
9
-
10
- ## What is it?
11
-
12
- Creates a new express application similar to the _express-generator_ module. Except this new application is configured to use TypeScript instead of plain JavaScript.
13
-
14
- This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
15
- <br/>
16
-
17
-
18
- ## Documenation
19
-
20
- Please refer to the official <a href="https://github.com/seanpmaxwell/express-generator-typescript">github repo</a> for the most up-to-date documentation.