201 Commits

Author SHA1 Message Date
65a6ae2e3c
feat(routes): update rent related routes
- The "/affected" route has been updated to now use the `RentController.getAssignedToUser` method.
- The "/affected/all" route, which was previously not implemented, now utilizes the `RentController.getAll` function.
- These changes will help facilitate the retrieval of individual and all rented vehicles.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:18:46 +02:00
83d07a2812
feat(services): add availability check in rent service
A new condition was added in `rent.service.ts` to check if a vehicle is available before executing the rent operation. It also logs an error if the vehicle is not available.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:18:33 +02:00
e8acfd7b30
feat(services): update condition checks in model.service.ts
Updated the condition checks in the 'delete' and 'fetch' methods of the `model.service.ts`. Now, it properly checks if the model exists by examining the first item of the result array, instead of considering the result array itself. This resolves issues where fetching or deleting a model with a non-existent slug would incorrectly attempt to perform operations considering the empty array as valid input.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:18:15 +02:00
438ae4b5d0
fix(controllers): update model slug in updateModel function
The model slug has been updated to use `req.params["modelSlug"]` instead of `body.slug_name` in the `updateModel` function, ensuring the correct slug is used when checking if the model exists.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:17:58 +02:00
6ccc899320
feat(interfaces): add isAvailable field to IDbVehicle interface
The IDbVehicle interface has been updated to include an optional `isAvailable` field. This field can be used to check the availability status of a vehicle.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:17:47 +02:00
5afb6e22bf
feat(services): update getBySlug function in MySQL services
The `getBySlug` function originally returned a single database model by slug from the MySQL handler. It has been updated to return a list of database models by slug name. Error handling for failed query executions is also included.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:17:37 +02:00
bdba2f6e29
feat(controllers): add rent controller
- Implemented functionality for creating, updating, and getting rent information.
- Created `createRent`, `updateRent`, `getAllAssigned`, and `getAssignedToUser` functions in the `rent.controller.ts` file.
- These functions handle all the interactions related to renting vehicles.

Issue: #25
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 13:17:25 +02:00
30c6f2e3f1
feat(services): remove unused import from rent.service.ts
The `body` import from "express-validator" has been removed from rent.service.ts as it was not used. Also, an error handler for deleting rent was updated to always return false on encountering an error, improving the error handling mechanism.

Issue: #24
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 12:02:36 +02:00
b47ec6c440
feat(services): add error logging in rent.service
A logging feature is added in the `rent.service.ts` to log any errors when attempting to delete rent. This feature helps in diagnosing issues during rent deletion.

Issue: #24
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 12:01:56 +02:00
b4f200cb32
feat(inspectionProfiles): increase TypeScript code redundancy threshold
The minimum size for the TypeScript language in the duplicated code check has been increased. This update reduces the sensitivity of the code redundancy inspection, potentially reducing false positive results.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 12:01:03 +02:00
ec53fcb247
feat(services): add rent service functions
This commit introduces new functions to handle rental services in the src/services/rent.service.ts. Functions created handle rental CRUD operations such as createRentService, updateRentService, deleteRentService, also additional utility functions such as getUserRentService and getRentByIdService that deal with user-associated rentals were introduced. These new functions serve to simplify rental management and improve our services for rental handling.

Issue: #24
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 12:00:48 +02:00
371d960cf3
feat(services): update getById method in mysql.service
- Update the getById method in mysql.service to return an array of vehicles instead of a single vehicle
- Add a new getById method to retrieve array of rental information by rental ID
- Improve the documentation to match the modifications in both methods' functionalities

Issue: #23
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 11:59:58 +02:00
3525fb12e6
feat(routes): add create vehicle function to route
This commit hooks up the `VehicleController.create` function to the route handling post requests at `/veh/new`. With this change, admin users can add new vehicles via this endpoint.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 11:23:13 +02:00
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
f87aecaf75
feat(routes): update endpoints in rentRouter
Update `rentRouter.ts` to include `VehicleController` methods in route handlers.
- Add `VehicleController.getAll` to "/veh/all" route.
- Update "/veh/:vehicleId" route to include `VehicleController.getById`, `VehicleController.update`, and `VehicleController.delete`.

