Skip to content

feat(routes-b): invoice templates, quote conversion, discount deletion - #1369

Merged
davedumto merged 1 commit into
davedumto:mainfrom
iduhtheman:fix/lancepay-invoice-templates-quote-convert-discount-delete
Aug 27, 2026
Merged

feat(routes-b): invoice templates, quote conversion, discount deletion#1369
davedumto merged 1 commit into
davedumto:mainfrom
iduhtheman:fix/lancepay-invoice-templates-quote-convert-discount-delete

Conversation

@iduhtheman

Copy link
Copy Markdown
Contributor

Summary

Adds four routes-b API routes:

  • GET /api/routes-b/invoices/templates/[id] — fetch a single invoice template, ownership-checked
  • GET/POST /api/routes-b/invoices/templates — list and create invoice templates, unique per (userId, name)
  • POST /api/routes-b/quotes/[id]/convert — convert a quote into a real invoice (creates the Invoice via the same generateInvoiceNumber()/paymentLink convention as POST /api/invoices, marks the quote converted, links it to the new invoice); rejects quotes that are already converted, declined, or expired
  • DELETE /api/routes-b/discounts/[id] — delete a discount code, ownership-checked

Adds Quote and InvoiceTemplate Prisma models plus a migration — neither existed in the schema before this PR.

closes #915
closes #914
closes #913
closes #910

⚠️ Also fixes a real pre-existing bug found while building this

While adding Quote's back-relation to Invoice, npx prisma generate failed with a schema validation error I traced back to the Refund model (merged in #1362): it was missing its closing } brace in schema.prisma. This silently swallowed two additional relation-completeness errors — Refund.invoice and InvoicePublicLink.invoice both reference Invoice but had no opposite relation field declared on Invoice itself.

Net effect: npx prisma generate has been failing on upstream/main since #1362 merged. Any code path touching prisma.refund.* would not typecheck/compile. This PR fixes the schema (closing brace + the two missing back-relation fields) so it validates and generates cleanly again.

Reassuring part: the actual SQL migration for Refund (20260826080000_add_discount_refund_models) was already correct — both foreign keys are present at the database level. This was purely a Prisma-schema-level bug, not a data-integrity issue.

Test plan

  • npx prisma generate — now succeeds (previously failed with a schema validation error)
  • vitest run on the 4 new route test files — 36/36 passing
  • Ran the broader routes-b/{discounts,invoices,quotes,credit-notes} test scope for a regression check — the only failures present (invoices/[id]/allocations, client, amount, collaborators/notify, regenerate-pdf, payment-methods, summaries/yearly) are in files this PR doesn't touch and were already failing before this PR (confirmed by inspection — e.g. allocations's failure is a params destructuring bug in its own test file, unrelated to the schema fix)

Adds four routes-b API routes:

- GET /api/routes-b/invoices/templates/[id] — fetch a single invoice
  template, ownership-checked (davedumto#915)
- GET/POST /api/routes-b/invoices/templates — list and create invoice
  templates, unique per user+name (davedumto#914)
- POST /api/routes-b/quotes/[id]/convert — convert a quote into a real
  invoice (creates the Invoice via the same generateInvoiceNumber()/
  paymentLink convention as POST /api/invoices, marks the quote
  "converted" and links it to the new invoice); rejects quotes that are
  already converted, declined, or expired (davedumto#913)
- DELETE /api/routes-b/discounts/[id] — delete a discount code,
  ownership-checked (davedumto#910)

Adds Quote and InvoiceTemplate Prisma models plus a migration —
neither existed in the schema before.

closes davedumto#915
closes davedumto#914
closes davedumto#913
closes davedumto#910

---

Also fixes a real, pre-existing bug found while working on this: the
Refund model (merged in davedumto#1362) was missing its closing brace in
schema.prisma, silently swallowing two relation-completeness errors
(Refund.invoice and InvoicePublicLink.invoice both had no opposite
relation field on Invoice). `npx prisma generate` has been failing on
upstream/main since that merge — this fixes the schema so it validates
and generates cleanly again. The underlying SQL migration was already
correct (both foreign keys present), so no data-level issue, but any
code path touching prisma.refund.* would not have typechecked/compiled.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@iduhtheman Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@iduhtheman is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

@davedumto
davedumto merged commit a025ce4 into davedumto:main Aug 27, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment