generated from Dicken/dickendock
Commit 2: REST-API für Geräte und Dienste (Zod-Validierung, Drizzle-Repositories)
This commit is contained in:
48
packages/shared/src/schemas.ts
Normal file
48
packages/shared/src/schemas.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const deviceSourceValues = [
|
||||
"fritzbox",
|
||||
"dns",
|
||||
"http",
|
||||
"https",
|
||||
"portscan",
|
||||
"manual",
|
||||
] as const;
|
||||
|
||||
export const DeviceSourceSchema = z.enum(deviceSourceValues);
|
||||
|
||||
export const DeviceCreateSchema = z.object({
|
||||
hostname: z.string().min(1, "hostname darf nicht leer sein"),
|
||||
ip: z.string().min(1, "ip darf nicht leer sein"),
|
||||
mac: z.string().optional(),
|
||||
manufacturer: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
online: z.boolean().optional(),
|
||||
source: DeviceSourceSchema.optional(),
|
||||
});
|
||||
export type DeviceCreateInput = z.infer<typeof DeviceCreateSchema>;
|
||||
|
||||
export const DeviceUpdateSchema = DeviceCreateSchema.partial();
|
||||
export type DeviceUpdateInput = z.infer<typeof DeviceUpdateSchema>;
|
||||
|
||||
export const ServiceCreateSchema = z.object({
|
||||
deviceId: z.string().min(1, "deviceId darf nicht leer sein"),
|
||||
displayName: z.string().min(1, "displayName darf nicht leer sein"),
|
||||
hostname: z.string().min(1, "hostname darf nicht leer sein"),
|
||||
url: z.string().url("url muss eine gültige URL sein"),
|
||||
https: z.boolean().optional(),
|
||||
port: z.number().int().min(1).max(65535),
|
||||
category: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
favicon: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
favorite: z.boolean().optional(),
|
||||
alias: z.array(z.string()).optional(),
|
||||
order: z.number().optional(),
|
||||
});
|
||||
export type ServiceCreateInput = z.infer<typeof ServiceCreateSchema>;
|
||||
|
||||
export const ServiceUpdateSchema = ServiceCreateSchema.omit({
|
||||
deviceId: true,
|
||||
}).partial();
|
||||
export type ServiceUpdateInput = z.infer<typeof ServiceUpdateSchema>;
|
||||
Reference in New Issue
Block a user