mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 08:25:43 +00:00
Generate ticket, dashboard, excess luggage rate updates
This commit is contained in:
@@ -10,6 +10,57 @@ export class DashboardService {
|
||||
@InjectDataSource() private dataSource: DataSource,
|
||||
) {}
|
||||
|
||||
async getBackofficeStats() {
|
||||
const [totalBookings, totalPackageBookings, totalTickets, totalPassengers, revenueRows, packageRevenueRows] =
|
||||
await Promise.all([
|
||||
this.prisma.booking.count(),
|
||||
this.prisma.booking.count({ where: { packageId: { not: null } } }),
|
||||
this.prisma.ticket.count(),
|
||||
this.prisma.passenger.count(),
|
||||
this.prisma.$queryRaw<{ currency: string; total: bigint }[]>`
|
||||
SELECT
|
||||
COALESCE("displayCurrency"::text, "currency"::text) AS currency,
|
||||
SUM(COALESCE("displayTotalMinor", "totalMinor")) AS total
|
||||
FROM passenger."Booking"
|
||||
WHERE status IN ('CONFIRMED', 'BOARDED')
|
||||
AND "packageId" IS NULL
|
||||
AND id IN (SELECT "bookingId" FROM passenger."PaymentIntent" WHERE status = 'SUCCEEDED')
|
||||
GROUP BY COALESCE("displayCurrency"::text, "currency"::text)
|
||||
`,
|
||||
this.prisma.$queryRaw<{ currency: string; total: bigint }[]>`
|
||||
SELECT
|
||||
COALESCE("displayCurrency"::text, "currency"::text) AS currency,
|
||||
SUM(COALESCE("displayTotalMinor", "totalMinor")) AS total
|
||||
FROM passenger."Booking"
|
||||
WHERE status IN ('CONFIRMED', 'BOARDED')
|
||||
AND "packageId" IS NOT NULL
|
||||
AND id IN (SELECT "bookingId" FROM passenger."PaymentIntent" WHERE status = 'SUCCEEDED')
|
||||
GROUP BY COALESCE("displayCurrency"::text, "currency"::text)
|
||||
`,
|
||||
]);
|
||||
|
||||
const totalPackageTickets = await this.prisma.ticket.count({
|
||||
where: { booking: { packageId: { not: null } } },
|
||||
});
|
||||
|
||||
const toMap = (rows: { currency: string; total: bigint }[]) =>
|
||||
Object.entries(
|
||||
rows.reduce((m, r) => { m[r.currency] = Number(r.total); return m; }, {} as Record<string, number>),
|
||||
).map(([currency, totalMinor]) => ({ currency, totalMinor }));
|
||||
|
||||
return {
|
||||
totalBookings,
|
||||
totalPackageBookings,
|
||||
totalNormalBookings: totalBookings - totalPackageBookings,
|
||||
totalTickets,
|
||||
totalPackageTickets,
|
||||
totalNormalTickets: totalTickets - totalPackageTickets,
|
||||
totalPassengers,
|
||||
revenueByCurrency: toMap(revenueRows),
|
||||
packageRevenueByCurrency: toMap(packageRevenueRows),
|
||||
};
|
||||
}
|
||||
|
||||
async getHomeDashboard(passengerId: string) {
|
||||
const now = new Date();
|
||||
const [passenger, upcomingBooking, wallet, promos, weatherAlerts, stationSignals, savedRoutes] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user