All files / testee testee.controller.ts

100% Statements 20/20
100% Branches 2/2
100% Functions 4/4
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 421x       1x 1x     1x   8x       8x   1x   7x 6x     1x 1x     1x   3x 2x     1x 1x     1x   1x      
import {
  Controller, Get, HttpException, Logger, Post, Req
} from '@nestjs/common';
import { Request } from 'express';
import { TesteeService } from './testee.service';
import { isTestee, Testee } from './testee.interface';
 
@Controller()
export class TesteeController {
  constructor(
    private readonly testeeService: TesteeService
  ) {
  }
 
  private readonly logger = new Logger(TesteeController.name);
 
  @Post('/testee/register')
  testeeRegister(@Req() request: Request): void {
    if (!isTestee(request.body)) {
      throw new HttpException('not testee data', 400);
    }
 
    this.logger.log(`testee registered:${JSON.stringify(request.body)}`);
    this.testeeService.addTestee(request.body);
  }
 
  @Post('/testee/unregister')
  testeeUnregister(@Req() request: Request): void {
    if (!('token' in request.body)) {
      throw new HttpException('no token in body', 400);
    }
 
    this.logger.log('testee unregistered:', request.body);
    this.testeeService.removeTestee(request.body.token);
  }
 
  @Get('/testees')
  testees(@Req() request: Request): Testee[] {
    return this.testeeService.getTestees();
  }
}