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>
This commit is contained in:
parent
0ed130f7b8
commit
b1dacb750a
@ -392,6 +392,32 @@ const MySqlService = {
|
|||||||
reject(err as Error);
|
reject(err as Error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a brand from the database.
|
||||||
|
*
|
||||||
|
* @param {MysqlHandler} handler - The MySQL handler object used to interact with the database.
|
||||||
|
* @param {string} brandId - The ID of the brand to be deleted.
|
||||||
|
*
|
||||||
|
* @return {Promise<unknown>} - A Promise that resolves with the result of the deletion operation.
|
||||||
|
* If the deletion is successful, the Promise resolves with the result.
|
||||||
|
* If an error occurs, the Promise rejects with the error.
|
||||||
|
*
|
||||||
|
* @throws {Error} If the brandId is undefined or invalid.
|
||||||
|
*/
|
||||||
|
delete(handler: MysqlHandler, brandId: string): Promise<unknown> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!brandId) return reject('Id is undefined');
|
||||||
|
if (brandId.length !== 36) return reject('Id invalid');
|
||||||
|
const _sql = "DELETE FROM `brands` WHERE `id` = ?";
|
||||||
|
const _values = [brandId];
|
||||||
|
try {
|
||||||
|
resolve(handler.execute(_sql, _values));
|
||||||
|
} catch (err: unknown) {
|
||||||
|
reject(err as Error);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Model: {
|
Model: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user