201 Commits

Author SHA1 Message Date
5163d79056
test(services): add DbHandler usage in user.service.ts
This commit includes:
- The usage of `DbHandler.factorize` with sample values
- Testing log trace to monitor the result and fields of factored user data

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:36:59 +02:00
ea3b7aa68b
feat(services): prevent id field from being factorized in mysql service
In the `mysql.service.ts`, the `factorize` function has been updated to exclude the `id` field. This change ensures the 'id' field is not injected into the result to avoid any potential issues. Furthermore, The update operation in the same file has been refactored to use the updated `factorize` function, hence enhancing code reusability.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:35:51 +02:00
bc12f94e41
feat(services): refactor user service and improve error handling
- Introduced error handling in `register`, `login`, `getAllUsersService`, and `editUserService` methods.
- Improved logging by adding breaks for better visibility.
- Refactored code for better readability and maintainability.
- Eliminated unnecessary and duplicate imports.
- Transitioned from MongoDB to MySQL service.
- Added comment flags for testing purposes.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:19:12 +02:00
df28d3aa52
feat(services): add factorize method and refactor update method in mysql.service
- The `factorize` method was added to `mysql.service.ts` to convert input data into a database query.
- The `update` method was refactored; unnecessary data fields were removed and a check for the `gdpr` field was added. A corresponding interface, `IUserUpdate`, was also imported at the beginning of the file.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:15:19 +02:00
3d5ea6ac30
feat(interfaces): add IUserUpdate interface
This commit introduces a new interface named IUserUpdate. This interface consists of optional properties like id, username, firstname, lastname, dob and gdpr. These properties are used for validating user's data during update operation.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:14:47 +02:00
2fb6cd6e83
feat(interfaces): add IDbFactorize interfaces
Added IDbFactorizeOutput and IDbFactorizeInput interfaces to handle inputs and outputs of the SQL query factorization function. Both interfaces contain various properties for customizing the SQL query and its error handling behavior.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:14:29 +02:00
34f028ef9f
feat(app): updated log messages in multiple files
Changes applied to several services and controllers files:
- Enhanced logging messages with line breaks in `brand.controller.ts`, `auth.controller.ts`, `model.controller.ts`, and `category.controller.ts`.
- Adjusted logging in `mysql.service.ts`, `brand.service.ts`, `user.service.ts`, `category.service.ts`, `model.service.ts` and `jwt.service.ts` to commence on a new line for better readability.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 14:18:47 +02:00
0635c512cc
feat(services): add memory usage info, update user, enhance log and register function
- Added log for loaded services
- Implemented feature to update user in MySQL service
- Added memory usage information in the server start log
- Enhanced registration function in user service to provide more detailed response and log information
- Minor code formatting improvements

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 14:08:00 +02:00
3232e5fac1
feat(services): improve UserService with enhanced error handling and data validation
This commit includes updates to `user.service.ts` that enhance error handling and data validation. The `getUserFromUsername` function has been renamed to `getUserByEmail` reflecting the new identifier being used to retrieve users. Both `getUserByEmail` and `getUserFromIdService` have been revised to include error handling and logging capability. The `register` function now incorporates stronger validation checks and proper GDPR verification. It is also updated to return JWT token on successful registration.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 12:38:26 +02:00
9225337e95
feat(interfaces): update IReqRegister interface
The `IReqRegister` interface was modified. It no longer includes the `displayName` field, but `dob`, `email`, and `password` fields were added. The 'password' property was moved to the end of the interface.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 12:37:24 +02:00
f1272ca2c8
refactor(interfaces): remove unnecessary quotes in ErrorType enum
Removed unnecessary quotes from the keys of the `ErrorType` enum in the `ISError.ts` file, making the code more readable and conforming to TypeScript's best practices.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 12:35:27 +02:00
4fd6c11326
feat(interfaces): add ISError interface and ErrorType enum
A new interface `ISError` has been added to represent error objects. Also, an enumeration `ErrorType` has been included to cover all possible types of errors that may occur in the application. This improves the structuring of error handling in the project.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 11:57:22 +02:00
355cb0ec90
refactor(services): refactor method arguments and promises handling in mysql.service.ts
- Compact multiple lines codes into single lines for readability and simplicity.
- Replace some Promise responses from unknown to specific IDbStatusResult for a more predictable result.
- In `insert`, `update`, `getById` and `delete` methods for `brands`, `categories`, `models`, `vehicles` and `users`, modify the way promises are handled and return values.
- This makes the code more readable and easier to understand.

Issue: #17
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 11:42:05 +02:00
19d265a0e6
refactor(services): simplify function calls and logging statements in user.service.ts
This commit simplifies multi-line function calls and logging statements in `user.service.ts` to be just single-line. This change enhances the readability and maintainability of the code by reducing unnecessary lines and making the function calls and logging statements more straightforward.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 11:05:34 +02:00
a6593cb76f
feat(all): refactor code for readability and simplicity
The controllers, services, routes, and others have been updated to reduce code complexity and improve readability. Changes include removing unnecessary lines, replacing long function signatures with simpler versions, and streamlining condition checks and logger statements.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 11:03:28 +02:00
28671146d1
feat(others): Add BiomeSettings in .idea/biome.xml
A new file `.idea/biome.xml` is added with `BiomeSettings` component for the project. It also includes MANUAL configuration with enabling formatOnSave option.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 10:56:39 +02:00
56bfd8cd0d
type: style
scope: services, interfaces

subject: Apply code formatting

- Correct indentation and formatting to match code style standards in multiple 'interfaces' and 'services' files.
- Also ensure lines at the end of the files.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 10:55:37 +02:00
cda313866f
feat(services): update return type in mysql.service
The return type for the update function in mysql.service is updated from Promise<unknown> to Promise<IDbStatusResult>. Also, the function resolves with the status result of the update instead of just being successful.