Issue: #22
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 11:17:45 +02:00
170b9a5693
feat(controllers): implement vehicle controller
Added a new `vehicle.controller.ts` file under controllers. It includes multiple functions related to vehicle management such as `createVehicle`, `updateVehicle`, `getAllVehicle`, `getVehicleById`, `getAvailableVehicle`, and `deleteVehicle`. These functions handle the creation, updates, retrieval, and deletion of a vehicle respectively. With these additions, the application now has the ability to manage vehicles through the `VehicleController` module.

Issue: #22
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 11:17:23 +02:00
c9ca39ddfa
feat(services): update code formatting in vehicle.service.ts
- Modify import statement format and standardize indentation across the entire file.
- Add line breaks and commas where needed for better readability.
- Remove unnecessary comments and white space.
- Ensure consistent usage of semicolons.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 11:01:54 +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
1c643b3625
feat(interfaces): add optional id property to IDbRent interface
A new optional `id` property has been added to `IDbRent` interface in the `interfaces` scope. This allows for more flexibility when working with rent objects in the database.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 09:52:07 +02:00
33d6793758
refactor(others): rename database table rent to rents
The database table `rent` has been renamed to `rents` to better align with naming conventions. The related DROP TABLE and CREATE TABLE commands have been updated accordingly in `db.sql`.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 09:51:42 +02:00
c95ac03680
feat(others): update database schema
- Change `LastIntrospectionLocalTimestamp` date in `brief_05` schema
- Rename table `rent` to `rents`
- Update `id` column `DasType` to `varchar(36)|0s`

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-03 09:51:24 +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
b6a2a74ba0
feat(services): add multiple vehicle services
Implemented `getAllVehiclesService`, `getVehicleByIdService` and `getAvailableVehicleService` in `vehicle.service.ts`. Each of these services fetches respective data from the MySQL database, handles errors, and returns the data along with a timestamp.

Issue: #21
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 16:49:13 +02:00
f310bedeff
feat(services): add vehicle update functionality in vehicle.service.ts
An `updateVehicleService` function has been introduced in `vehicle.service.ts` to enable vehicle data updates in the application. The function handles data validation, updates the MySQL database, and logs the process status.

Issue: #21
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 16:39:50 +02:00
838ea4ad22
feat(services): add new vehicle service
This commit introduces a new file `vehicle.service.ts` which includes a function for creating new vehicles. It uses MySQL service for data handling and includes error handling and logging functionalities. The changes help in improving the code modularity and providing a specific service for vehicle management.

Issue: #21
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 16:37:28 +02:00
00064fd054
feat(controllers): tag functions to test in auth.controller.ts
Marked several functions in `auth.controller.ts` file with `//ToTest` comments indicating that these functions are ready for testing. The tagged functions are `getAllUsers`, `getUser`, `editUser`, `deleteUser`, `deleteSelf` and `getSelf`. This is important for ensuring that all these features function as expected.

Issue: #19
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 16:13:46 +02:00
70a6e5df54
refactor(controllers): enhance error handling in auth controller
Update error handling in `auth.controller.ts` to provide more accurate responses based on operation results. This includes rigorous checking of response types before proceeding with particular operations. Notable changes include switching from string errors to error codes, and ensuring necessary properties exist in objects before accessing them.

Issue: #19
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 16:12:21 +02:00
7f52a9d75e
feat(controllers): improve response error handling in auth.controller
- Improve error handling in methods of the `auth.controller`
- Refactor conditional checks for errors to handle non-string types and missing payload data.
- Update response error messages to be more consistent and informative.

