feat(services): update getAvailable method in mysql.service

- Transform `getAvailable` method into a promise that retrieves available vehicles from the database.
- This method now takes the MySQL handler object to execute the query and returns a promise that resolves to an array of available vehicles.
- It also handles error while executing the query.

Issue: #20
Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-29 13:38:15 +02:00
parent 89d9fc47b2
commit 9a6d7a73b2
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -687,20 +687,23 @@ const MySqlService = {
});
},
//TODO get available
getAvailable(handler: MysqlHandler, data: IDbVehicle) {
/**
* Retrieves the available vehicles from the database.
*
* @param {MysqlHandler} handler - The MySQL handler object used to execute the query.
* @returns {Promise<Array<IDbVehicle>>} A promise that resolves to an array of available vehicles.
* @throws {Error} If an error occurs while executing the query.
*/
getAvailable(handler: MysqlHandler): Promise<Array<IDbVehicle>> {
return new Promise((resolve, reject) => {
})
},
//TODO get out of due date
getDue(handler: MysqlHandler, data: IDbVehicle) {
return new Promise((resolve, reject) => {
const _sql = "SELECT * FROM `vehicles` WERE `isAvailable` = 1";
try {
resolve(handler.query(_sql) as unknown as Array<IDbVehicle>);
} catch (err: unknown) {
reject(err as Error);
}
})
}
},
Category: {
/**