Skip to content

Commit 33eb440

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

26 files changed

Lines changed: 1640 additions & 308 deletions

‎.eslintrc.json‎

Lines changed: 10 additions & 2 deletions
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‎

Lines changed: 3 additions & 1 deletion
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‎

Lines changed: 15 additions & 2 deletions
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‎

Lines changed: 12 additions & 21 deletions
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‎

Lines changed: 9 additions & 2 deletions
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
};
Lines changed: 7 additions & 4 deletions
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‎

Lines changed: 7 additions & 2 deletions
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‎

Lines changed: 7 additions & 2 deletions
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();
Lines changed: 20 additions & 14 deletions
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‎

Lines changed: 6 additions & 1 deletion
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.

0 commit comments

Comments
 (0)