From 44b5745f3b79245ba1fae497584f9a1820257a64 Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 30 Apr 2024 09:59:06 +0200 Subject: [PATCH] feat(services): update insert function in mysql service The `insert` function in mysql service has been updated. The function now includes more accurate commenting, and a check for `id` validity. It now returns a Promise with `IDbStatusResult` instead of `unknown`. The changes improve function clarity and error handling. Issue: #17 Signed-off-by: Mathis --- src/services/mysql.service.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/services/mysql.service.ts b/src/services/mysql.service.ts index 6436ef2..cd379b9 100644 --- a/src/services/mysql.service.ts +++ b/src/services/mysql.service.ts @@ -92,14 +92,15 @@ const MySqlService = { User: { /** - * Insert a user into the database. + * Inserts a new user into the database. * * @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. - * @throws {Error} If an error occurs while executing the query. + * @returns {Promise} A promise that resolves with the database status result. + * @throws {Error} If an error occurs during the execution. + * @throws {string} If the `id` field is undefined or invalid. */ - insert(handler: MysqlHandler, data: IDbUser): Promise { + 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'); @@ -118,7 +119,7 @@ const MySqlService = { data.hash ] try { - resolve(handler.execute(_sql, _values) as unknown) + resolve(handler.execute(_sql, _values) as unknown as IDbStatusResult) } catch (err: unknown) { reject(err as Error); }