phase.controller.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Controller, Get, Post, Body, Param, Put, Delete, Query } from '@nestjs/common';
  2. import { PhaseService } from '../services/phase.service';
  3. import { Phase } from '../schemas/site.schema';
  4. @Controller('phases')
  5. export class PhaseController {
  6. constructor(private readonly phaseService: PhaseService) { }
  7. @Post()
  8. async create(@Body() phase: Phase) {
  9. return this.phaseService.create(phase);
  10. }
  11. @Get()
  12. async findAll(@Query('siteId') siteId?: string) {
  13. const filter = siteId ? { siteId } : {};
  14. return this.phaseService.findAll(filter);
  15. }
  16. @Get(':id')
  17. async findById(@Param('id') id: string, @Query('populate') populate: string) {
  18. return this.phaseService.findById(id, populate === 'true');
  19. }
  20. @Put(':id')
  21. async update(@Param('id') id: string, @Body() update: Partial<Phase>) {
  22. await this.phaseService.update(id, update);
  23. return { message: 'Phase updated successfully' };
  24. }
  25. @Delete(':id')
  26. async delete(@Param('id') id: string) {
  27. await this.phaseService.delete(id);
  28. return { message: 'Phase and all related blocks/FFB data deleted successfully' };
  29. }
  30. }