This commit is contained in:
2026-09-19 22:19:35 +02:00
commit 231b3e006a
124 changed files with 13816 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { TabsService } from './tabs.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
@ApiTags('Tabs')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('venues/:venueId/tabs')
export class TabsController {
constructor(private tabsService: TabsService) {}
@Get()
@ApiOperation({ summary: 'List all open tabs for a venue' })
async findAll(@Param('venueId') venueId: string) {
return this.tabsService.findAll(venueId);
}
}
+10
View File
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { TabsController } from './tabs.controller';
import { TabsService } from './tabs.service';
@Module({
controllers: [TabsController],
providers: [TabsService],
exports: [TabsService],
})
export class TabsModule {}
+43
View File
@@ -0,0 +1,43 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class TabsService {
constructor(private prisma: PrismaService) {}
async findAll(venueId: string) {
const ownerships = await this.prisma.tabOwnership.findMany({
where: { venueId },
include: {
device: {
select: { id: true, name: true, lastSeenAt: true, revokedAt: true },
},
},
});
const tabs = [];
for (const ownership of ownerships) {
const snapshot = await this.prisma.openTabSnapshot.findFirst({
where: { tabId: ownership.tabId, deviceId: ownership.deviceId },
orderBy: { reportedAt: 'desc' },
});
if (snapshot) {
tabs.push({
tabId: snapshot.tabId,
customerName: snapshot.customerName,
version: snapshot.version,
totalInCents: snapshot.totalInCents,
itemCount: snapshot.itemCount,
deviceId: ownership.device.id,
deviceName: ownership.device.name,
deviceLastSeenAt: ownership.device.lastSeenAt,
deviceRevokedAt: ownership.device.revokedAt,
lastReportedAt: snapshot.reportedAt,
});
}
}
return { tabs };
}
}