Initial scaffold: full-stack RackMapper application
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>
This commit is contained in:
97
server/routes/serviceMap.ts
Normal file
97
server/routes/serviceMap.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import * as mapService from '../services/mapService';
|
||||
import { ok } from '../types/index';
|
||||
import type { NodeType } from '../lib/constants';
|
||||
|
||||
export const serviceMapRouter = Router();
|
||||
|
||||
serviceMapRouter.get('/', async (_req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
res.json(ok(await mapService.listMaps()));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.post('/', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const { name, description } = req.body as { name: string; description?: string };
|
||||
res.status(201).json(ok(await mapService.createMap({ name, description })));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.get('/:id', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
res.json(ok(await mapService.getMap(req.params.id)));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.put('/:id', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const { name, description } = req.body as { name?: string; description?: string };
|
||||
res.json(ok(await mapService.updateMap(req.params.id, { name, description })));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.delete('/:id', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await mapService.deleteMap(req.params.id);
|
||||
res.json(ok(null));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.post('/:id/nodes', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const { label, nodeType, positionX, positionY, metadata, color, icon, moduleId } = req.body as {
|
||||
label: string;
|
||||
nodeType: NodeType;
|
||||
positionX: number;
|
||||
positionY: number;
|
||||
metadata?: string;
|
||||
color?: string;
|
||||
icon?: string;
|
||||
moduleId?: string;
|
||||
};
|
||||
res.status(201).json(
|
||||
ok(await mapService.addNode(req.params.id, { label, nodeType, positionX, positionY, metadata, color, icon, moduleId }))
|
||||
);
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.post('/:id/populate', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
res.json(ok(await mapService.populateFromRack(req.params.id)));
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
serviceMapRouter.post('/:id/edges', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const { sourceId, targetId, label, edgeType, animated, metadata } = req.body as {
|
||||
sourceId: string;
|
||||
targetId: string;
|
||||
label?: string;
|
||||
edgeType?: string;
|
||||
animated?: boolean;
|
||||
metadata?: string;
|
||||
};
|
||||
res.status(201).json(
|
||||
ok(await mapService.addEdge(req.params.id, { sourceId, targetId, label, edgeType, animated, metadata }))
|
||||
);
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
export { mapService };
|
||||
Reference in New Issue
Block a user