From 44b04459fb3b68f09915542bdb1c1657d6f05712 Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 25 Apr 2024 16:26:29 +0200 Subject: [PATCH] feat(services): add detailed comments and specify return types in mysql.service In the `mysql.service`, this commit adds detailed doc-block comments for `insert` and `update` functions under `Brand` and `Category`. Additionally, the return types of the `update` functions under `Brand` and `Category` are now specifically defined as `Promise`, providing clarity on the expected returns. Issue: #5 Signed-off-by: Mathis --- src/services/mysql.service.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/services/mysql.service.ts b/src/services/mysql.service.ts index 56e60a4..07c919f 100644 --- a/src/services/mysql.service.ts +++ b/src/services/mysql.service.ts @@ -271,7 +271,15 @@ const MySqlService = { } }, Brand: { - insert(handler: MysqlHandler, data: IDbBrand) { + /** + * Inserts a record into the `brands` table. + * + * @param {MysqlHandler} handler - The MySQL handler instance. + * @param {IDbBrand} data - The data object representing the record to be inserted. + * @returns {Promise} A promise that resolves with the result of the insertion. + * The promise is rejected with an error if the insertion fails. + */ + insert(handler: MysqlHandler, data: IDbBrand): Promise { return new Promise((resolve, reject) => { if (!data.id) return reject('Id is undefined'); if (data.id.length !== 36) return reject('Id invalid'); @@ -290,7 +298,14 @@ const MySqlService = { } }) }, - update(handler: MysqlHandler, data: IDbBrand) { + /** + * Updates a brand in the database. + * @param {MysqlHandler} handler - The MySQL handler. + * @param {IDbBrand} data - The brand data to be updated. + * @returns {Promise} - A promise that resolves with the number of affected rows in the database. + * @throws {Error} - If an error occurs during the update process. + */ + update(handler: MysqlHandler, data: IDbBrand): Promise { return new Promise((resolve, reject) => { if (!data.id) return reject('Id is undefined'); if (data.id.length !== 36) return reject('Id invalid'); @@ -308,7 +323,7 @@ const MySqlService = { data.id ] const _sql = `UPDATE "brands" SET ${_template} WHERE 'id' = ?`; - return resolve(handler.execute(_sql, _values)); + return resolve(handler.execute(_sql, _values) as unknown as number); } catch (err: unknown) { reject(err as Error); @@ -423,7 +438,7 @@ const MySqlService = { * * @param {MysqlHandler} handler - The MySQL handler instance. * @param {IDbCategory} data - The category data to update. - * @returns {Promise} - A Promise that resolves with the result of the UPDATE query execution. + * @returns {Promise} - A promise that resolves with the number of affected rows in the database. * @throws {Error} - If an error occurs during execution. */ update(handler: MysqlHandler, data: IDbCategory): Promise { @@ -442,7 +457,7 @@ const MySqlService = { data.id ] const _sql = `UPDATE "categories" SET ${_template} WHERE 'id' = ?`; - return resolve(handler.execute(_sql, _values)); + return resolve(handler.execute(_sql, _values) as unknown as number); } catch (err: unknown) { reject(err as Error);