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 <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-25 16:29:39 +02:00
parent f3fc63502d
commit a992868eb6
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -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<Array<IDbBrand>>} 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<Array<IDbBrand>> {
return new Promise((resolve, reject) => {
const _sql = "SELECT * FROM `brands`";
try {
resolve(handler.query(_sql) as unknown as Array<IDbBrand>);
} catch (err: unknown) {
reject(err as Error);
}
})
}
},
Model: {