Compare commits

...

4 Commits

Author SHA1 Message Date
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
3 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,4 @@
export interface IReqLogin {
username: string;
password: string;
}

View File

@ -0,0 +1,8 @@
export interface IReqRegister {
username: string;
displayName: string;
firstName: string;
lastName: string;
password: string;
gdpr?: boolean;
}

View File

@ -1,6 +1,7 @@
import type IDbCategory from "@interfaces/database/IDbCategory";
import type {IDbCategory} from "@interfaces/database/IDbCategory";
import type {IDbModel} from "@interfaces/database/IDbModel";
import type {IDbUser} from "@interfaces/database/IDbUser";
import type {IDbBrand} from "@interfaces/database/IDbBrand";
import mysql, {type Connection, type ConnectionOptions} from 'mysql2';
import {Logger} from "tslog";
@ -269,7 +270,28 @@ const MySqlService = {
});
}
},
Brand: {
insert(handler: MysqlHandler, data: IDbBrand) {
return new Promise((resolve, reject) => {
if (!data.id) return reject('Id is undefined');
if (data.id.length !== 36) return reject('Id invalid');
const _sql = "INSERT INTO `brands`(`id`,`display_name`, `slug_name`, `image_blob`) VALUES (?, ?, ?, ?)"
const _values = [
data.id,
data.display_name,
data.slug_name,
data.image_blob
]
try {
resolve(handler.execute(_sql, _values))
} catch (err: unknown) {
reject(err as Error);
}
})
}
},
Model: {
/**
@ -357,7 +379,7 @@ const MySqlService = {
if (!data.id) return reject('Id is undefined');
if (data.id.length !== 36) return reject('Id invalid');
const _sql = "INSERT INTO `categorys`(`id`,`slug_name`, `display_name`) VALUES (?, ?, ?)"
const _sql = "INSERT INTO `categories`(`id`,`slug_name`, `display_name`) VALUES (?, ?, ?)"
const _values = [
data.id,
data.slug_name,