diff --git a/src/services/mysql.service.ts b/src/services/mysql.service.ts index cdd5bff..15c596c 100644 --- a/src/services/mysql.service.ts +++ b/src/services/mysql.service.ts @@ -392,6 +392,32 @@ const MySqlService = { 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} - 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 { + 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: {