41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
// app/api/devices/route.ts
|
|
import { NextResponse } from 'next/server';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const devices = await prisma.device.findMany({
|
|
include: {
|
|
group: true,
|
|
location: true,
|
|
tags: true, // 🔹 NEU
|
|
},
|
|
});
|
|
|
|
return NextResponse.json(
|
|
devices.map((d) => ({
|
|
inventoryNumber: d.inventoryNumber,
|
|
name: d.name,
|
|
manufacturer: d.manufacturer,
|
|
model: d.model,
|
|
serialNumber: d.serialNumber,
|
|
productNumber: d.productNumber,
|
|
comment: d.comment,
|
|
ipv4Address: d.ipv4Address,
|
|
ipv6Address: d.ipv6Address,
|
|
macAddress: d.macAddress,
|
|
username: d.username,
|
|
passwordHash: d.passwordHash,
|
|
group: d.group?.name ?? null,
|
|
location: d.location?.name ?? null,
|
|
tags: d.tags.map((t) => t.name),
|
|
updatedAt: d.updatedAt.toISOString(),
|
|
})),
|
|
);
|
|
|
|
} catch (err) {
|
|
console.error('[GET /api/devices]', err);
|
|
return NextResponse.json({ error: 'INTERNAL_ERROR' }, { status: 500 });
|
|
}
|
|
}
|