The user.service has been reformatted for better readability. Changes mainly include adding new lines and spaces to make the code more structured. No change in logic involved, purely cosmetic.
Signed-off-by: Mathis <yidhra@tuta.io>
- The readability within mysql.service.ts file is improved by formatting multi-line functions.
- The factorize function for 'users', 'brands', 'vehicles', and 'categories' has been updated to enhance code quality.
- Import statements were restructured for better readability.
Signed-off-by: Mathis <yidhra@tuta.io>
This commit:
- Standardizes the data handling in all update methods, using `handler.factorize()`
- Moves gdpr date validation to the top of 'update' method to reject it earliest
- Removes the unused `_values` and `_template` variables.
Signed-off-by: Mathis <yidhra@tuta.io>
Remove the condition to check 'id' while generating SQL query keys in the `mysql.service.ts`. Now, a map function is used directly resulting in cleaner and leaner code.
Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
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>
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>
- 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>
- 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>
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>
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>
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>
- 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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
- 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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>