Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
import { z } from 'zod';
|
2026-05-06 14:56:59 +02:00
|
|
|
import { baseListQuerySchema } from '@/lib/api/list-query';
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
|
2026-05-02 00:01:33 +02:00
|
|
|
export const INVOICE_KINDS = ['general', 'deposit'] as const;
|
|
|
|
|
export type InvoiceKind = (typeof INVOICE_KINDS)[number];
|
|
|
|
|
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
export const createInvoiceSchema = z
|
|
|
|
|
.object({
|
2026-04-24 16:02:00 +02:00
|
|
|
billingEntity: z.object({
|
|
|
|
|
type: z.enum(['client', 'company']),
|
|
|
|
|
id: z.string().min(1),
|
|
|
|
|
}),
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
billingEmail: z.string().email().optional(),
|
|
|
|
|
billingAddress: z.string().max(500).optional(),
|
|
|
|
|
dueDate: z.string().min(1),
|
|
|
|
|
paymentTerms: z
|
|
|
|
|
.enum(['immediate', 'net10', 'net15', 'net30', 'net45', 'net60'])
|
|
|
|
|
.default('net30'),
|
|
|
|
|
currency: z.string().length(3).default('USD'),
|
|
|
|
|
notes: z.string().max(2000).optional(),
|
2026-05-02 00:01:33 +02:00
|
|
|
/** Optional link to a sales interest. Required when kind === 'deposit'. */
|
|
|
|
|
interestId: z.string().min(1).optional(),
|
|
|
|
|
kind: z.enum(INVOICE_KINDS).default('general'),
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
lineItems: z
|
|
|
|
|
.array(
|
|
|
|
|
z.object({
|
|
|
|
|
description: z.string().min(1),
|
|
|
|
|
quantity: z.coerce.number().positive().default(1),
|
|
|
|
|
unitPrice: z.coerce.number().min(0),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.optional(),
|
|
|
|
|
expenseIds: z.array(z.string()).optional(),
|
|
|
|
|
})
|
2026-05-02 00:01:33 +02:00
|
|
|
.refine((data) => data.kind !== 'deposit' || !!data.interestId, {
|
|
|
|
|
message: 'Deposit invoices must be linked to an interest',
|
|
|
|
|
path: ['interestId'],
|
|
|
|
|
})
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
.refine(
|
|
|
|
|
(data) =>
|
|
|
|
|
(data.lineItems && data.lineItems.length > 0) ||
|
|
|
|
|
(data.expenseIds && data.expenseIds.length > 0),
|
|
|
|
|
{ message: 'Invoice must have at least one line item or linked expense' },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const updateInvoiceSchema = z.object({
|
|
|
|
|
clientName: z.string().min(1).max(200).optional(),
|
|
|
|
|
billingEmail: z.string().email().optional(),
|
|
|
|
|
billingAddress: z.string().max(500).optional(),
|
|
|
|
|
dueDate: z.string().min(1).optional(),
|
2026-04-24 16:02:00 +02:00
|
|
|
paymentTerms: z.enum(['immediate', 'net10', 'net15', 'net30', 'net45', 'net60']).optional(),
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
currency: z.string().length(3).optional(),
|
|
|
|
|
notes: z.string().max(2000).optional(),
|
2026-05-02 00:01:33 +02:00
|
|
|
interestId: z.string().min(1).nullable().optional(),
|
|
|
|
|
kind: z.enum(INVOICE_KINDS).optional(),
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
lineItems: z
|
|
|
|
|
.array(
|
|
|
|
|
z.object({
|
|
|
|
|
description: z.string().min(1),
|
|
|
|
|
quantity: z.coerce.number().positive().default(1),
|
|
|
|
|
unitPrice: z.coerce.number().min(0),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.optional(),
|
|
|
|
|
expenseIds: z.array(z.string()).optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const recordPaymentSchema = z.object({
|
|
|
|
|
paymentDate: z.string().min(1),
|
|
|
|
|
paymentMethod: z.string().optional(),
|
|
|
|
|
paymentReference: z.string().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const listInvoicesSchema = baseListQuerySchema.extend({
|
|
|
|
|
status: z.string().optional(),
|
|
|
|
|
clientName: z.string().optional(),
|
|
|
|
|
dateFrom: z.string().optional(),
|
|
|
|
|
dateTo: z.string().optional(),
|
2026-04-24 16:02:00 +02:00
|
|
|
billingEntityType: z.enum(['client', 'company']).optional(),
|
|
|
|
|
billingEntityId: z.string().optional(),
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
});
|
|
|
|
|
|
2026-05-02 00:01:33 +02:00
|
|
|
// `z.input` keeps fields with `.default()` (paymentTerms, currency, kind)
|
feat(deps): bump zod 3→4 + @hookform/resolvers 3→5
Resolved 65 type errors across the codebase via these v4 migration
patterns:
- `ZodError.errors` renamed to `ZodError.issues` (4 call sites in auth
routes + central error handler).
- `z.record(value)` now requires explicit key type: `z.record(z.string(),
value)`. Updated 7 sites across templates / forms / saved-views /
website-inquiries.
- `.refine(check, msgFn)` second-arg shape changed — now requires an
`{ error: (issue) => ... }` object form. Updated
`mergeFieldsSchema` in document-templates validator.
- `.transform(...).default(...)` chains: v4 enforces default value type
matches transform OUTPUT. Reordered to `.default(...).transform(...)`
in list-query / company-memberships handlers.
- `z.coerce.*()` INPUT type widened to `unknown` in v4. Service signatures
using `z.input<typeof schema>` (kept for caller flexibility around
defaults) now re-parse via `schema.parse(data)` to recover the
post-coercion shape Drizzle needs. Done in berth-reservations service.
Invoice service narrows `lineItems` locally with a typed cast since
re-parsing would double-validate.
- `.optional().transform(...)` no longer propagates the optional marker
through v4's new ZodPipe. Moved `.optional()` to the END of chain in
`optionalDesiredDimSchema` (interests) and documents list query
(folderId, signatureOnly).
- ZodIssue subtype shapes simplified: `received` removed from
invalid_type, `type` renamed to `origin` on too_small. Test fixtures
updated.
- @hookform/resolvers v5 splits Resolver into 3-generic form (Input,
Context, Output). useForm calls in 6 forms (client, yacht, berth,
interest, expense, invoices-new-page) now pass explicit generics:
`useForm<z.input<typeof schema>, unknown, z.infer<typeof schema>>`.
Verified: tsc clean (0 errors), vitest 1293/1293 pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 18:29:03 +02:00
|
|
|
// optional from the caller's perspective. The route layer runs the
|
|
|
|
|
// schema through `parseBody`, so the service body can rely on those
|
|
|
|
|
// defaults being present at runtime — narrow with a local cast where
|
|
|
|
|
// the post-parse shape matters (e.g. coerced `unitPrice` is `number`).
|
2026-05-02 00:01:33 +02:00
|
|
|
export type CreateInvoiceInput = z.input<typeof createInvoiceSchema>;
|
|
|
|
|
export type UpdateInvoiceInput = z.input<typeof updateInvoiceSchema>;
|
feat(deps): bump zod 3→4 + @hookform/resolvers 3→5
Resolved 65 type errors across the codebase via these v4 migration
patterns:
- `ZodError.errors` renamed to `ZodError.issues` (4 call sites in auth
routes + central error handler).
- `z.record(value)` now requires explicit key type: `z.record(z.string(),
value)`. Updated 7 sites across templates / forms / saved-views /
website-inquiries.
- `.refine(check, msgFn)` second-arg shape changed — now requires an
`{ error: (issue) => ... }` object form. Updated
`mergeFieldsSchema` in document-templates validator.
- `.transform(...).default(...)` chains: v4 enforces default value type
matches transform OUTPUT. Reordered to `.default(...).transform(...)`
in list-query / company-memberships handlers.
- `z.coerce.*()` INPUT type widened to `unknown` in v4. Service signatures
using `z.input<typeof schema>` (kept for caller flexibility around
defaults) now re-parse via `schema.parse(data)` to recover the
post-coercion shape Drizzle needs. Done in berth-reservations service.
Invoice service narrows `lineItems` locally with a typed cast since
re-parsing would double-validate.
- `.optional().transform(...)` no longer propagates the optional marker
through v4's new ZodPipe. Moved `.optional()` to the END of chain in
`optionalDesiredDimSchema` (interests) and documents list query
(folderId, signatureOnly).
- ZodIssue subtype shapes simplified: `received` removed from
invalid_type, `type` renamed to `origin` on too_small. Test fixtures
updated.
- @hookform/resolvers v5 splits Resolver into 3-generic form (Input,
Context, Output). useForm calls in 6 forms (client, yacht, berth,
interest, expense, invoices-new-page) now pass explicit generics:
`useForm<z.input<typeof schema>, unknown, z.infer<typeof schema>>`.
Verified: tsc clean (0 errors), vitest 1293/1293 pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 18:29:03 +02:00
|
|
|
export type CreateInvoiceParsed = z.infer<typeof createInvoiceSchema>;
|
|
|
|
|
export type UpdateInvoiceParsed = z.infer<typeof updateInvoiceSchema>;
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
export type RecordPaymentInput = z.infer<typeof recordPaymentSchema>;
|
|
|
|
|
export type ListInvoicesInput = z.infer<typeof listInvoicesSchema>;
|