Compare commits

...

5 Commits

Author SHA1 Message Date
915b205b6e
chore(others): add mariadb to .gitignore
The .gitignore file was updated to ignore the `mariadb` file, preventing it from being tracked by version control. This ensures database related elements are ignored for smoother version control operations.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 09:54:20 +02:00
4ff1aa852d
feat(app): add handling for app port from environment variable
This commit imports the `process` module from `node:process` and changes the app to listen on a port specified by an environment variable (APP_PORT). It also adds an error handler to stop the server and log the error message if the server fails to start.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 09:54:04 +02:00
c024770b4a
feat(services): handle MySQL connection errors with process exit
Updated `mysql.service.ts` to handle MySQL connection errors by terminating the process instead of throwing a generic error. This change provides a more direct response to database connection failures.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 09:53:18 +02:00
37ec62405e
feat(routes): update catalog routes with ModelController methods
A ModelController has been imported and its methods applied to the catalogue routes in the system. The changes include methods for creating, getting all, getting by slug, updating, and deleting models. Prior routes have been updated and enhanced with these additional controller methods for improved performance.

Issue: #28
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 09:52:43 +02:00
57151ec777
feat(controllers): add new TODO in model.controller
- The code update adds a new `TODO` comment in the `model.controller.ts` file.
- The new `TODO` is about getting a model with available vehicles.

Issue: #28
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 09:51:59 +02:00
5 changed files with 19 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules
pnpm-lock.yaml
.env
dist
mariadb

View File

@ -6,6 +6,7 @@ import helmet from "helmet";
import AuthRouter from "@routes/auth/authRouter";
import CatalogRouter from "@routes/catalog/catalogRouter";
import RentRouter from "@routes/rent/rentRouter";
import * as process from "node:process";
const logger = new Logger({ name: "App" });
@ -43,5 +44,10 @@ try {
throw null;
}
//app.listen(3333)
logger.info('Server is running !')
try {
app.listen(process.env["APP_PORT"])
logger.info('Server is running !')
} catch (error) {
logger.error(`Server failed to start: ${error}`);
process.exit(1);
}

View File

@ -103,6 +103,7 @@ async function deleteModel(req: Request, res: Response): Promise<Response> {
//TODO get all vehicles of an model by slug
//TODO get model with vehicle available.
const ModelController = {
create: createModel,

View File

@ -2,20 +2,21 @@ import express, {type Router} from "express";
import AdminGuard from "@validators/AdminGuard";
import UserGuard from "@validators/UserGuard";
import CategoryController from "@controllers/category.controller";
import ModelController from "@controllers/model.controller";
const CatalogRouter: Router = express.Router();
//-- MODELS >>
CatalogRouter.route('/model/new').get(AdminGuard)
CatalogRouter.route('/model/new').get(AdminGuard, ModelController.create)
CatalogRouter.route('/model/all').get()
CatalogRouter.route('/model/all').get(ModelController.getAll)
CatalogRouter.route('/model/:modelSlug')
.get(UserGuard)
.patch(AdminGuard)
.delete(AdminGuard)
.get(UserGuard, ModelController.getBySlug)
.patch(AdminGuard, ModelController.update)
.delete(AdminGuard, ModelController.delete)
//-- CATEGORY >>

View File

@ -5,6 +5,7 @@ import type {IDbBrand} from "@interfaces/database/IDbBrand";
import type {IDbStatusResult} from "@interfaces/database/IDbStatusResult";
import mysql, {type Connection, type ConnectionOptions} from 'mysql2';
import {Logger} from "tslog";
import process from "node:process";
const access: ConnectionOptions = {
@ -28,7 +29,7 @@ class MysqlHandler {
this.Connection.connect((err) => {
if (err) {
this.Logger.error(`Error connecting to MySQL: ${err}`);
throw new Error()
process.exit(1);
}
this.Logger.info(`Connected to MySQL database (${access.database})`);
});