31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import type { Request, Response } from "express";
|
|
import { FloorRepository } from "../../db/repositories/floor.repository.js";
|
|
import { createFloorSchema } from "../../shared/validation/project-structure.schemas.js";
|
|
|
|
const floorRepository = new FloorRepository();
|
|
|
|
export async function listFloorsByProject(req: Request, res: Response) {
|
|
const { projectId } = req.params;
|
|
if (typeof projectId !== "string") {
|
|
return res.status(400).json({ error: "Invalid projectId" });
|
|
}
|
|
|
|
const result = await floorRepository.listByProject(projectId);
|
|
return res.json(result);
|
|
}
|
|
|
|
export async function createFloor(req: Request, res: Response) {
|
|
const { projectId } = req.params;
|
|
if (typeof projectId !== "string") {
|
|
return res.status(400).json({ error: "Invalid projectId" });
|
|
}
|
|
|
|
const parsed = createFloorSchema.safeParse(req.body);
|
|
if (!parsed.success) {
|
|
return res.status(400).json({ error: parsed.error.flatten() });
|
|
}
|
|
|
|
const floor = await floorRepository.create(projectId, parsed.data.name);
|
|
return res.status(201).json(floor);
|
|
}
|