Add admin middleware to enforce authentication and permission checks for dashboard access. Implement API models and routes for library CRUD operations, including listing, getting, creating, updating, and deleting libraries with validation and error handling.
96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const LIBRARY_TYPES = ["MOVIE", "SERIES"] as const;
|
|
|
|
// List all libraries
|
|
export const LibraryListInput = z.void();
|
|
export type LibraryListInput = z.infer<typeof LibraryListInput>;
|
|
|
|
export const LibraryListOutput = z.array(
|
|
z.object({
|
|
id: z.number(),
|
|
name: z.string(),
|
|
type: z.enum(LIBRARY_TYPES),
|
|
path: z.string(),
|
|
primaryLanguage: z.string(),
|
|
fallbackLanguage: z.string(),
|
|
createdAt: z.date(),
|
|
updatedAt: z.date(),
|
|
}),
|
|
);
|
|
export type LibraryListOutput = z.infer<typeof LibraryListOutput>;
|
|
|
|
// Get a library by ID
|
|
export const LibraryGetInput = z.object({
|
|
id: z.number().min(1),
|
|
});
|
|
export type LibraryGetInput = z.infer<typeof LibraryGetInput>;
|
|
|
|
export const LibraryGetOutput = z.object({
|
|
id: z.number(),
|
|
name: z.string(),
|
|
type: z.enum(LIBRARY_TYPES),
|
|
path: z.string(),
|
|
primaryLanguage: z.string(),
|
|
fallbackLanguage: z.string(),
|
|
createdAt: z.date(),
|
|
updatedAt: z.date(),
|
|
});
|
|
export type LibraryGetOutput = z.infer<typeof LibraryGetOutput>;
|
|
|
|
// Create a new library
|
|
export const LibraryCreateInput = z.object({
|
|
name: z.string().min(1).max(255),
|
|
type: z.enum(LIBRARY_TYPES),
|
|
path: z.string().min(1).max(255),
|
|
primaryLanguage: z.string().min(1).max(255),
|
|
fallbackLanguage: z.string().min(1).max(255),
|
|
});
|
|
export type LibraryCreateInput = z.infer<typeof LibraryCreateInput>;
|
|
|
|
export const LibraryCreateOutput = z.object({
|
|
success: z.boolean(),
|
|
message: z.string(),
|
|
data: LibraryGetOutput,
|
|
});
|
|
export type LibraryCreateOutput = z.infer<typeof LibraryCreateOutput>;
|
|
|
|
// Update a library
|
|
export const LibraryUpdateInputParam = z.object({
|
|
id: z.number(),
|
|
});
|
|
export type LibraryUpdateInputParam = z.infer<typeof LibraryUpdateInputParam>;
|
|
|
|
export const LibraryUpdateInput = z.object({
|
|
name: z.string().min(1).max(255),
|
|
type: z.enum(LIBRARY_TYPES),
|
|
path: z.string().min(1).max(255),
|
|
primaryLanguage: z.string().min(1).max(255),
|
|
fallbackLanguage: z.string().min(1).max(255),
|
|
});
|
|
export type LibraryUpdateInput = z.infer<typeof LibraryUpdateInput>;
|
|
|
|
export const LibraryUpdateOutput = z.object({
|
|
id: z.number(),
|
|
name: z.string(),
|
|
type: z.enum(LIBRARY_TYPES),
|
|
path: z.string(),
|
|
primaryLanguage: z.string(),
|
|
fallbackLanguage: z.string(),
|
|
createdAt: z.date(),
|
|
updatedAt: z.date(),
|
|
});
|
|
export type LibraryUpdateOutput = z.infer<typeof LibraryUpdateOutput>;
|
|
|
|
// Delete a library
|
|
export const LibraryDeleteInput = z.object({
|
|
id: z.number().min(1),
|
|
});
|
|
export type LibraryDeleteInput = z.infer<typeof LibraryDeleteInput>;
|
|
|
|
export const LibraryDeleteOutput = z.object({
|
|
success: z.boolean(),
|
|
message: z.string().optional(),
|
|
});
|
|
export type LibraryDeleteOutput = z.infer<typeof LibraryDeleteOutput>;
|