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>
The `getBySlugCategory` function in `category.controller.ts` now has a detailed comment. The comment includes a description of the function, its parameters, and its return value.
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>
The security middleware `express-xss-sanitizer` has been replaced with `helmet` for enhanced security measures. `helmet` provides better protection against potential security vulnerabilities.
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>
This interface defines the register request structure, including `username`, `displayName`, `firstName`, `lastName`, `password`, and `gdpr` status. This will ensure consistency in the form of request data throughout the application.
Signed-off-by: Mathis <yidhra@tuta.io>
The new IReqLogin interface defines the request shape for user login. It includes two string properties - username and password.
Signed-off-by: Mathis <yidhra@tuta.io>
In order to improve security, we've added Helmet to the app to provide protection against cross-site scripting (XSS) attacks. This integration involves enabling the xss filter middleware through Helmet.
Issue: #3
Signed-off-by: Mathis <yidhra@tuta.io>
Category routes have been updated to utilize the `CategoryController`. New, getAll, getBySlug, update, and delete methods from CategoryController are integrated with their corresponding category routes.
Signed-off-by: Mathis <yidhra@tuta.io>
The package.json has been updated to include the 'uuid' package in both main and dev dependencies. This includes the addition of 'uuid' version "^9.0.1" to the list of dependencies and '@types/uuid' version "^9.0.8" to the list of devDependencies.
Signed-off-by: Mathis <yidhra@tuta.io>
The `category.controller.ts` has been updated to handle deleting a category and retrieving a category by slug. The `deleteCategory` function takes a category slug from the request params and first checks if the category exists before attempting to delete it. While the `getBySlugCategory` function simply retrieves a category by its slug.
Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
In `credential.service.ts`, markers were added to functions `getHashFromPassword` and `comparePassword` to indicate necessity for testing. This provides clear indications for developers about which functions require tests to be written or updated.
Signed-off-by: Mathis <yidhra@tuta.io>
The getAllCategory function is added in `category.controller.ts`. This function retrieves all categories and presents an error message if it fails. Specifically, it interacts with the Category service to get all categories, logs the process, and maps each element to an {`id`, `display_name`, `slug_name`} object before sending the response.
Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
Remove unused import `{IDbCategory}` from `category.controller.ts`. This reduces clutter and increases code clarity in the file.
Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
This commit includes the addition of a new function, `updateCategory` in the category.service.ts file. This function allows for updating a category in the database. Error handling and logging are also implemented within the function.
Signed-off-by: Mathis <yidhra@tuta.io>
This commit includes the creation of an updateCategory function in the category controller which allows for existing categories to be updated. It also includes appropriate error handling and response messages. In addition, it also introduces logging for the successful creation of a category.
Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
- Revised comments replacing 'TODO' with 'FIX' and 'FEAT' in AuthController.
- Renamed 'AuthController.ts' to 'auth.controller.ts' and updated the reference in the router.
- Planned for implementing re-auth by current password in case of password change.
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>
A comment has been added in the category service to return the new id in the future. Currently, the implementation returns a boolean value after creating a new category, but there is a plan to update this to return the generated id.
Signed-off-by: Mathis <yidhra@tuta.io>
A new controller, category.controller.ts, has been added to handle category creation.
This includes validation to prevent the creation of duplicate categories and error handling in the event of failure to create a new category.
Issue: #12
Signed-off-by: Mathis <yidhra@tuta.io>
The return type of the createCategory function in category.service.ts has been changed from unknown to boolean. Now, the function will return true if the creation is successful, and false if an error occurs.
Signed-off-by: Mathis <yidhra@tuta.io>
Several method calls in category.service.ts were incorrectly using IDbCategory instead of Category in MysqlService. This commit fixes the naming to correctly use Category in all method calls to ensure correct function execution.
Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>
Refactor the category service by:
- Calling methods from MysqlService.IDbCategory instead of MysqlService.Category.
- Adding new methods: getById and deleteCategory with typed return and clear comments.
These changes enhances code flexibility and readability.
Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>
Update category service functions with added getBySlug function and refactor getAllCategory to getAll. Exception handling has been improved, returning null on error.
Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>
The commit updates the 'category.service.ts' file by refactoring the UUID usage. Previously, the UUID feature was imported as a whole, but now only the v4 function is imported for efficiency. It introduces a new function 'getAllCategory' to fetch all categories. This, combined with better error handling and logging, leads to improved service reliability.
Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>
A new CategoryService has been added in the services layer. This includes a function createCategory for creating a new category using IDbCategory data. Some placeholders for future features such as get, delete and retrieve by id or slug are also included.
Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>