feat(branding): implement full invoice template CRUD system with default-enforcement and ownership guards#274
Open
macan88 wants to merge 3 commits intodavedumto:mainfrom
Open
feat(branding): implement full invoice template CRUD system with default-enforcement and ownership guards#274macan88 wants to merge 3 commits intodavedumto:mainfrom
macan88 wants to merge 3 commits intodavedumto:mainfrom
Conversation
…ult-enforcement and ownership guards
…ult-enforcement and ownership guards
…ult-enforcement and ownership guards
7 tasks
|
@macan88 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.
Problem
All invoices currently render with the generic LancePay default branding because the
/api/routes-d/branding/templatesroute only implemented a single-userBrandingSettingsPATCH/GET — the fullInvoiceTemplateCRUD system described in issue #240 was never built. Freelancers had no way to save, list, or apply custom branded templates to their invoices.Root Cause
The existing
route.tswas scoped toBrandingSettings(a single row per user) rather than the multi-templateInvoiceTemplateentity required by the feature. There was no POST to create templates, no PUT to update them, no per-id GET, and no schema that captured layout, accent colour, or visibility toggles.Solution
app/api/routes-d/branding/templates/route.ts— replaced the stub with full GET (list) + POST (create) + PUT (update by?id=or bodyid) handlers, all authenticated and validated via Zod.app/api/routes-d/branding/templates/[id]/route.ts— new file providing GET (single template) and DELETE, where DELETE guards against in-use templates and auto-promotes the next template to default after deletion.Both files share the same auth helper pattern already established in the codebase and use Prisma
$transactionto make the "clear old default → write new record" pair atomic.Edge Cases Handled
isDefault=truewrite path clears all other defaults for the user inside the same$transaction, so two concurrent POSTs cannot both land withisDefault=true.404(not403) regardless of whether the record exists but belongs to another user, preventing resource-existence leakage.(userId, name)is surfaced as a clean409 Conflictrather than a raw 500.409if any invoices reference the template; callers can pass?force=trueto null out those references before deleting.templateUpdateSchema(all fields optional) so callers only need to send changed fields; unchanged fields retain their current DB values.Testing
GET returns templates ordered default-first and 401 on bad tokenPOST creates template and atomically clears existing default when isDefault=truePOST returns 400 with field-level errors for invalid hex colorPUT returns 404 (not 403) for templates owned by another userPUT does not call updateMany when isDefault is absent from payloadCloses #240