114 Commits

Author SHA1 Message Date
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
0f8fd9a3e8
feat: Add Docker compose file for database setup
Add a `docker-compose.yml` file to ease local development. The file specifies configuration for a MariaDB container that will now serve as our database server. Environment variables and ports are also configured in the file.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 09:39:15 +02:00
80dff138cc
chore(others): add dist to .gitignore
The update now includes `dist` directory in the `.gitignore` file to avoid pushing compiled files to the repository.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 16:22:30 +02:00
0887fe213f
feat(services): update JWT methods in jwt.service.ts
Update the methods related to JWT in `jwt.service.ts`. Import and utilize `jwtVerify` and `SignJWT` from the "jose" package, replacing their previous counterparts. This refactors the `JwtVerifyService` and `JwtSignService` functions for better JWT handling.

Issue: #30
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 16:22:14 +02:00
3231f916f8
feat(validators): add check for non-existent userId
- The `UserGuard` now checks whether the `userId` extracted from the token exists.
- If the `userId` does not exist, an error is logged and a response with the 'Unauthorized' status is returned.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 15:44:01 +02:00
a74731a49e
feat(controllers): add ModelController with CRUD methods
This commit adds a new controller, `ModelController`, to the controllers directory. This controller includes create, read, update and delete (CRUD) methods for handling 'model' related operations. Each method incorporates appropriate error handling and logging.

Issue: #28
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 14:09:29 +02:00
9bdcdef88f
feat(routes): apply routers and rename files
- Routers `AuthRouter`, `CatalogRouter`, and `RentRouter` are used in the application in `src/app.ts` with error handling.
- The router files under `src/routes/auth`, `src/routes/catalog`, and `src/routes/rent` are renamed to `authRouter.ts`, `catalogRouter.ts`, `rentRouter.ts` respectively.
- The default exports in these router files have been updated to reflect their new names.
- The imports in `src/routes/index.ts` are updated according to the renamed files.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 12:21:13 +02:00
5d53cd28f8
refactor(services): update methods in ModelService
Removed `getByIdModel`, `getByCategoryModel`, and `getModelsByBrand` methods. These changes are to refine the methods available in ModelService for better usage and understanding.

Issue: #27
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 12:13:28 +02:00
8711b3530a
feat(services): add fetch functions for models
Added two new functions, `getBySlugModel` and `getAllModels`, to the `ModelService` in `model.service.ts`. `getBySlugModel` fetches a model based on its slug while `getAllModels` fetches all models from the database.

Issue: #27
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 12:12:03 +02:00
13d72ad529
feat(services): update logging in updateModel and add deleteModel
The `updateModel` function's logging has been updated to use `slug_name` instead of `id`. Additionally, a new function `deleteModel` has been added to remove models from the database based on their slug. This function checks the existence of a model before attempting deletion and logs the process.

Issue: #27
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 12:06:19 +02:00
f23aabccd4
feat(services): add updateModel function and refine createModel function in model.service.ts
This commit mainly includes adding `updateModel` function, which updates a model in the database and refines `createModel` function in `model.service.ts`. It provides more clear explanations before the function and also specifies the return data type.

Issue: #27
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 11:58:04 +02:00
c70bcef352
feat(services): add model service
This commit adds a new service `ModelService` to handle model operations such as create, update, and delete. Some features like getBySlug, getAll, getById, getByCategory, and getByBrand are also introduced.

Issue: #27
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 11:53:42 +02:00
30bd5a0dbe
feat(services): update database operations return type in mysql.service
This commit includes significant changes in `mysql.service.ts` in the `services` scope.
- Imported `IDbStatusResult` type.
- Updated the return type of all operations (insert, update, delete) on both `Brand` and `Model`. These operations now return `Promise<IDbStatusResult>` instead of `Promise<unknown>` or `Promise<number>`.
- Also, adjusted the functions documentations to reflect these changes, providing more clarity about the returned result from database operations.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 11:34:15 +02:00
61c546459a
feat(interfaces): add IDbStatusResult interface
A new interface, `IDbStatusResult`, has been added to the 'interfaces' scope. This interface includes details about database operations such as field count, affected rows, insert id, info, server status, warning status, and changed rows.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 11:18:41 +02:00
adaf4e30db
feat(services): update MySQL services with method adjustments
- Modified 'getById' reject message for accuracy.
- Adjusted 'getBySlug' method parameters for clarity and renamed the field used in the SQL statement.
- Added a new 'getById' method for retrieving models by ID.
- Updated the 'insert' method to correctly insert data into the `models` table.
- Refactored 'getBySlug' method for categories, renaming the parameter and making error messages more precise.

