feat(services): add getAll function to mysql service
This commit adds a new `getAll` function in the `mysql.service.ts` file, which retrieves all categories from the database. It executes a SQL query and includes error handling that either resolves with an array of category objects or rejects with an Error object. BREAKING-CHANGE: #6 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
2210280edd
commit
02383b8c8a
@ -402,7 +402,25 @@ const MySqlService = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Retrieves all categories from the database.
|
||||||
|
*
|
||||||
|
* @param {MysqlHandler} handler - The MySQL handler used for executing the query.
|
||||||
|
*
|
||||||
|
* @return {Promise<Array<IDbCategory>>} - A promise that resolves with an array of category objects from the database.
|
||||||
|
* - The category objects are of type IDbCategory.
|
||||||
|
* - If an error occurs, the promise will be rejected with an Error object.
|
||||||
|
*/
|
||||||
|
getAll(handler: MysqlHandler) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const _sql = "SELECT * FROM `categories`";
|
||||||
|
try {
|
||||||
|
resolve(handler.query(_sql) as unknown as Array<IDbCategory>);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
reject(err as Error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user