add backend/src/routes/cockpit.ts
This commit is contained in:
parent
17abbf2a33
commit
b0989f31f2
54
backend/src/routes/cockpit.ts
Normal file
54
backend/src/routes/cockpit.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { Router, Request, Response } from 'express';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { PaymentService } from '../modules/banking/paymentService';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const paymentService = new PaymentService(prisma);
|
||||
|
||||
/** Router für das Vermieter-Cockpit-Dashboard (aggregierte Übersichtsdaten). */
|
||||
export const cockpitRouter = Router();
|
||||
|
||||
cockpitRouter.get('/cockpit/summary', async (_req: Request, res: Response) => {
|
||||
const [trafficLights, openTickets, rooms] = await Promise.all([
|
||||
paymentService.getRentTrafficLights(),
|
||||
prisma.ticket.findMany({
|
||||
where: { status: { in: ['OPEN', 'IN_PROGRESS'] } },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
category: true,
|
||||
priority: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
room: { select: { roomNumber: true } },
|
||||
},
|
||||
}),
|
||||
prisma.room.findMany({
|
||||
select: { id: true, roomNumber: true, sizeSqm: true, status: true },
|
||||
orderBy: { roomNumber: 'asc' },
|
||||
}),
|
||||
]);
|
||||
|
||||
const counts = { GREEN: 0, YELLOW: 0, RED: 0 } as Record<'GREEN' | 'YELLOW' | 'RED', number>;
|
||||
let totalWarmRentSum = 0;
|
||||
for (const light of trafficLights) {
|
||||
counts[light.status]++;
|
||||
totalWarmRentSum += light.amountDue;
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
generatedAt: new Date().toISOString(),
|
||||
rooms,
|
||||
trafficLights,
|
||||
summary: {
|
||||
totalRooms: rooms.length,
|
||||
rentGreen: counts.GREEN,
|
||||
rentYellow: counts.YELLOW,
|
||||
rentRed: counts.RED,
|
||||
totalMonthlyRentTarget: totalWarmRentSum,
|
||||
openTicketsCount: openTickets.length,
|
||||
},
|
||||
openTickets,
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user