201 Commits

Author SHA1 Message Date
f23aabccd4
feat(services): add updateModel function and refine createModel function in model.service.ts
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>
2024-04-26 11:58:04 +02:00
c70bcef352
feat(services): add model service
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>
2024-04-26 11:53:42 +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
61c546459a
feat(interfaces): add IDbStatusResult interface
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>
2024-04-26 11:18:41 +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
2f4ad31edf
docs(controllers): add TODO comment for future feature in brand controller
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>
2024-04-26 10:29:07 +02:00
c25b204c67
feat(controllers): add BrandController with CRUD operations
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>
2024-04-26 10:26:38 +02:00
0a6321deb0
feat(services): mark blob validation as TODO in brand service
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>
2024-04-26 10:00:55 +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
85adbbcdb3
docs(services): add new tasks in brand.service.ts
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>
2024-04-26 09:53:27 +02:00
5c0d266002
feat(services): add deleteBrand function to brand.service.ts
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>
2024-04-26 09:52:09 +02:00
6c626e0b18
feat(services): add getByIdBrand function in brand service
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>
2024-04-26 09:41:37 +02:00
aecaf83d85
feat(services): add getBySlugBrand function in brand.service
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>
2024-04-26 09:40:24 +02:00
33d44ee4b6
feat(services): add getAllBrand function in BrandService
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>
2024-04-26 09:35:55 +02:00
90cd80e540
feat(services): add updateBrand function to BrandService
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>
2024-04-26 09:30:03 +02:00
f3bddc7170
feat(services): change IDbBrand import to explicit type import
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>
2024-04-25 16:57:39 +02:00
789d62ea62
feat(services): refactor register and login functions in UserService
- 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>
2024-04-25 16:57:21 +02:00
debb30b896
refactor(services): remove duplicate comments in category.service.ts
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>
2024-04-25 16:57:10 +02:00
6e429f4f27
feat(services): add new BrandService with createBrand function
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>
2024-04-25 16:56:50 +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
2640ebbc70
feat(controllers): add detailed comment to getBySlugCategory function
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>
2024-04-25 16:31:33 +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
f3fc63502d
feat: Replace express-xss-sanitizer with helmet
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>
2024-04-25 16:26:52 +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
dda3eea9e1
feat(interfaces): add IReqRegister interface
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>
2024-04-25 16:06:33 +02:00
a430044d95
feat(interfaces): add IReqLogin interface
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>
2024-04-25 16:06:02 +02:00
6c601e0b42
feat(app): add helmet for XSS protection
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>
2024-04-25 15:56:48 +02:00
3ee76fb965
feat(routes): add CategoryController to category routes
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>
2024-04-25 15:19:50 +02:00
8b306e9a31
build(package): add uuid to dependencies
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>
2024-04-25 15:03:08 +02:00
62cb05cb33
feat(controllers): add delete and getBySlug methods in category controller
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>
2024-04-25 15:02:46 +02:00
da001bf7cc
docs(services): add test markers to credential functions
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>
2024-04-25 14:54:17 +02:00
cd51a04aba
feat(controllers): add getAllCategory function in category controller
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>
2024-04-25 14:52:42 +02:00
bd80518b5f
refactor(controllers): remove unused import in category.controller
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>
2024-04-25 14:44:24 +02:00
ab3b3c9cf5
feat(services): add updateCategory functionality in category.service
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>
2024-04-25 14:43:41 +02:00
56a1722412
feat(controllers): add update category functionality in category controller
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>
2024-04-25 14:42:42 +02:00
36ad90eda6
feat(controllers): Refactor AuthController and update router reference
- 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>
2024-04-25 14:23:13 +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
a582f8c431
docs(services): add comment for future improvement in category service
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>
2024-04-25 14:22:02 +02:00
23116f4345
feat(controllers): add category creation functionality
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>
2024-04-25 14:21:24 +02:00
4a9bc402b4
feat(services): change return type in createCategory function
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>
2024-04-25 14:11:15 +02:00
f3cd6c5985
fix(services): correct MysqlService method calls in category.service.ts
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>
2024-04-25 14:00:07 +02:00
325c6ec6a0
feat(services): update methods in category service
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>
2024-04-25 13:55:55 +02:00
11be3a40c3
feat(services): update category service functions
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>
2024-04-25 13:50:45 +02:00
3d3bc8580a
feat(services): update category.service with improved UUID usage and new function
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>
2024-04-25 13:46:08 +02:00
38b6b05190
feat(services): add CategoryService with createCategory function
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>
2024-04-25 13:33:09 +02:00