feat: add cleanup logic for unpaid and inactive orders in whIntentSucceededHandler

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Marco Pedone 2026-05-05 14:50:06 +02:00
parent 0f335365ef
commit 3939d78039

View file

@ -100,6 +100,16 @@ export const whIntentSucceededHandler = async ({
userId: ordine.userid, userId: ordine.userid,
}); });
// cleanup ordini non pagati e non attivi per lo stesso utente, stesso tipo e servizio (es. se paga acconto, cancellare altri ordini acconto non pagati)
await trx
.deleteFrom("ordini")
.where("userid", "=", ordine.userid)
.where("isActive", "=", false)
.where("paymentstatus", "!=", paymentStatusEnum.enum.success)
.where("type", "=", ordine.type)
.where("servizio_id", "=", ordine.servizio_id)
.execute();
const lock_expires = add(new Date(), { seconds: 30 }); // Lock for 30 sec const lock_expires = add(new Date(), { seconds: 30 }); // Lock for 30 sec
switch (ordine.type) { switch (ordine.type) {