From 2210280eddd6bc80390fa3db4ff3f7161c6c603c Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 25 Apr 2024 12:11:17 +0200 Subject: [PATCH] feat(services): update return types and add documentation in mysql service The return types for the 'insert' and 'update' methods in mysql.service.ts have been updated to 'Promise'. Also, detailed JSDoc comments have been added for 'insert' and 'update' methods for both User and Category entities. No functionality changes have been made. Signed-off-by: Mathis --- src/services/mysql.service.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/services/mysql.service.ts b/src/services/mysql.service.ts index 13ae6c1..69b384f 100644 --- a/src/services/mysql.service.ts +++ b/src/services/mysql.service.ts @@ -90,10 +90,10 @@ const MySqlService = { * * @param {MysqlHandler} handler - The MySQL database handler. * @param {IDbUser} data - The user data to insert. - * @returns {Promise} A promise that resolves if the user was inserted successfully, or rejects with an error. + * @returns {Promise} A promise that resolves if the user was inserted successfully, or rejects with an error. * @throws {Error} If an error occurs while executing the query. */ - insert(handler: MysqlHandler, data: IDbUser) { + insert(handler: MysqlHandler, data: IDbUser): Promise { return new Promise((resolve, reject) => { if (!data.id) return reject('Id is undefined'); if (data.id.length !== 36) return reject('Id invalid'); @@ -112,7 +112,7 @@ const MySqlService = { data.hash ] try { - resolve(handler.execute(_sql, _values)) + resolve(handler.execute(_sql, _values) as unknown) } catch (err: unknown) { reject(err as Error); } @@ -344,9 +344,15 @@ const MySqlService = { }) } }, - Category: { - insert(handler: MysqlHandler, data: IDbCategory) { + /** + * Inserts a category into the database. + * + * @param {MysqlHandler} handler - The MySQL handler object. + * @param {IDbCategory} data - The category data to be inserted. + * @return {Promise} - A promise that resolves if the insertion is successful, and rejects with an error if it fails. + */ + insert(handler: MysqlHandler, data: IDbCategory): Promise { return new Promise((resolve, reject) => { if (!data.id) return reject('Id is undefined'); if (data.id.length !== 36) return reject('Id invalid'); @@ -365,7 +371,15 @@ const MySqlService = { }) }, - update(handler: MysqlHandler, data: IDbCategory) { + /** + * Updates a category in the database. + * + * @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. + * @throws {Error} - If an error occurs during execution. + */ + update(handler: MysqlHandler, data: IDbCategory): Promise { return new Promise((resolve, reject) => { if (!data.id) return reject('Id is undefined'); if (data.id.length !== 36) return reject('Id invalid'); @@ -380,7 +394,6 @@ const MySqlService = { data.display_name, data.id ] - const _sql = `UPDATE "categories" SET ${_template} WHERE 'id' = ?`; return resolve(handler.execute(_sql, _values)); @@ -388,7 +401,8 @@ const MySqlService = { reject(err as Error); } }) - } + }, + } }