Rewrite frontend, added rooms, voltage selection per project, startet with todos

This commit is contained in:
2026-05-01 17:07:56 +02:00
parent 81d47ce16f
commit 65819900b1
49 changed files with 3695 additions and 394 deletions
@@ -0,0 +1,52 @@
import type { Request, Response } from "express";
import { GlobalDeviceRepository } from "../../db/repositories/global-device.repository.js";
import {
createGlobalDeviceSchema,
updateGlobalDeviceSchema,
} from "../../shared/validation/global-device.schemas.js";
const globalDeviceRepository = new GlobalDeviceRepository();
export async function listGlobalDevices(_req: Request, res: Response) {
const rows = await globalDeviceRepository.list();
return res.json(rows);
}
export async function createGlobalDevice(req: Request, res: Response) {
const parsed = createGlobalDeviceSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: parsed.error.flatten() });
}
const created = await globalDeviceRepository.create(parsed.data);
return res.status(201).json(created);
}
export async function updateGlobalDevice(req: Request, res: Response) {
const { globalDeviceId } = req.params;
if (typeof globalDeviceId !== "string") {
return res.status(400).json({ error: "Invalid globalDeviceId" });
}
const parsed = updateGlobalDeviceSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: parsed.error.flatten() });
}
await globalDeviceRepository.update(globalDeviceId, parsed.data);
const row = await globalDeviceRepository.findById(globalDeviceId);
if (!row) {
return res.status(404).json({ error: "Global device not found" });
}
return res.json(row);
}
export async function deleteGlobalDevice(req: Request, res: Response) {
const { globalDeviceId } = req.params;
if (typeof globalDeviceId !== "string") {
return res.status(400).json({ error: "Invalid globalDeviceId" });
}
await globalDeviceRepository.delete(globalDeviceId);
return res.status(204).send();
}