40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import type { Request, Response } from "express";
|
|
import { circuitWriteService } from "../composition/circuit-write-service.js";
|
|
import {
|
|
moveCircuitDeviceRowsBulkSchema,
|
|
moveCircuitDeviceRowSchema,
|
|
} from "../../shared/validation/circuit.schemas.js";
|
|
|
|
export async function moveCircuitDeviceRow(req: Request, res: Response) {
|
|
const { rowId } = req.params;
|
|
if (typeof rowId !== "string") {
|
|
return res.status(400).json({ error: "Invalid rowId" });
|
|
}
|
|
|
|
const parsed = moveCircuitDeviceRowSchema.safeParse(req.body);
|
|
if (!parsed.success) {
|
|
return res.status(400).json({ error: parsed.error.flatten() });
|
|
}
|
|
|
|
try {
|
|
const moved = await circuitWriteService.moveDeviceRow(rowId, parsed.data);
|
|
return res.json(moved);
|
|
} catch (error) {
|
|
return res.status(400).json({ error: error instanceof Error ? error.message : "Failed to move device row." });
|
|
}
|
|
}
|
|
|
|
export async function moveCircuitDeviceRowsBulk(req: Request, res: Response) {
|
|
const parsed = moveCircuitDeviceRowsBulkSchema.safeParse(req.body);
|
|
if (!parsed.success) {
|
|
return res.status(400).json({ error: parsed.error.flatten() });
|
|
}
|
|
|
|
try {
|
|
const moved = await circuitWriteService.moveDeviceRowsBulk(parsed.data);
|
|
return res.json(moved);
|
|
} catch (error) {
|
|
return res.status(400).json({ error: error instanceof Error ? error.message : "Failed to move device rows." });
|
|
}
|
|
}
|