feat: enhance getCompatibileAnnunci query to include additional delivery month conditions
This commit is contained in:
parent
d6cd5f86b8
commit
6a20a7fb36
1 changed files with 26 additions and 14 deletions
|
|
@ -1311,21 +1311,33 @@ export const getCompatibileAnnunci = async ({
|
|||
}
|
||||
|
||||
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
|
||||
if (servizio.entromese === month) {
|
||||
if (entromese !== null) {
|
||||
if (entromese === month) {
|
||||
qry = qry.where((eb) =>
|
||||
eb.or([
|
||||
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) =>
|
||||
eb.or([eb("consegna", "=", 0), eb("consegna", "=", month)]),
|
||||
eb.or([
|
||||
eb("consegna", "=", 0),
|
||||
eb("consegna", "=", month),
|
||||
eb("consegna", "=", month + 1),
|
||||
]),
|
||||
);
|
||||
} else {
|
||||
qry = qry.where("consegna", "=", servizio.entromese);
|
||||
qry = qry.where((eb) =>
|
||||
eb.or([
|
||||
eb("consegna", "=", entromese),
|
||||
eb("consegna", "=", entromese + 1),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return await qry.execute();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue