Skip to content

Commit 33eb440

Browse files
feat: format the inline documentation (#9)
1 parent fe057f7 commit 33eb440

26 files changed

+1640
-308
lines changed

.eslintrc.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"extends": [
88
"airbnb-base",
99
"prettier",
10-
"plugin:prettier/recommended"
10+
"plugin:prettier/recommended",
11+
"plugin:jsdoc/recommended"
1112
],
1213
"ignorePatterns": [
1314
"/dist"
@@ -18,9 +19,11 @@
1819
},
1920
"plugins": [
2021
"prettier",
21-
"jest"
22+
"jest",
23+
"jsdoc"
2224
],
2325
"rules": {
26+
"valid-jsdoc": "off",
2427
"prettier/prettier": "error",
2528
"no-console": "warn",
2629
"arrow-body-style": [
@@ -66,5 +69,10 @@
6669
"devDependencies": true
6770
}
6871
]
72+
},
73+
"settings": {
74+
"jsdoc": {
75+
"mode": "typescript"
76+
}
6977
}
7078
}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules/
22
coverage/
33
dist/
44
.vscode/
5-
.env
5+
.env
6+
out/
7+
docs/

app/index.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import App from './server';
22

3-
const PORT = 3001;
3+
/**
4+
* The port on which the server will listen.
5+
* @type {number}
6+
*/
7+
const { PORT } = process.env;
8+
9+
/**
10+
* Start the server and listen on the specified port.
11+
* @function
12+
* @name startServer
13+
* @param {number} port - The port number on which the server will listen.
14+
* @param {Function} callback - A callback function to be executed once the server is listening.
15+
* @returns {void}
16+
*/
417
App.listen(PORT, () => {
5-
console.log(`App listen at http://localhost:${PORT}`);
18+
console.log(`App listen at http://localhost:${process.env.PORT}`);
619
});

app/internal/adapters/auth/jwt.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
1+
/**
2+
* @module Auth/JWT
3+
*/
4+
15
import jsonwebtoken from 'jsonwebtoken';
26

37
/**
48
* Generates a JSON Web Token (JWT) for the specified admin ID and expiration time.
5-
*
69
* @function
7-
* @memberof JWT
8-
* @param {string} adminID - The ID of the admin for whom the token is generated.
10+
* @param {string} adminID - The ID for whom the token is generated.
911
* @param {string | number} expiresIn - The expiration time for the token (e.g., '2h', '7d', or a timestamp).
10-
* @param {string} secretKey - Security secretKey.
11-
* @returns {string} The generated JWT.
12+
* @param {string} secretKey - The secret key used to sign the JWT token.
13+
* @returns {string} The generated JWT token.
1214
*/
1315
const generateToken = (adminID, expiresIn, secretKey) =>
1416
jsonwebtoken.sign({ id: adminID }, secretKey, {
1517
expiresIn,
1618
});
1719

1820
/**
19-
* Verifies the authenticity of a JSON Web Token (JWT).
20-
*
21+
* Verifies the authenticity of a JWT token.
2122
* @function
22-
* @memberof JWT
23-
* @param {string} token - The JWT to be verified.
24-
* @param {string} secretKey - The JWT secretKey used to be verify.
25-
* @returns {object} The decoded payload of the verified JWT.
26-
* @throws {Error} If the token verification fails.
23+
* @param {string} token - The JWT token to be verified.
24+
* @param {string} secretKey - The secret key used to verify the JWT token.
25+
* @returns {string} The decoded payload of the verified JWT.
26+
* @throws {Error} If the token is invalid or has expired.
2727
*/
2828
const verifyToken = (token, secretKey) => jsonwebtoken.verify(token, secretKey);
2929

