From a992868eb68e48ec777da075690e59a81bd54550 Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 25 Apr 2024 16:29:39 +0200 Subject: [PATCH] feat(services): add 'getAll' function to mysql.service.ts A new function named `getAll` has been added to `mysql.service.ts`. This function is designed to retrieve all records from the `brands` table. It returns a promise that resolves to an array of `IDbBrand` objects representing the retrieved records. Issue: #5 Signed-off-by: Mathis --- src/services/mysql.service.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/services/mysql.service.ts b/src/services/mysql.service.ts index 07c919f..5869e8f 100644 --- a/src/services/mysql.service.ts +++ b/src/services/mysql.service.ts @@ -298,6 +298,7 @@ const MySqlService = { } }) }, + /** * Updates a brand in the database. * @param {MysqlHandler} handler - The MySQL handler. @@ -329,8 +330,25 @@ const MySqlService = { reject(err as Error); } }) - } + }, + /** + * Retrieves all records from the `brands` table. + * + * @param {MysqlHandler} handler - The MySQL handler object to execute the query. + * + * @return {Promise>} A promise that resolves to an array of IDbBrand objects representing the retrieved records. If an error occurs during the query execution, the promise will be rejected with an Error object. + */ + getAll(handler: MysqlHandler): Promise> { + return new Promise((resolve, reject) => { + const _sql = "SELECT * FROM `brands`"; + try { + resolve(handler.query(_sql) as unknown as Array); + } catch (err: unknown) { + reject(err as Error); + } + }) + } }, Model: {