feat: add plannedTabs
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
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')
|
||||
@@ -9,6 +12,7 @@ import { PrismaService } from '../prisma/prisma.service';
|
||||
export class VenuesController {
|
||||
constructor(
|
||||
private venuesService: VenuesService,
|
||||
private authService: AuthService,
|
||||
private prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
@@ -26,24 +30,41 @@ export class VenuesController {
|
||||
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: 'List devices for a venue' })
|
||||
@ApiOperation({ summary: 'Get venue device info' })
|
||||
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' },
|
||||
const device = await this.prisma.device.findFirst({
|
||||
where: { venueId, revokedAt: null },
|
||||
select: { id: true, name: true, lastSeenAt: true, createdAt: true },
|
||||
});
|
||||
return { devices };
|
||||
return { device };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user