70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { Controller, Get, Param, UseGuards, Post, Body } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { VenuesService } from './venues.service';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { RolesGuard } from '../common/guards/roles.guard';
|
|
import { Roles } from '../common/decorators/roles.decorator';
|
|
import { AuthService } from '../auth/auth.service';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
@ApiTags('Venues')
|
|
@Controller('venues')
|
|
export class VenuesController {
|
|
constructor(
|
|
private venuesService: VenuesService,
|
|
private authService: AuthService,
|
|
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/users')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('admin')
|
|
@ApiOperation({ summary: 'List users for a venue' })
|
|
async findUsers(@Param('venueId') venueId: string) {
|
|
const users = await this.prisma.clientUser.findMany({
|
|
where: { venueId },
|
|
select: { id: true, email: true, name: true, role: true, createdAt: true },
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
return { users };
|
|
}
|
|
|
|
@Post(':venueId/users')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('admin')
|
|
@ApiOperation({ summary: 'Create a new user for the venue' })
|
|
async createUser(
|
|
@Param('venueId') venueId: string,
|
|
@Body() dto: { email: string; password: string; name: string; role: string },
|
|
) {
|
|
return this.authService.createUser(venueId, dto.email, dto.password, dto.name, dto.role);
|
|
}
|
|
|
|
@Get(':venueId/devices')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiOperation({ summary: 'Get venue device info' })
|
|
async findDevices(@Param('venueId') venueId: string) {
|
|
const device = await this.prisma.device.findFirst({
|
|
where: { venueId, revokedAt: null },
|
|
select: { id: true, name: true, lastSeenAt: true, createdAt: true },
|
|
});
|
|
return { device };
|
|
}
|
|
} |