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:
37
server/services/vlanService.ts
Normal file
37
server/services/vlanService.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { prisma } from '../lib/prisma';
|
||||
import { AppError } from '../types/index';
|
||||
|
||||
export async function listVlans() {
|
||||
return prisma.vlan.findMany({ orderBy: { vlanId: 'asc' } });
|
||||
}
|
||||
|
||||
export async function createVlan(data: {
|
||||
vlanId: number;
|
||||
name: string;
|
||||
description?: string;
|
||||
color?: string;
|
||||
}) {
|
||||
const existing = await prisma.vlan.findUnique({ where: { vlanId: data.vlanId } });
|
||||
if (existing) throw new AppError(`VLAN ID ${data.vlanId} already exists`, 409, 'DUPLICATE');
|
||||
|
||||
if (data.vlanId < 1 || data.vlanId > 4094) {
|
||||
throw new AppError('VLAN ID must be between 1 and 4094', 400, 'INVALID_VLAN_ID');
|
||||
}
|
||||
|
||||
return prisma.vlan.create({ data });
|
||||
}
|
||||
|
||||
export async function updateVlan(
|
||||
id: string,
|
||||
data: Partial<{ name: string; description: string; color: string }>
|
||||
) {
|
||||
const existing = await prisma.vlan.findUnique({ where: { id } });
|
||||
if (!existing) throw new AppError('VLAN not found', 404, 'NOT_FOUND');
|
||||
return prisma.vlan.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
export async function deleteVlan(id: string) {
|
||||
const existing = await prisma.vlan.findUnique({ where: { id } });
|
||||
if (!existing) throw new AppError('VLAN not found', 404, 'NOT_FOUND');
|
||||
return prisma.vlan.delete({ where: { id } });
|
||||
}
|
||||
Reference in New Issue
Block a user