50 Commits

Author SHA1 Message Date
82afff9878
feat(services): add update function in mysql service
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>
2024-05-03 11:23:00 +02:00
fef2bda082
refactor(services): simplify SQL query strings and reformat function parameters
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>
2024-05-03 11:18:30 +02:00
da028ea2c4
feat(services): update CRUD operations in mysql.service.ts
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>
2024-05-03 10:30:57 +02:00
03fc5307e6
feat(services): add deleteVehicleService function to vehicle service
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>
2024-05-02 16:51:32 +02:00
1cbc771251
feat(app): update debug syntax, refactor HTTP status codes
- 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>
2024-05-02 15:29:19 +02:00
abaeafea8a
feat(services-controllers): implement debug mode and refactor error handling
- 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>
2024-05-02 14:18:28 +02:00
3472c59ac2
feat(services): refactor MysqlHandler to improve factorize method
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>
2024-05-02 12:22:17 +02:00
d7f9cb0b37
feat(services): enhance readability and update factorize function for various elements in mysql.service
- 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>
2024-04-30 16:51:55 +02:00
23ce32cb6f
feat(services): refactor update methods in mysql service
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>
2024-04-30 16:50:40 +02:00
f6d18fc58d
feat(services): simplify SQL query keys generation in mysql service
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>
2024-04-30 16:39:43 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
73e086be44
docs(services): add TODO comment in mysql.service
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>
2024-04-25 14:22:25 +02:00
0abdbab627
feat(services): add getById and delete methods in mysql.service.ts
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>
2024-04-25 12:52:42 +02:00
3328c5a1df
feat(services): add getById function to mysql.service
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>
2024-04-25 12:30:32 +02:00
ead64291df
feat(services): add getBySlug method to MysqlService and refine getAll method
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>
2024-04-25 12:27:25 +02:00
02383b8c8a
feat(services): add getAll function to mysql service
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>
2024-04-25 12:18:33 +02:00
2210280edd
feat(services): update return types and add documentation in mysql service
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>
2024-04-25 12:11:17 +02:00
47adae9137
feat: Update MySQL service for category operations
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>
2024-04-25 12:01:02 +02:00
ef83ad18a4
feat(services): Db - category insert method
#6
2024-04-25 11:37:09 +02:00
adbecfa435
style(services): 🎨 Db 2024-04-25 11:36:20 +02:00
6a54dd0afa
feat(services): Db - partial insert method for 'model' 2024-04-24 16:55:15 +02:00
ccee786c2f
feat(services): 🎉 db - models getters interaction
#7
2024-04-24 15:07:45 +02:00
69fae2b780
feat(services): db - user interaction
#4
2024-04-24 15:04:44 +02:00
742330d6fe
refactor(services): 🏗️ var name change
#9
2024-04-23 15:12:41 +02:00
ad0f30876e
feat: MySQL Service 2024-04-23 13:44:58 +02:00