Issue: #19
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 15:41:38 +02:00
62742e6afe
feat(services): update user service
- Moved import statement to top for better organization.
- Removed unnecessary comments and lines.
- Simplified return statements for clarity and efficiency.
- Streamlined deletion process by directly returning the result.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 15:40:48 +02:00
bdfc598218
feat(services): update user service dynamic types and enhance error handling
- Refactored `editUserService` function to use `IUserUpdate` type for `inputData` instead of `IDbUser`.
- Enhanced error handling in `editUserService` and `deleteUserService` by checking for affected rows in the returned result.
- Updated `deleteUserService` from using MongoDB method to MySqlService method.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 15:37:39 +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
8644b5add6
feat(services): update user.service.ts for better error handling and debugging
The updated `user.service.ts` now includes better error handling using optional chaining and also generates a JSDoc definition for HTML status codes. An extra logger trace has also been added, which provides token related information in debug mode. This will capture user login token details for debugging purposes. Also cleaned up code formatting for readability.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 15:28:45 +02:00
b66a5aff6d
feat(interfaces): add HttpStatusCode enum
Added a new file `HttpStatusCode.ts` in the `interfaces` scope. This file defines an enum which represents all the possible HTTP Status Codes, enhancing readability and maintainability in the code base by replacing hard-coded numbers with meaningful names.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 14:37:46 +02:00
3d3da77df0
feat(services): add getByEmailService to user.service.ts
A new method `getByEmailService` has been added to `user.service.ts`. This method retrieves a user from the database by their email. The tracing log adjustment has also been performed, where logging only happens when it's in debug mode. If there are multiple users with the same email, this method will return the first user.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 14:25:10 +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
cb41c68f77
feat(utils): add debug state utility
This commit includes the creation of a new utility file for checking if the app is running in debugging mode. It exports `isDebugMode()` function that checks the `DEBUG` environment variable's value.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 14:11:48 +02:00
e98729c9e5
style(app): Remove newline from memory usage logging
This commit modifies the logging of memory and heap usage in the app.ts file. The redundant newline code `\n` at the end of the log message has been removed to enhance readability and neatness of the logs.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 13:31:56 +02:00
cd09a0c61b
build(others): update TypeScript compiler options in tsconfig.json
This commit updates the TypeScript compilerOptions in tsconfig.json. The changes include higher module resolution targets, adjustments in various compiler constraints, and the modification of paths for baseUrl. This will help improve the code's compile-time and run-time behavior.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 13:12:54 +02:00
1723a8588a
feat(controllers): update registerUser function in auth controller
This commit includes changes to improve the `registerUser` function in auth.controller.ts.
- Switched registration from displayName to email and added email validation
- Adjusted types and logging for better consistency and readability

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 12:23:20 +02:00
3fe6453b0c
style(utils): improve code readability in email validator
Improved code readability by formatting the regular expression in the `isEmail` function in `utils/validators/email.ts` and also ensured a newline at the end of the file.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 12:23:05 +02:00
98477c5f27
feat(interfaces): update user and request interfaces
- Renamed `is_mail_verified` to `is_email_verified` in `IDbUser`
- Replaced `username` with `email` in `IReqLogin`
- Commented out `dob` in `IReqRegister`
- Added new field `_questionMarksFields` in `IDbFactorize`

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 12:22:43 +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
3b6726113d
feat(services): enhance user service functions
- Modified the logic in `getUserByEmail` to handle multiple user instances.
- Altered the dob field to save as current date in inserted user records.
- Richened `getByEmailService` function to check email existence in the database.
- Adjusted `is_mail_verified` flag to `is_email_verified` within user insertion function.

Issue: #18
Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 12:21:37 +02:00
d78b0aec4c
feat(utils): add email validator function
A new function `isEmail` has been added to the utils folder that validates if a given string input is a valid email address. This should help in reducing erroneous entries and improve data validation.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 09:59:51 +02:00
ae6b25fbd6
style(services): improve code readability in user.service file
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>
2024-04-30 16:52:23 +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
cb1c2ee87c
feat(interfaces): add newline at end of IDbFactorize file
A newline has been added at the end of the `IDbFactorize.ts` file to conform to coding style conventions.

Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-30 16:51:13 +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