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>
This commit is contained in:
parent
01241dff4b
commit
016f7fa9d4
@ -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: {
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user