feat(admin): add posts CRUD sandbox and shared CRUD foundation
This commit is contained in:
@@ -4,22 +4,32 @@ export * from "./rbac"
|
||||
|
||||
export const postStatusSchema = z.enum(["draft", "published"])
|
||||
|
||||
export const postSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
const postMutableFieldsSchema = z.object({
|
||||
title: z.string().min(3).max(180),
|
||||
slug: z.string().min(3).max(180),
|
||||
excerpt: z.string().max(320).optional(),
|
||||
body: z.string().min(1),
|
||||
status: postStatusSchema,
|
||||
})
|
||||
|
||||
export const postSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
...postMutableFieldsSchema.shape,
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
})
|
||||
|
||||
export const upsertPostSchema = postSchema.omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
})
|
||||
export const createPostInputSchema = postMutableFieldsSchema
|
||||
export const updatePostInputSchema = postMutableFieldsSchema
|
||||
.partial()
|
||||
.refine((value) => Object.keys(value).length > 0, {
|
||||
message: "At least one field is required for an update.",
|
||||
})
|
||||
|
||||
// Backward-compatible alias while migrating callers to create/update-specific schemas.
|
||||
export const upsertPostSchema = createPostInputSchema
|
||||
|
||||
export type Post = z.infer<typeof postSchema>
|
||||
export type CreatePostInput = z.infer<typeof createPostInputSchema>
|
||||
export type UpdatePostInput = z.infer<typeof updatePostInputSchema>
|
||||
export type UpsertPostInput = z.infer<typeof upsertPostSchema>
|
||||
|
||||
Reference in New Issue
Block a user