Issue: #17
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 10:01:14 +02:00
91b88ea592
chore: Bump package version to 1.1.0
The package.json file has been updated, specifically the version of the project has been changed from 1.0.0 to 1.1.0.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 09:59:24 +02:00
44b5745f3b
feat(services): update insert function in mysql service
The `insert` function in mysql service has been updated. The function now includes more accurate commenting, and a check for `id` validity. It now returns a Promise with `IDbStatusResult` instead of `unknown`. The changes improve function clarity and error handling.

Issue: #17
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 09:59:06 +02:00
a9cf48b04a
docs(services): update MySqlService in mysql.service.ts
Added a comment to test all users in MySqlService. Also, removed a redundant comment in Vehicle's MySqlService. All changes are seen in mysql.service.ts.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 15:00:33 +02:00
16a8e892f9
feat(others): Update database collations
The collations in the database have been updated, changing from `armscii8` to new ones such as `big5`, `dec8`, `cp850`, and others. This should help to smooth internationalization and localization processes involving different charsets.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 15:00:04 +02:00
89ba2cb6d1
feat(others): add new SQL dump file
The `db.sql` file was newly created which contains the structure for several tables namely `brands`, `categories`, `models`, `rent`, `users`, and `vehicles`. The tables contain relationships and constraints among them and is a MariaDB dump prepared for a Linux system.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 14:58:44 +02:00
47bb7aacdf
refactor(services): add IDbVehicle import in mysql.service.ts
This commit includes changes to the import lines in 'mysql.service.ts'. Import of 'IDbVehicle' from '@interfaces/database/IDbVehicle' has been moved to maintain alphabetical order of the imports.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 13:40:46 +02:00
88e89f0551
feat(database): update database schema and sql dialect settings
- Added new procedures `CheckVehicleAvailability` and `IsVehicleAvailable` to the database schema.
- Introduced an `isAvailable` column to the `vehicles` table.
- Updated sql dialect settings to include a new console file for the database.
- Reflected changes also include id adjustments and table modifications.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 13:39:28 +02:00
9a6d7a73b2
feat(services): update getAvailable method in mysql.service
- Transform `getAvailable` method into a promise that retrieves available vehicles from the database.
- This method now takes the MySQL handler object to execute the query and returns a promise that resolves to an array of available vehicles.
- It also handles error while executing the query.

Issue: #20
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 13:38:15 +02:00
89d9fc47b2
feat(database): update database configuration
Update the database configuration like updating the LastIntrospectionLocalTimestamp and refactoring indexes and keys. This includes adding two new indexes `users_pk` and `users_pk_2`, and corresponding keys. Moreover, the columns' ID have been updated. These changes are done for better database performance and clear structuring.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 13:09:54 +02:00
37cfaf4bbd
feat(services): implement getById and getAll methods in mysql service
Implemented getById and getAll methods in the mysql service. The getById method retrieves a vehicle by its ID, and the getAll method fetches all vehicles from the database. These improvements facilitate more efficient data retrieval and enhance overall service functionality.

Issue: #20
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 12:23:13 +02:00
8138231112
feat(data-grip): Add new data source and schema metadata files
Two new files have been added: `brief_05.6nelCw.meta` for schema metadata, and `1f2800b5-8649-4a80-a9ec-b7b2a24623b4.xml` for defining the data source. These configurations support the interaction with our database in different environments.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 12:12:50 +02:00
edf2f6880c
feat(services): enhance insert and update methods in mysql.service.ts
- Enhanced `insert` and `update` methods in `mysql.service.ts`
- Added detailed documentation and type checks for `insert` function.
- Implemented body of `update` method, included parameter validation and SQL query building.

Issue: #20
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 12:05:34 +02:00
cd4b8479d2
fix(scripts): correct 'bun:dev' script in package.json
The previous `bun:dev` script was missing the key command `bun run`. This has been corrected for proper execution of the script in the development mode.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 11:44:58 +02:00
d05c7efadc
feat(package.json): change main entry point and add development script
This commit modifies the `package.json` file in two key ways. The main file is now `src/app.ts` instead of `dist/app.js`. Additionally, a new script `bun:dev` has been added to aid in development, which watches the main file for changes.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 11:35:44 +02:00
8fe0fa57d8
feat(services): add Vehicle methods to mysql service
This commit introduces several new Vehicle methods to the mysql service (insert, update, getBySlug, getAll, getAvailable, getDue). These methods are scaffolded but not fully implemented, with `insert` being the most complete at this stage.

Issue: #20
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 11:31:50 +02:00
2796b514eb
feat(routes): add BrandController methods to catalog routes
The commit introduces BrandController methods to the catalog router. Specifically, it implements create, getAll, getBySlug, update, and delete functionalities for brand routes. This update enhances brand management within the catalog.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 11:30:59 +02:00
0053c0ce19
feat(interfaces): add IDbVehicle interface
Add a new interface called `IDbVehicle` in the interfaces module. The `IDbVehicle` interface includes properties such as `id`, `plate_number`, `model_id`, `odometer`, and `health_state` for defining a vehicle object in our database.

Issue: #20
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 11:30:13 +02:00
041e77efcd
feat(controllers): include request param to getAll functions
Changes include the inclusion of the request parameter (`_req`) in the `getAllBrand` and `getAllCategory` functions and some code format adjustment in `category.controller.ts`. This addition allows more flexibility in handling the request if needed in the future. The `total` field has also been added to the category output to conveniently provide category count.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-29 11:29:29 +02:00
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
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