fix: use await to wait for map

This commit is contained in:
Nemo D'ACREMONT 2024-11-27 16:01:03 +01:00
parent 2c01512c53
commit 24a12ea3b1
No known key found for this signature in database
GPG Key ID: 6E5BCE8022FA8276

View File

@ -58,9 +58,11 @@ const getBox = async (idOrTitle: number | string): Promise<Either<Box, string>>
const getAllBoxes = async () => {
const client = new_client();
await client.connect();
const res = await client.query("SELECT * FROM boites");
await client.end();
return res.rows.map(db2box);
return await Promise.all(res.rows.map(async (el) => { return await db2box(el) }));
}
const getAllBoxesFromDate = async (date: Date) => {
@ -73,8 +75,9 @@ const getAllBoxesFromDate = async (date: Date) => {
const dateString = `${YYYY}-${MM}-${DD}`;
const res = await client.query("SELECT * FROM boites WHERE date_boite > $1", [dateString]);
await client.end();
return res.rows.map(db2box);
return await Promise.all(res.rows.map(async (el) => { return await db2box(el) }));
}
const boxService = {