30-
/**
31-
* JSON Web Token (JWT) utility functions for token generation and verification.
32-
*
33-
* @namespace
34-
* @typedef {Object} JWT
35-
* @property {function} generateToken - Function to generate a JWT.
36-
* @property {function} verifyToken - Function to verify the authenticity of a JWT.
37-
*/
38-
3930
export const JWT = {
4031
generateToken,
4132
verifyToken,

app/internal/adapters/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import { MainRoute, UsersRoute, AuthRoute } from './routes';
1+
import { JWT } from './auth';
2+
import { AuthRoute, MainRoute, UsersRoute } from './routes';
23

4+
/**
5+
* Adapters module containing various adapters.
6+
* @property {object} Auth - Authentication adapter.
7+
* @property {object} Routes - Routes adapter.
8+
*/
39
export const Adapters = {
4-
Routes: { MainRoute, UsersRoute, AuthRoute },
10+
Auth: { JWT },
11+
Routes: { MainRoute, AuthRoute, UsersRoute },
512
};
+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
/**
2+
* @module Routes/Auth
3+
*/
4+
15
import express from 'express';
26
import { AuthController } from '../../core/controllers';
37

48
/**
5-
* Create a new instance of UserRoutes.
6-
* @param {express.Application} app - The Express application instance.
9+
* Set up routes related to authentication.
10+
* @function AuthRoute
11+
* @param {express.Application} app - The Express application.
712
*/
813
export const AuthRoute = (app) => {
914
const router = express.Router();
1015
app.use('/auth', router);
11-
12-
// Get Token
1316
router.get('/token', AuthController.getToken);
1417
};

app/internal/adapters/routes/main.routes.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
/**
2+
* @module Routes/Main
3+
*/
4+
15
import express from 'express';
26
import { MainController } from '../../core/controllers';
37

48
/**
5-
* Create a new instance of MainRoutes.
6-
* @param {express.Application} app - The Express application instance.
9+
* Set up main routes.
10+
* @function MainRoute
11+
* @param {express.Application} app - The Express application.
712
*/
813
export const MainRoute = (app) => {
914
const router = express.Router();

app/internal/adapters/routes/users.routes.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
/**
2+
* @module Routes/Users
3+
*/
4+
15
import express from 'express';
26
import { UsersController } from '../../core/controllers';
37

48
/**
5-
* Create a new instance of UserRoutes.
6-
* @param {express.Application} app - The Express application instance.
9+
* Set up routes related to Users CRUD operations
10+
* @function UsersRoute
11+
* @param {express.Application} app - The Express application.
712
*/
813
export const UsersRoute = (app) => {
914
const router = express.Router();
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1+
/**
2+
* @module Controllers/Auth
3+
*/
4+
15
import { constants } from 'http2';
26
import { AuthServices } from '../services';
37

48
/**
5-
* Callback function for performing a CRUD.
9+
* Callback function getting a token.
10+
* @function
611
* @param {import('express').Request} req - Express request object.
712
* @param {import('express').Response} res - Express response object.
813
* @param {import('express').NextFunction} next - Express next middleware function.
9-
* @function getToken - Obtain the JWT token.
1014
*/
15+
const getToken = (req, res, next) => {
16+
try {
17+
const token = AuthServices.getToken(
18+
req.body.adminId,
19+
req.config.auth.expiresIn,
20+
req.config.auth.securityKey,
21+
);
22+
res.status(constants.HTTP_STATUS_OK).json(token);
23+
} catch (err) {
24+
next(err);
25+
}
26+
};
27+
1128
export const AuthController = {
12-
getToken: (req, res, next) => {
13-
try {
14-
const token = AuthServices.getToken(
15-
req.body.adminId,
16-
req.config.auth.expiresIn,
17-
req.config.auth.securityKey,
18-
);
19-
res.status(constants.HTTP_STATUS_OK).json(token);
20-
} catch (err) {
21-
next(err);
22-
}
23-
},
29+
getToken,
2430
};

app/internal/core/controllers/main.controller.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/**
2+
* @module Controllers/Main
3+
*/
4+
15
import { constants } from 'http2';
26
import { MainServices } from '../services';
37

48
/**
5-
* Callback function for performing a health check.
9+
* Callback function the health check.
10+
* @function
611
* @param {import('express').Request} req - Express request object.
712
* @param {import('express').Response} res - Express response object.
813
* @param {import('express').NextFunction} next - Express next middleware function.
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,76 @@
1+
/**
2+
* @module Controllers/Users
3+
*/
14
import { constants } from 'http2';
25
import { UserServices } from '../services';
36

47
/**
5-
* Callback function for performing a CRUD.
8+
* Callback function for getting a user by id.
9+
* @function
610
* @param {import('express').Request} req - Express request object.
711
* @param {import('express').Response} res - Express response object.
812
* @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.
1313
*/
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+
1471
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,
4776
};

app/internal/core/domain/models/responses.models.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
/**
2+
* Auth middlewares
3+
* @module Models/Responses
4+
*/
5+
16
/**
27
* Represents a simple response object.
3-
* @typedef {Object} SimpleResponse
8+
* @typedef {object} SimpleResponse
49
* @property {string} message - The message associated with the response.
510
*/
611

@@ -15,7 +20,7 @@ const simple = (message) => ({
1520

1621
/**
1722
* Represents a token response object.
18-
* @typedef {Object} TokenResponse
23+
* @typedef {object} TokenResponse
1924
* @property {string} access_token - The token created.
2025
* @property {string} expires_in - The expiration time of the toke.
2126
* @property {string} tokenType - The token type for the request, by default is Bearer.
@@ -24,10 +29,9 @@ const simple = (message) => ({
2429
/**
2530
* Creates a token response object.
2631
* @param {string} token - The token created with the expiration time.
27-
* @property {string} expiresIn - The expiration time of the token.
32+
* @param {string} expiresIn - The expiration time of the token.
2833
* @returns {TokenResponse} The token response with the information about the token created.
2934
*/
30-
3135
const tokenResponse = (token, expiresIn) => ({
3236
access_token: token,
3337
expiresIn,

0 commit comments

Comments
 (0)