import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { EvaluationService } from '../service/evaluation.service';
import { TokenData } from 'src/common/decorator/token-data.decorator';
import { TokenDataEntity } from 'src/common/entities/token-data.entity';

@Controller('evaluation')
export class EvaluationController {
  constructor(private readonly evaluationService: EvaluationService) {}

  @Post()
  create(@Body() data, @TokenData() token: TokenDataEntity) {
    data.creator = data.updater = token.userId;
    return this.evaluationService.create(data);
  }

  @Get()
  findAll() {
    return this.evaluationService.findAll();
  }

  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body('name') name: string,
    @TokenData() token: TokenDataEntity,
  ) {
    return this.evaluationService.update(+id, { name, updater: token.userId });
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.evaluationService.remove(+id);
  }
}
