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:
47
server/services/portService.ts
Normal file
47
server/services/portService.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { prisma } from '../lib/prisma';
|
||||
import { AppError } from '../types/index';
|
||||
import type { VlanMode } from '../lib/constants';
|
||||
|
||||
const portInclude = {
|
||||
vlans: { include: { vlan: true } },
|
||||
};
|
||||
|
||||
export async function updatePort(
|
||||
id: string,
|
||||
data: {
|
||||
label?: string;
|
||||
mode?: VlanMode;
|
||||
nativeVlan?: number | null;
|
||||
notes?: string;
|
||||
vlans?: Array<{ vlanId: string; tagged: boolean }>;
|
||||
}
|
||||
) {
|
||||
const existing = await prisma.port.findUnique({ where: { id } });
|
||||
if (!existing) throw new AppError('Port not found', 404, 'NOT_FOUND');
|
||||
|
||||
const { vlans: vlanAssignments, ...portData } = data;
|
||||
|
||||
return prisma.$transaction(async (tx) => {
|
||||
await tx.port.update({ where: { id }, data: portData });
|
||||
|
||||
if (vlanAssignments !== undefined) {
|
||||
if (vlanAssignments.length > 0) {
|
||||
const vlanIds = vlanAssignments.map((v) => v.vlanId);
|
||||
const found = await tx.vlan.findMany({ where: { id: { in: vlanIds } } });
|
||||
if (found.length !== vlanIds.length) {
|
||||
throw new AppError('One or more VLANs not found', 404, 'VLAN_NOT_FOUND');
|
||||
}
|
||||
}
|
||||
|
||||
await tx.portVlan.deleteMany({ where: { portId: id } });
|
||||
|
||||
if (vlanAssignments.length > 0) {
|
||||
await tx.portVlan.createMany({
|
||||
data: vlanAssignments.map(({ vlanId, tagged }) => ({ portId: id, vlanId, tagged })),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return tx.port.findUnique({ where: { id }, include: portInclude });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user