forked from jappel/leistungsbilanz-ts
Rewrite frontend, added rooms, voltage selection per project, startet with todos
This commit is contained in:
parent
81d47ce16f
commit
65819900b1
49 changed files with 3695 additions and 394 deletions
39
src/server/controllers/room.controller.ts
Normal file
39
src/server/controllers/room.controller.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import type { Request, Response } from "express";
|
||||
import { FloorRepository } from "../../db/repositories/floor.repository.js";
|
||||
import { RoomRepository } from "../../db/repositories/room.repository.js";
|
||||
import { createRoomSchema } from "../../shared/validation/consumer.schemas.js";
|
||||
|
||||
const floorRepository = new FloorRepository();
|
||||
const roomRepository = new RoomRepository();
|
||||
|
||||
export async function listRoomsByProject(req: Request, res: Response) {
|
||||
const { projectId } = req.params;
|
||||
if (typeof projectId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid projectId" });
|
||||
}
|
||||
|
||||
const result = await roomRepository.listByProject(projectId);
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
export async function createRoom(req: Request, res: Response) {
|
||||
const { projectId } = req.params;
|
||||
if (typeof projectId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid projectId" });
|
||||
}
|
||||
|
||||
const parsed = createRoomSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
|
||||
if (parsed.data.floorId) {
|
||||
const hasValidFloor = await floorRepository.existsInProject(projectId, parsed.data.floorId);
|
||||
if (!hasValidFloor) {
|
||||
return res.status(400).json({ error: "Floor does not belong to the provided project." });
|
||||
}
|
||||
}
|
||||
|
||||
const room = await roomRepository.create(projectId, parsed.data);
|
||||
return res.status(201).json(room);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue