Rework artwork list
This commit is contained in:
97
src/schemas/artworks/tableSchema.ts
Normal file
97
src/schemas/artworks/tableSchema.ts
Normal file
@ -0,0 +1,97 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const triStateSchema = z.enum(["any", "true", "false"]);
|
||||
|
||||
// Allowlisted sorting ids (server will enforce)
|
||||
export const artworkSortIdSchema = z.enum([
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"sortIndex",
|
||||
"name",
|
||||
"slug",
|
||||
"published",
|
||||
"nsfw",
|
||||
"needsWork",
|
||||
// relation-derived sorts
|
||||
"albumsCount",
|
||||
"categoriesCount",
|
||||
"tagsCount",
|
||||
]);
|
||||
|
||||
export const artworkTableInputSchema = z.object({
|
||||
pagination: z.object({
|
||||
pageIndex: z.number().int().min(0).default(0),
|
||||
pageSize: z.number().int().min(1).max(200).default(25),
|
||||
}),
|
||||
|
||||
sorting: z
|
||||
.array(
|
||||
z.object({
|
||||
id: artworkSortIdSchema,
|
||||
desc: z.boolean(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
|
||||
filters: z
|
||||
.object({
|
||||
name: z.string().trim().max(200).optional(),
|
||||
slug: z.string().trim().max(200).optional(),
|
||||
|
||||
published: triStateSchema.default("any"),
|
||||
nsfw: triStateSchema.default("any"),
|
||||
needsWork: triStateSchema.default("any"),
|
||||
|
||||
galleryId: z.string().min(1).optional(),
|
||||
albumIds: z.array(z.string().min(1)).max(200).optional(),
|
||||
categoryIds: z.array(z.string().min(1)).max(200).optional(),
|
||||
})
|
||||
.default({
|
||||
published: "any",
|
||||
nsfw: "any",
|
||||
needsWork: "any",
|
||||
}),
|
||||
});
|
||||
|
||||
export type ArtworkTableInput = z.infer<typeof artworkTableInputSchema>;
|
||||
|
||||
export const artworkTableRowSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
slug: z.string(),
|
||||
|
||||
published: z.boolean(),
|
||||
nsfw: z.boolean(),
|
||||
needsWork: z.boolean(),
|
||||
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
|
||||
fileKey: z.string(),
|
||||
|
||||
gallery: z
|
||||
.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
})
|
||||
.nullable(),
|
||||
|
||||
albums: z.array(z.object({ id: z.string(), name: z.string() })),
|
||||
categories: z.array(z.object({ id: z.string(), name: z.string() })),
|
||||
|
||||
// counts are useful both for display and for sorting sanity
|
||||
albumsCount: z.number().int().min(0),
|
||||
categoriesCount: z.number().int().min(0),
|
||||
tagsCount: z.number().int().min(0),
|
||||
});
|
||||
|
||||
export type ArtworkTableRow = z.infer<typeof artworkTableRowSchema>;
|
||||
|
||||
export const artworkTableOutputSchema = z.object({
|
||||
rows: z.array(artworkTableRowSchema),
|
||||
total: z.number().int().min(0),
|
||||
pageIndex: z.number().int().min(0),
|
||||
pageSize: z.number().int().min(1),
|
||||
});
|
||||
|
||||
export type ArtworkTableOutput = z.infer<typeof artworkTableOutputSchema>;
|
||||
Reference in New Issue
Block a user