Rewrite frontend, added rooms, voltage selection per project, startet with todos
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import type { Request, Response } from "express";
|
||||
import { ProjectRepository } from "../../db/repositories/project.repository.js";
|
||||
import { createProjectSchema } from "../../shared/validation/consumer.schemas.js";
|
||||
import {
|
||||
createProjectSchema,
|
||||
updateProjectSettingsSchema,
|
||||
} from "../../shared/validation/consumer.schemas.js";
|
||||
|
||||
const projectRepository = new ProjectRepository();
|
||||
|
||||
@@ -14,7 +17,37 @@ export async function createProject(req: Request, res: Response) {
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
const project = await projectRepository.create(parsed.data.name);
|
||||
const project = await projectRepository.create(parsed.data);
|
||||
return res.status(201).json(project);
|
||||
}
|
||||
|
||||
export async function getProject(req: Request, res: Response) {
|
||||
const { projectId } = req.params;
|
||||
if (typeof projectId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid projectId" });
|
||||
}
|
||||
const row = await projectRepository.findById(projectId);
|
||||
if (!row) {
|
||||
return res.status(404).json({ error: "Project not found" });
|
||||
}
|
||||
return res.json(row);
|
||||
}
|
||||
|
||||
export async function updateProjectSettings(req: Request, res: Response) {
|
||||
const { projectId } = req.params;
|
||||
if (typeof projectId !== "string") {
|
||||
return res.status(400).json({ error: "Invalid projectId" });
|
||||
}
|
||||
|
||||
const parsed = updateProjectSettingsSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: parsed.error.flatten() });
|
||||
}
|
||||
|
||||
await projectRepository.updateSettings(projectId, parsed.data);
|
||||
const row = await projectRepository.findById(projectId);
|
||||
if (!row) {
|
||||
return res.status(404).json({ error: "Project not found" });
|
||||
}
|
||||
return res.json(row);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user