Compare commits
3 Commits
a992868eb6
...
0ed130f7b8
Author | SHA1 | Date | |
---|---|---|---|
0ed130f7b8 | |||
50c1ff797f | |||
2640ebbc70 |
@ -118,7 +118,15 @@ async function getAllCategory(res: Response): Promise<Response> {
|
||||
});
|
||||
}
|
||||
|
||||
async function getBySlugCategory(req: Request, res:Response) {
|
||||
/**
|
||||
* Get category by slug
|
||||
*
|
||||
* @param {Request} req - The request object containing category slug
|
||||
* @param {Response} res - The response object to send back the category
|
||||
*
|
||||
* @return {Promise<Response>} - The response with category data or error message
|
||||
*/
|
||||
async function getBySlugCategory(req: Request, res:Response): Promise<Response> {
|
||||
const categorySlug = req.params["categorySlug"];
|
||||
if (!categorySlug) {
|
||||
logger.error("Category slug is missing");
|
||||
|
@ -348,6 +348,50 @@ const MySqlService = {
|
||||
reject(err as Error);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetches a category by its Id
|
||||
*
|
||||
* @param {MysqlHandler} handler - The instance of the MysqlHandler used for executing the query
|
||||
* @param {string} brandId - The Id of the category to be fetched
|
||||
* @return {Promise<IDbBrand>} - A promise that, when resolved, returns the category matching the Id
|
||||
* @throws {Error} - If an error occurs during execution
|
||||
* @throws {string} - If brandId is undefined or invalid
|
||||
*/
|
||||
getById(handler: MysqlHandler, brandId: string): Promise<IDbBrand> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!brandId) return reject('slug is undefined')
|
||||
if (brandId.length !== 36) return reject('Id invalid');
|
||||
const _sql = "SELECT * FROM `brands` WHERE `id` = ?";
|
||||
const _values = [brandId];
|
||||
try {
|
||||
resolve(handler.execute(_sql, _values) as unknown as IDbBrand);
|
||||
} catch (err: unknown) {
|
||||
//TODO Reject with null and logger error
|
||||
reject(err as Error);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves a brand from the database by its slug.
|
||||
*
|
||||
* @param {MysqlHandler} handler - The MySQL handler object used to connect to the database.
|
||||
* @param {string} brandSlug - The slug of the brand to retrieve.
|
||||
* @returns {Promise<IDbBrand>} - A promise that resolves with the brand object if found, or rejects with an error message.
|
||||
*/
|
||||
getBySlug(handler: MysqlHandler, brandSlug: string): Promise<IDbBrand> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!brandSlug) return reject('slug is undefined')
|
||||
const _sql = "SELECT * FROM `brands` WHERE `slug_name` = ?";
|
||||
const _values = [brandSlug];
|
||||
try {
|
||||
resolve(handler.execute(_sql, _values) as unknown as IDbBrand);
|
||||
} catch (err: unknown) {
|
||||
reject(err as Error);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
Model: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user