feat: enhance getCompatibileAnnunci query to include additional delivery month conditions

This commit is contained in:
Marco Pedone 2026-03-20 14:16:03 +01:00
parent d6cd5f86b8
commit 6a20a7fb36

View file

@ -1311,21 +1311,33 @@ export const getCompatibileAnnunci = async ({
} }
qry = qry.where("prezzo", "<=", servizio.budget * 1e2 * 1.2); // Allow 20% margin qry = qry.where("prezzo", "<=", servizio.budget * 1e2 * 1.2); // Allow 20% margin
const { entromese } = servizio;
const month = new Date().getMonth() + 1; // Months are 0-indexed in JS const month = new Date().getMonth() + 1; // Months are 0-indexed in JS
if (servizio.entromese === month) { if (entromese !== null) {
if (entromese === month) {
qry = qry.where((eb) => qry = qry.where((eb) =>
eb.or([ eb.or([
eb("consegna", "=", 0), eb("consegna", "=", 0),
eb("consegna", "=", servizio.entromese), eb("consegna", "=", entromese),
eb("consegna", "=", entromese + 1),
]), ]),
); );
} else if (servizio.entromese === 0) { } else if (entromese === 0) {
qry = qry.where((eb) => qry = qry.where((eb) =>
eb.or([eb("consegna", "=", 0), eb("consegna", "=", month)]), eb.or([
eb("consegna", "=", 0),
eb("consegna", "=", month),
eb("consegna", "=", month + 1),
]),
); );
} else { } else {
qry = qry.where("consegna", "=", servizio.entromese); qry = qry.where((eb) =>
eb.or([
eb("consegna", "=", entromese),
eb("consegna", "=", entromese + 1),
]),
);
}
} }
return await qry.execute(); return await qry.execute();