49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { VenuesService } from './venues.service';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
@ApiTags('Venues')
|
|
@Controller('venues')
|
|
export class VenuesController {
|
|
constructor(
|
|
private venuesService: VenuesService,
|
|
private prisma: PrismaService,
|
|
) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List all venues (public)' })
|
|
async findAll() {
|
|
return this.venuesService.findAll();
|
|
}
|
|
|
|
@Get(':venueId')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiOperation({ summary: 'Get venue by ID' })
|
|
async findOne(@Param('venueId') venueId: string) {
|
|
return this.venuesService.findOne(venueId);
|
|
}
|
|
|
|
@Get(':venueId/devices')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiOperation({ summary: 'List devices for a venue' })
|
|
async findDevices(@Param('venueId') venueId: string) {
|
|
const devices = await this.prisma.device.findMany({
|
|
where: { venueId },
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
lastSeenAt: true,
|
|
revokedAt: true,
|
|
createdAt: true,
|
|
tokenExpiresAt: true,
|
|
tokenPrefix: true,
|
|
},
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
return { devices };
|
|
}
|
|
} |