feat(routes-b): invoice templates, quote conversion, discount deletion - #1369
Merged
davedumto merged 1 commit intoAug 27, 2026
Conversation
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.
|
@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! 🚀 |
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds four
routes-bAPI routes:GET /api/routes-b/invoices/templates/[id]— fetch a single invoice template, ownership-checkedGET/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 theInvoicevia the samegenerateInvoiceNumber()/paymentLinkconvention asPOST /api/invoices, marks the quoteconverted, links it to the new invoice); rejects quotes that are already converted, declined, or expiredDELETE /api/routes-b/discounts/[id]— delete a discount code, ownership-checkedAdds
QuoteandInvoiceTemplatePrisma models plus a migration — neither existed in the schema before this PR.closes #915
closes #914
closes #913
closes #910
While adding
Quote's back-relation toInvoice,npx prisma generatefailed with a schema validation error I traced back to theRefundmodel (merged in #1362): it was missing its closing}brace inschema.prisma. This silently swallowed two additional relation-completeness errors —Refund.invoiceandInvoicePublicLink.invoiceboth referenceInvoicebut had no opposite relation field declared onInvoiceitself.Net effect:
npx prisma generatehas been failing onupstream/mainsince #1362 merged. Any code path touchingprisma.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 runon the 4 new route test files — 36/36 passingroutes-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 aparamsdestructuring bug in its own test file, unrelated to the schema fix)