Commit 2: REST-API für Geräte und Dienste (Zod-Validierung, Drizzle-Repositories)

This commit is contained in:
2026-07-19 01:53:43 +02:00
parent 3a7f423f60
commit a5b998b421
11 changed files with 418 additions and 5 deletions

View File

@@ -9,6 +9,9 @@
"build": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.5.4"
}

View File

@@ -5,6 +5,9 @@
* als auch vom Frontend (apps/frontend) verwendet werden.
*/
export * from "./schemas.js";
export interface Device {
id: string;
hostname: string;

View 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>;