File size: 1,247 Bytes
d988ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common';
import { AdminService } from './admin.service';
import { AdminAuthGuard } from './admin.guard';

@Controller('admin')
@UseGuards(AdminAuthGuard)
export class AdminController {
  constructor(private readonly adminService: AdminService) { }

  @Get('clipboards')
  listClipboards() {
    return this.adminService.listClipboards();
  }

  @Get('clipboards/:roomCode')
  getClipboard(@Param('roomCode') roomCode: string) {
    return this.adminService.getClipboard(roomCode);
  }

  @Post('clipboards/:roomCode/password')
  updatePassword(
    @Param('roomCode') roomCode: string,
    @Body() body: { password?: string | null },
  ) {
    return this.adminService.setPassword(roomCode, body.password);
  }

  @Post('clipboards/:roomCode/ttl')
  updateTTL(
    @Param('roomCode') roomCode: string,
    @Body() body: { ttl?: number | null },
  ) {
    const ttl = body.ttl === null || body.ttl === undefined ? null : Number(body.ttl);
    return this.adminService.setTTL(roomCode, isNaN(ttl) ? null : ttl);
  }

  @Delete('clipboards/:roomCode')
  deleteClipboard(@Param('roomCode') roomCode: string) {
    return this.adminService.deleteClipboard(roomCode);
  }
}