|
| 1 | +/** |
| 2 | + * @module Controllers/Users |
| 3 | + */ |
1 | 4 | import { constants } from 'http2';
|
2 | 5 | import { UserServices } from '../services';
|
3 | 6 |
|
4 | 7 | /**
|
5 |
| - * Callback function for performing a CRUD. |
| 8 | + * Callback function for getting a user by id. |
| 9 | + * @function |
6 | 10 | * @param {import('express').Request} req - Express request object.
|
7 | 11 | * @param {import('express').Response} res - Express response object.
|
8 | 12 | * @param {import('express').NextFunction} next - Express next middleware function.
|
9 |
| - * @function getByID - Obtain the information of a user using an ID. |
10 |
| - * @function create - Create a new user. |
11 |
| - * @function update - RRefresh the information of a user using his ID. |
12 |
| - * @function delete - Delete the information of a user using his ID. |
13 | 13 | */
|
| 14 | +const getById = (req, res, next) => { |
| 15 | + try { |
| 16 | + const message = UserServices.getById(); |
| 17 | + res.status(constants.HTTP_STATUS_OK).json(message); |
| 18 | + } catch (err) { |
| 19 | + next(err); |
| 20 | + } |
| 21 | +}; |
| 22 | + |
| 23 | +/** |
| 24 | + * Callback function for create a user. |
| 25 | + * @function |
| 26 | + * @param {import('express').Request} req - Express request object. |
| 27 | + * @param {import('express').Response} res - Express response object. |
| 28 | + * @param {import('express').NextFunction} next - Express next middleware function. |
| 29 | + */ |
| 30 | +const create = async (req, res, next) => { |
| 31 | + try { |
| 32 | + const message = UserServices.create(); |
| 33 | + res.status(constants.HTTP_STATUS_OK).json(message); |
| 34 | + } catch (err) { |
| 35 | + next(err); |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + * Callback function for update a user. |
| 41 | + * @function |
| 42 | + * @param {import('express').Request} req - Express request object. |
| 43 | + * @param {import('express').Response} res - Express response object. |
| 44 | + * @param {import('express').NextFunction} next - Express next middleware function. |
| 45 | + */ |
| 46 | +const update = async (req, res, next) => { |
| 47 | + try { |
| 48 | + const message = UserServices.update(); |
| 49 | + res.status(constants.HTTP_STATUS_OK).json(message); |
| 50 | + } catch (err) { |
| 51 | + next(err); |
| 52 | + } |
| 53 | +}; |
| 54 | + |
| 55 | +/** |
| 56 | + * Callback function for delete a user. |
| 57 | + * @function |
| 58 | + * @param {import('express').Request} req - Express request object. |
| 59 | + * @param {import('express').Response} res - Express response object. |
| 60 | + * @param {import('express').NextFunction} next - Express next middleware function. |
| 61 | + */ |
| 62 | +const drop = async (req, res, next) => { |
| 63 | + try { |
| 64 | + const message = UserServices.deleteByID(); |
| 65 | + res.status(constants.HTTP_STATUS_OK).json(message); |
| 66 | + } catch (err) { |
| 67 | + next(err); |
| 68 | + } |
| 69 | +}; |
| 70 | + |
14 | 71 | export const UsersController = {
|
15 |
| - getById: (req, res, next) => { |
16 |
| - try { |
17 |
| - const message = UserServices.getById(); |
18 |
| - res.status(constants.HTTP_STATUS_OK).json(message); |
19 |
| - } catch (err) { |
20 |
| - next(err); |
21 |
| - } |
22 |
| - }, |
23 |
| - create: async (req, res, next) => { |
24 |
| - try { |
25 |
| - const message = UserServices.create(); |
26 |
| - res.status(constants.HTTP_STATUS_OK).json(message); |
27 |
| - } catch (err) { |
28 |
| - next(err); |
29 |
| - } |
30 |
| - }, |
31 |
| - update: async (req, res, next) => { |
32 |
| - try { |
33 |
| - const message = UserServices.update(); |
34 |
| - res.status(constants.HTTP_STATUS_OK).json(message); |
35 |
| - } catch (err) { |
36 |
| - next(err); |
37 |
| - } |
38 |
| - }, |
39 |
| - delete: async (req, res, next) => { |
40 |
| - try { |
41 |
| - const message = UserServices.deleteByID(); |
42 |
| - res.status(constants.HTTP_STATUS_OK).json(message); |
43 |
| - } catch (err) { |
44 |
| - next(err); |
45 |
| - } |
46 |
| - }, |
| 72 | + getById, |
| 73 | + create, |
| 74 | + update, |
| 75 | + delete: drop, |
47 | 76 | };
|
0 commit comments