Skip to content

Commit 371a224

Browse files
committed
feat(templates): update http-status-codes import
1 parent 0f6a1f9 commit 371a224

File tree

1 file changed

+10
-14
lines changed
  • generators/app/templates/<%= elementCompNamePlural %>

1 file changed

+10
-14
lines changed

generators/app/templates/<%= elementCompNamePlural %>/controller.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { Request, Response, NextFunction } from 'express';
2-
import {
3-
BAD_REQUEST,
4-
NOT_FOUND,
5-
INTERNAL_SERVER_ERROR,
6-
} from 'http-status-codes';
2+
import { StatusCodes } from 'http-status-codes';
73
import { HttpError } from '@boringcodes/utils/error';
84

95
import { ENTITY } from './constants';
@@ -19,7 +15,7 @@ const list = async (_: Request, res: Response, next: NextFunction) => {
1915

2016
res.send(objects);
2117
} catch (err) {
22-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
18+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
2319
}
2420
};
2521

@@ -30,26 +26,26 @@ const create = async (req: Request, res: Response, next: NextFunction) => {
3026

3127
res.send(object);
3228
} catch (err) {
33-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
29+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
3430
}
3531
};
3632

3733
const getById = async (req: Request, _: Response, next: NextFunction) => {
3834
try {
3935
if (!req.params.id) {
40-
throw new HttpError(BAD_REQUEST, 'Invalid resource Id');
36+
throw new HttpError(StatusCodes.BAD_REQUEST, 'Invalid resource Id');
4137
}
4238

4339
// TODO: get object by id
4440
const object = {};
4541
if (!object) {
46-
return next(new HttpError(NOT_FOUND, 'Resource not found'));
42+
return next(new HttpError(StatusCodes.NOT_FOUND, 'Resource not found'));
4743
}
4844
Object.assign(req, { [ENTITY]: object });
4945

5046
next();
5147
} catch (err) {
52-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
48+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
5349
}
5450
};
5551

@@ -58,7 +54,7 @@ const get = (req: Request, res: Response, next: NextFunction) => {
5854
// TODO: get object
5955
res.send((req as MyRequest)[ENTITY]);
6056
} catch (err) {
61-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
57+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
6258
}
6359
};
6460

@@ -73,7 +69,7 @@ const updatePartial = async (
7369

7470
res.send(object);
7571
} catch (err) {
76-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
72+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
7773
}
7874
};
7975

@@ -84,7 +80,7 @@ const update = async (req: Request, res: Response, next: NextFunction) => {
8480

8581
res.send(object);
8682
} catch (err) {
87-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
83+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
8884
}
8985
};
9086

@@ -95,7 +91,7 @@ const del = async (req: Request, res: Response, next: NextFunction) => {
9591

9692
res.send(object);
9793
} catch (err) {
98-
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
94+
next(new HttpError(err.code || StatusCodes.INTERNAL_SERVER_ERROR, err));
9995
}
10096
};
10197

0 commit comments

Comments
 (0)