This commit adds an `update` function to the `mysql.service.ts`. This new function will update a rent record in the database. It takes a database handler object and a rent object containing the updated data, and returns a Promise that resolves to the status result of the update operation. The function will throw an error if an issue occurs during the update operation.
Issue: #23
Signed-off-by: Mathis <yidhra@tuta.io>
This commit includes the following changes in `mysql.service.ts` file:
- Simplify SQL query strings for `UPDATE` and `INSERT` commands in various methods to make them more readable.
- Reformat parameters in `getAllModelsFromCategory` and `delete` methods for better readability.
Signed-off-by: Mathis <yidhra@tuta.io>
In this commit:
- Implemented factorize method to standardize data processing and update operations for users, brands, models, categories, and rents.
- Updated SQL syntax to improve code hygiene and readability.
- Added debug mode checks to improve performance in production.
- Added exception handling for possible errors during SQL query execution.
- Added additional methods to get assigned vehicles to a user and all assigned vehicles from the database.
- Added missing delete method for vehicle and rent tables.
Issue: #23 & #21
Signed-off-by: Mathis <yidhra@tuta.io>
A new function `deleteVehicleService` is added to `vehicle.service.ts` to handle the vehicle deletion process. It will return true if the operation is successful, and false if it fails or encounters an error.
Issue: #21
Signed-off-by: Mathis <yidhra@tuta.io>
- Updated import and usage of `isDebugMode` function across multiple controllers and services for better readability
- Improved the use of HTTP status codes in `auth.controller.ts` for more accurate responses
- Refactored HTTP status codes `HttpStatusCode` enum to include detailed comments
Signed-off-by: Mathis <yidhra@tuta.io>
- Implement debug mode for logging in services and controllers.
- Improve the precision of memory usage information in the app by rounding.
- Refactor error handling in services, notably in user service register function for better error checking.
- Include a condition in the AdminGuard validator to check if the token is valid.
- Fix issue in auth controller that was misidentifying user registration error as a successful registration.
- Refactor log display in Mysql service error throwing for better readability.
- Refactor memory usage information display in app for better readability.
These changes aim to improve the clarity of logs and accuracy of error reporting for a better debugging experience. The implementation of debug mode gives more control over the information displayed in the development phase. Several fixes in error handling also contribute to a more robust system.
Signed-off-by: Mathis <yidhra@tuta.io>
Update the MysqlHandler class in the 'mysql.service.ts':
- Enhance the `factorize` method to handle 'id' in a special manner and create a string of '?' for prepared SQL queries.
- Refactor the `add` method to utilize the updated `factorize` method for constructing SQL queries.
- Update the return types of `getById` and `getByEmail` methods to return an array of IDbUser instead of a single IDbUser instance.
- Rename a private attribute 'Logger' to 'logger'.
Issue: #18
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>
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>
- 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>
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>
- 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>
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>
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>
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>
- 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>
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>
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>
- 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>
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>
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>
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>
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>
- 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>
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>
A TODO comment has been added in the mysql.service.ts file as a reminder to get models in category in the future. This is to ensure that future development accounts for this necessity.
Signed-off-by: Mathis <yidhra@tuta.io>
The changes introduce two new methods in mysql.service.ts. The getById method retrieves a category from the database using its ID while the delete method will delete a category from the database using the provided category ID. Both methods return promises.
Issue: #6
Signed-off-by: Mathis <yidhra@tuta.io>
This commit adds a getById function to the mysql.service.ts file. The added functionality allows retrieving category data from the mysql database by id. Error handling has been included for undefined or invalid id cases.
Issue: #6
Signed-off-by: Mathis <yidhra@tuta.io>
Added a new method getBySlug to retrieve a category by its slug in mysql.service.ts. Also, updated the getAll method by specifying the return type to Promise<Array<IDbCategory>> for better type checking.
Issue: #6
Signed-off-by: Mathis <yidhra@tuta.io>
This commit adds a new `getAll` function in the `mysql.service.ts` file, which retrieves all categories from the database. It executes a SQL query and includes error handling that either resolves with an array of category objects or rejects with an Error object.
BREAKING-CHANGE: #6
Signed-off-by: Mathis <yidhra@tuta.io>
The return types for the 'insert' and 'update' methods in mysql.service.ts have been updated to 'Promise<unknown>'. Also, detailed JSDoc comments have been added for 'insert' and 'update' methods for both User and Category entities. No functionality changes have been made.
Signed-off-by: Mathis <yidhra@tuta.io>
This update introduces changes in the 'mysql.service.ts' to allow create and update operations for categories. The 'INSERT INTO' SQL query has been adjusted from targeting `users` to `categories`. An `update` function has also been added to allow updates in category data. The import order has been rearranged for better readability.
Signed-off-by: Mathis <yidhra@tuta.io>