Issue: #7
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 11:09:26 +02:00
2f4ad31edf
docs(controllers): add TODO comment for future feature in brand controller
In the brand controller file, a comment was added indicating a future enhancement to implement the functionality that fetches all models of a specific brand.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 10:29:07 +02:00
c25b204c67
feat(controllers): add BrandController with CRUD operations
This commit introduces a new `BrandController` in the controllers folder, offering key Create, Read, Update, and Delete (CRUD) operations. This includes `createBrand`, `updateBrand`, `getBySlugBrand`, `getAllBrand`, and `deleteBrand` methods, providing better control and operation of brands within the application.

Issue: #14
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 10:26:38 +02:00
0a6321deb0
feat(services): mark blob validation as TODO in brand service
A TODO comment has been added to the `brand.service.ts` file indicating that blob validation needs to be implemented in the future, for both the 'create' and 'update' functions in the brand service.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 10:00:55 +02:00
a811a2ece2
docs(services): add tasks to MySQL and Category services
An additional task is marked in the MySQL service to check if models are linked before taking further actions. Similarly, in the Category service, two tasks are added to verify the existence of a category and elements linked to it before proceeding with deletion.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:57:44 +02:00
85adbbcdb3
docs(services): add new tasks in brand.service.ts
A couple of new tasks have been added into the `brand.service.ts` file.
The tasks aim to fetch models and stats of a certain brand.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:53:27 +02:00
5c0d266002
feat(services): add deleteBrand function to brand.service.ts
The `brand.service.ts` file is updated to include a new function `deleteBrand`, which allows a brand to be deleted from the database by its ID. Appropriate error handling and activity logging have been incorporated to ensure smooth operation.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:52:09 +02:00
6c626e0b18
feat(services): add getByIdBrand function in brand service
A new function, `getByIdBrand`, has been added to the brand service. This function retrieves a brand from the database based on the provided brand ID, Checks are performed on the brand ID before the retrieval attempts.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:41:37 +02:00
aecaf83d85
feat(services): add getBySlugBrand function in brand.service
Adds a new function `getBySlugBrand` in `brand.service.ts`. This function retrieves a brand by its slug, providing a more specific search option. It implements error logging for missing slug or brand not found scenarios, and successful retrieval of the brand.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:40:24 +02:00
33d44ee4b6
feat(services): add getAllBrand function in BrandService
The BrandService in the services module now includes a new functionality - the getAllBrand function. This function retrieves all brands from the database. Loggers have been added to check successful retrieval and error handling.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:35:55 +02:00
90cd80e540
feat(services): add updateBrand function to BrandService
A new function `updateBrand` has been introduced to `BrandService`. This function handles updating a brand in the database, including checks for missing `id`, brand existence by `slug_name`, and logging for successful or failed updates.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-26 09:30:03 +02:00
f3bddc7170
feat(services): change IDbBrand import to explicit type import
Change the import of `IDbBrand` in `brand.service.ts` to explicitly denote it as a type. This clarifies that `IDbBrand` is only used for its type information, improving readability and understanding of code usage.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:57:39 +02:00
789d62ea62
feat(services): refactor register and login functions in UserService
- Removed extraneous comments and updated function parameters to use interface types in `register` and `login` methods.
- Renamed `RegisterService` and `LoginService` to `register` and `login` respectively.
- This update enhances readability and maintains the consistency in code by leveraging TypeScript's type-checking feature.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:57:21 +02:00
debb30b896
refactor(services): remove duplicate comments in category.service.ts
Duplicate comments were found and removed from `category.service.ts`. This refactoring step will make the code cleaner and less confusing.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:57:10 +02:00
6e429f4f27
feat(services): add new BrandService with createBrand function
This commit introduces the new file `brand.service.ts` under services. Specifically, it implements the `createBrand` method which handles the creation of a new brand instance in the database if there's no existing brand with the same slug name. The function returns a promise containing the operation result. A UUID is also generated as `brandId`, and several logs will be recorded in different situations.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:56:50 +02:00
b1dacb750a
feat(services): add delete function in mysql service
A new delete function has been added to the `mysql.service.ts` file under services. This function deletes a brand from the database using the brandId. It throws an error if the brandId is undefined or invalid.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:40:42 +02:00
0ed130f7b8
feat(services): update MySQL service to fetch brand data
- Corrected the SQL query in fetching brand data based on ID.
- Added a new function, `getBySlug`, to fetch brand data using the brand slug. This ensures a flexible data access method thus enhancing the service's usability.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:38:41 +02:00
50c1ff797f
feat(services): add getById function to mysql.service
The code now includes a `getById` function in `mysql.service.ts`, which fetches a category by its id. This function will reject with an error message if brandId is not defined or if its length is not 36. The query is executed using a MysqlHandler instance.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:36:12 +02:00
2640ebbc70
feat(controllers): add detailed comment to getBySlugCategory function
The `getBySlugCategory` function in `category.controller.ts` now has a detailed comment. The comment includes a description of the function, its parameters, and its return value.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:31:33 +02:00
a992868eb6
feat(services): add 'getAll' function to mysql.service.ts
A new function named `getAll` has been added to `mysql.service.ts`. This function is designed to retrieve all records from the `brands` table. It returns a promise that resolves to an array of `IDbBrand` objects representing the retrieved records.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:29:39 +02:00
f3fc63502d
feat: Replace express-xss-sanitizer with helmet
The security middleware `express-xss-sanitizer` has been replaced with `helmet` for enhanced security measures. `helmet` provides better protection against potential security vulnerabilities.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:26:52 +02:00
44b04459fb
feat(services): add detailed comments and specify return types in mysql.service
In the `mysql.service`, this commit adds detailed doc-block comments for `insert` and `update` functions under `Brand` and `Category`. Additionally, the return types of the `update` functions under `Brand` and `Category` are now specifically defined as `Promise<number>`, providing clarity on the expected returns.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:26:29 +02:00
64aa814d2c
feat(services): add update method to mysql service
An `update` method is added to the `mysql.service.ts` for handling database updates. This new function checks for validity of the `id` before constructing and executing an SQL update statement. Errors are also caught and handled.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:24:02 +02:00
016f7fa9d4
feat(services): add brand insert method in mysql service
- Adjusted import syntax for IDbCategory interface
- Imported IDbBrand from database interfaces
- Added a new `insert` method in Brand object in MysqlHandler to insert brand data into the database. The method resolves with execution of SQL command and rejects on error or invalid ID.

