Files
rack-planner/server/services/rackService.ts
jason 231de3d005 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>
2026-03-21 21:48:56 -05:00

60 lines
1.6 KiB
TypeScript

import { prisma } from '../lib/prisma';
import { AppError } from '../types/index';
// Full include shape used across all rack queries
const rackInclude = {
modules: {
orderBy: { uPosition: 'asc' as const },
include: {
ports: {
orderBy: { portNumber: 'asc' as const },
include: {
vlans: {
include: { vlan: true },
},
},
},
},
},
};
export async function listRacks() {
return prisma.rack.findMany({
orderBy: { displayOrder: 'asc' },
include: rackInclude,
});
}
export async function getRack(id: string) {
const rack = await prisma.rack.findUnique({ where: { id }, include: rackInclude });
if (!rack) throw new AppError('Rack not found', 404, 'NOT_FOUND');
return rack;
}
export async function createRack(data: {
name: string;
totalU?: number;
location?: string;
displayOrder?: number;
}) {
// Auto-assign displayOrder to end of list if not provided
if (data.displayOrder === undefined) {
const last = await prisma.rack.findFirst({ orderBy: { displayOrder: 'desc' } });
data.displayOrder = last ? last.displayOrder + 1 : 0;
}
return prisma.rack.create({ data, include: rackInclude });
}
export async function updateRack(
id: string,
data: Partial<{ name: string; totalU: number; location: string; displayOrder: number }>
) {
await getRack(id); // throws 404 if missing
return prisma.rack.update({ where: { id }, data, include: rackInclude });
}
export async function deleteRack(id: string) {
await getRack(id);
return prisma.rack.delete({ where: { id } });
}