Complete project scaffold with working auth, REST API, Prisma/SQLite schema, Docker config, and React frontend for both Rack Planner and Service Mapper modules. Both server and client pass TypeScript strict mode with zero errors. Initial migration applied. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { Router, Request, Response, NextFunction } from 'express';
|
|
import * as rackService from '../services/rackService';
|
|
import * as moduleService from '../services/moduleService';
|
|
import { ok } from '../types/index';
|
|
import type { ModuleType, PortType } from '../lib/constants';
|
|
|
|
export const racksRouter = Router();
|
|
|
|
racksRouter.get('/', async (_req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
res.json(ok(await rackService.listRacks()));
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|
|
|
|
racksRouter.post('/', async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
const { name, totalU, location, displayOrder } = req.body as {
|
|
name: string;
|
|
totalU?: number;
|
|
location?: string;
|
|
displayOrder?: number;
|
|
};
|
|
res.status(201).json(ok(await rackService.createRack({ name, totalU, location, displayOrder })));
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|
|
|
|
racksRouter.get('/:id', async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
res.json(ok(await rackService.getRack(req.params.id)));
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|
|
|
|
racksRouter.put('/:id', async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
const { name, totalU, location, displayOrder } = req.body as {
|
|
name?: string;
|
|
totalU?: number;
|
|
location?: string;
|
|
displayOrder?: number;
|
|
};
|
|
res.json(ok(await rackService.updateRack(req.params.id, { name, totalU, location, displayOrder })));
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|
|
|
|
racksRouter.delete('/:id', async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
await rackService.deleteRack(req.params.id);
|
|
res.json(ok(null));
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|
|
|
|
racksRouter.post('/:id/modules', async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
const { name, type, uPosition, uSize, manufacturer, model, ipAddress, notes, portCount, portType } =
|
|
req.body as {
|
|
name: string;
|
|
type: ModuleType;
|
|
uPosition: number;
|
|
uSize?: number;
|
|
manufacturer?: string;
|
|
model?: string;
|
|
ipAddress?: string;
|
|
notes?: string;
|
|
portCount?: number;
|
|
portType?: PortType;
|
|
};
|
|
res.status(201).json(
|
|
ok(await moduleService.createModule(req.params.id, { name, type, uPosition, uSize, manufacturer, model, ipAddress, notes, portCount, portType }))
|
|
);
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|