Issue: #5
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:19:27 +02:00
01241dff4b
fix(services): correct database table name in mysql.service.ts
Update the hardcoded table name in the raw SQL query within mysql.service.ts. We changed `categorys` to `categories` to align with the actual database schema.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:07:29 +02:00
dda3eea9e1
feat(interfaces): add IReqRegister interface
This interface defines the register request structure, including `username`, `displayName`, `firstName`, `lastName`, `password`, and `gdpr` status. This will ensure consistency in the form of request data throughout the application.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:06:33 +02:00
a430044d95
feat(interfaces): add IReqLogin interface
The new IReqLogin interface defines the request shape for user login. It includes two string properties - username and password.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 16:06:02 +02:00
6c601e0b42
feat(app): add helmet for XSS protection
In order to improve security, we've added Helmet to the app to provide protection against cross-site scripting (XSS) attacks. This integration involves enabling the xss filter middleware through Helmet.

Issue: #3
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 15:56:48 +02:00
3ee76fb965
feat(routes): add CategoryController to category routes
Category routes have been updated to utilize the `CategoryController`. New, getAll, getBySlug, update, and delete methods from CategoryController are integrated with their corresponding category routes.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 15:19:50 +02:00
8b306e9a31
build(package): add uuid to dependencies
The package.json has been updated to include the 'uuid' package in both main and dev dependencies. This includes the addition of 'uuid' version "^9.0.1" to the list of dependencies and '@types/uuid' version "^9.0.8" to the list of devDependencies.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 15:03:08 +02:00
62cb05cb33
feat(controllers): add delete and getBySlug methods in category controller
The `category.controller.ts` has been updated to handle deleting a category and retrieving a category by slug. The `deleteCategory` function takes a category slug from the request params and first checks if the category exists before attempting to delete it. While the `getBySlugCategory` function simply retrieves a category by its slug.

Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 15:02:46 +02:00
da001bf7cc
docs(services): add test markers to credential functions
In `credential.service.ts`, markers were added to functions `getHashFromPassword` and `comparePassword` to indicate necessity for testing. This provides clear indications for developers about which functions require tests to be written or updated.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 14:54:17 +02:00
cd51a04aba
feat(controllers): add getAllCategory function in category controller
The getAllCategory function is added in `category.controller.ts`. This function retrieves all categories and presents an error message if it fails. Specifically, it interacts with the Category service to get all categories, logs the process, and maps each element to an {`id`, `display_name`, `slug_name`} object before sending the response.

Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 14:52:42 +02:00