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>
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>
- 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>
- 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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
A TODO comment has been added to the `brand.service.ts` file indicating that blob validation needs to be implemented in the future, for both the 'create' and 'update' functions in the brand service.
Issue: #13
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 couple of new tasks have been added into the `brand.service.ts` file.
The tasks aim to fetch models and stats of a certain brand.
Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
The `brand.service.ts` file is updated to include a new function `deleteBrand`, which allows a brand to be deleted from the database by its ID. Appropriate error handling and activity logging have been incorporated to ensure smooth operation.
Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
A new function, `getByIdBrand`, has been added to the brand service. This function retrieves a brand from the database based on the provided brand ID, Checks are performed on the brand ID before the retrieval attempts.
Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
Adds a new function `getBySlugBrand` in `brand.service.ts`. This function retrieves a brand by its slug, providing a more specific search option. It implements error logging for missing slug or brand not found scenarios, and successful retrieval of the brand.
Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
The BrandService in the services module now includes a new functionality - the getAllBrand function. This function retrieves all brands from the database. Loggers have been added to check successful retrieval and error handling.
Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
A new function `updateBrand` has been introduced to `BrandService`. This function handles updating a brand in the database, including checks for missing `id`, brand existence by `slug_name`, and logging for successful or failed updates.
Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
Change the import of `IDbBrand` in `brand.service.ts` to explicitly denote it as a type. This clarifies that `IDbBrand` is only used for its type information, improving readability and understanding of code usage.
Signed-off-by: Mathis <yidhra@tuta.io>
- Removed extraneous comments and updated function parameters to use interface types in `register` and `login` methods.
- Renamed `RegisterService` and `LoginService` to `register` and `login` respectively.
- This update enhances readability and maintains the consistency in code by leveraging TypeScript's type-checking feature.
Signed-off-by: Mathis <yidhra@tuta.io>
Duplicate comments were found and removed from `category.service.ts`. This refactoring step will make the code cleaner and less confusing.
Signed-off-by: Mathis <yidhra@tuta.io>
This commit introduces the new file `brand.service.ts` under services. Specifically, it implements the `createBrand` method which handles the creation of a new brand instance in the database if there's no existing brand with the same slug name. The function returns a promise containing the operation result. A UUID is also generated as `brandId`, and several logs will be recorded in different situations.
Issue: #13
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>