Phase 2a: Prisma schema + shared schemas for v1.0 features
- New models: Attachment, Webhook, Notification, SavedView - New fields: User.notificationPrefs (Json), indexes on Ticket - post-push.sql manages the tsvector columns + GIN indexes + triggers for FTS on Ticket (title/overview/displayId) and Comment (body); Prisma can't express these - package.json scripts: db:push and start:prod now chain `prisma db execute` against post-push.sql after `prisma db push` - db:migrate script removed — project uses push workflow, not migrations - Shared Zod schemas: attachment (25MB limit + mimetype allowlist), savedView, notification (prefs, mark-read, webhook CRUD) - Shared type additions: Attachment, Notification, SavedView, Webhook, PaginatedResponse<T> - Test fixtures updated for the new User.notificationPrefs column Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ATTACHMENT_MAX_BYTES = 25 * 1024 * 1024;
|
||||
|
||||
export const ATTACHMENT_MIME_ALLOWLIST = [
|
||||
'image/png',
|
||||
'image/jpeg',
|
||||
'image/gif',
|
||||
'image/webp',
|
||||
'image/svg+xml',
|
||||
'application/pdf',
|
||||
'application/zip',
|
||||
'application/json',
|
||||
'application/x-yaml',
|
||||
'text/plain',
|
||||
'text/csv',
|
||||
'text/markdown',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'application/msword',
|
||||
'application/vnd.ms-excel',
|
||||
'application/octet-stream',
|
||||
];
|
||||
|
||||
export const attachmentTargetSchema = z.object({
|
||||
ticketId: z.string().cuid().optional(),
|
||||
commentId: z.string().cuid().optional(),
|
||||
});
|
||||
@@ -4,3 +4,6 @@ export * from './ticket';
|
||||
export * from './comment';
|
||||
export * from './user';
|
||||
export * from './cti';
|
||||
export * from './attachment';
|
||||
export * from './savedView';
|
||||
export * from './notification';
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const notificationPrefsSchema = z.object({
|
||||
email: z
|
||||
.object({
|
||||
assignment: z.boolean().default(true),
|
||||
mention: z.boolean().default(true),
|
||||
resolved: z.boolean().default(false),
|
||||
})
|
||||
.default({}),
|
||||
inApp: z
|
||||
.object({
|
||||
assignment: z.boolean().default(true),
|
||||
mention: z.boolean().default(true),
|
||||
resolved: z.boolean().default(true),
|
||||
})
|
||||
.default({}),
|
||||
});
|
||||
|
||||
export const markReadSchema = z.object({
|
||||
ids: z.array(z.string().min(1)).optional(),
|
||||
all: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const createWebhookSchema = z.object({
|
||||
name: z.string().min(1).max(80),
|
||||
url: z.string().url(),
|
||||
events: z.array(z.string().min(1)).min(1),
|
||||
active: z.boolean().default(true),
|
||||
});
|
||||
|
||||
export const updateWebhookSchema = z.object({
|
||||
name: z.string().min(1).max(80).optional(),
|
||||
url: z.string().url().optional(),
|
||||
events: z.array(z.string().min(1)).min(1).optional(),
|
||||
active: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const WEBHOOK_EVENTS = [
|
||||
'ticket.created',
|
||||
'ticket.status_changed',
|
||||
'ticket.assigned',
|
||||
'ticket.resolved',
|
||||
'comment.created',
|
||||
] as const;
|
||||
|
||||
export type NotificationPrefs = z.infer<typeof notificationPrefsSchema>;
|
||||
export type CreateWebhookInput = z.infer<typeof createWebhookSchema>;
|
||||
export type UpdateWebhookInput = z.infer<typeof updateWebhookSchema>;
|
||||
export type WebhookEvent = (typeof WEBHOOK_EVENTS)[number];
|
||||
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const savedViewFiltersSchema = z
|
||||
.object({
|
||||
status: z.string().optional(),
|
||||
severity: z.number().optional(),
|
||||
assigneeId: z.string().optional(),
|
||||
createdById: z.string().optional(),
|
||||
categoryId: z.string().optional(),
|
||||
typeId: z.string().optional(),
|
||||
itemId: z.string().optional(),
|
||||
search: z.string().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const createSavedViewSchema = z.object({
|
||||
name: z.string().min(1).max(80),
|
||||
filters: savedViewFiltersSchema,
|
||||
});
|
||||
|
||||
export const updateSavedViewSchema = z.object({
|
||||
name: z.string().min(1).max(80).optional(),
|
||||
filters: savedViewFiltersSchema.optional(),
|
||||
});
|
||||
|
||||
export type CreateSavedViewInput = z.infer<typeof createSavedViewSchema>;
|
||||
export type UpdateSavedViewInput = z.infer<typeof updateSavedViewSchema>;
|
||||
export type SavedViewFilters = z.infer<typeof savedViewFiltersSchema>;
|
||||
@@ -22,5 +22,28 @@ export const updateTicketSchema = z.object({
|
||||
assigneeId: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export const bulkActionSchema = z.discriminatedUnion('action', [
|
||||
z.object({
|
||||
action: z.literal('reassign'),
|
||||
ids: z.array(z.string().min(1)).min(1).max(500),
|
||||
value: z.string().nullable(),
|
||||
}),
|
||||
z.object({
|
||||
action: z.literal('close'),
|
||||
ids: z.array(z.string().min(1)).min(1).max(500),
|
||||
}),
|
||||
z.object({
|
||||
action: z.literal('setSeverity'),
|
||||
ids: z.array(z.string().min(1)).min(1).max(500),
|
||||
value: severitySchema,
|
||||
}),
|
||||
z.object({
|
||||
action: z.literal('setStatus'),
|
||||
ids: z.array(z.string().min(1)).min(1).max(500),
|
||||
value: ticketStatusSchema,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type CreateTicketInput = z.infer<typeof createTicketSchema>;
|
||||
export type UpdateTicketInput = z.infer<typeof updateTicketSchema>;
|
||||
export type BulkActionInput = z.infer<typeof bulkActionSchema>;
|
||||
|
||||
Reference in New Issue
Block a user