feat(vendors): auto-verify vendor on first successful payment

When accounts confirms a payment (SENT_FOR_PAYMENT → PAID_DELIVERED),
set Vendor.isVerified = true for the PO's vendor. The field already
exists in the schema (default false); this closes the loop so vendors
who have transacted at least once are marked verified automatically
without manual admin intervention.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Hardik 2026-05-16 21:11:25 +05:30
parent a5fb7d088c
commit 891e854c7c

View file

@ -169,6 +169,14 @@ export async function markPaid({
// Sync product catalog: auto-create new items, upsert per-vendor prices // Sync product catalog: auto-create new items, upsert per-vendor prices
await syncProductCatalog(poId, po.lineItems, po.vendorId, session.user.id); await syncProductCatalog(poId, po.lineItems, po.vendorId, session.user.id);
// Auto-verify the vendor on first successful payment
if (po.vendorId) {
await db.vendor.update({
where: { id: po.vendorId },
data: { isVerified: true },
});
}
const managers = await db.user.findMany({ where: { role: "MANAGER", isActive: true } }); const managers = await db.user.findMany({ where: { role: "MANAGER", isActive: true } });
await notify({ event: "PAYMENT_SENT", po, recipients: [po.submitter, ...managers] }); await notify({ event: "PAYMENT_SENT", po, recipients: [po.submitter, ...managers] });