import { Body, Controller, Delete, Get, Param, Post, Query, UseGuards, ValidationPipe, } from '@nestjs/common'; import { Token } from 'src/decorators/token.decorator'; import { AuthGuard } from 'src/guards/auth.guard'; import { ListQueryDto } from './dtos/list-query.dto'; import { RegisterIndustryChangeApplicationDto } from './dtos/register-industry-change-application.dto'; import { IndustryChangeApplicationService } from './industry-change-application.service'; @Controller({ path: '/resident-register/industry-change-applications', }) @UseGuards(AuthGuard) export class IndustryChangeApplicationController { constructor( private readonly applicationsSerivce: IndustryChangeApplicationService, ) {} @Get() async getList( @Query(new ValidationPipe({ transform: true })) queryOpts: ListQueryDto, ) { const allApplications = await this.applicationsSerivce.getAll(queryOpts); return this.applicationsSerivce.makeReadable(allApplications); } @Get(':id') async getSingle(@Param('id') id: string) { const findInstance = await this.applicationsSerivce.getById(id); if (!findInstance) return null; return this.applicationsSerivce.makeReadable(findInstance); } @Delete(':id') async delete(@Param('id') id: string, @Token() authToken: string) { return this.applicationsSerivce.makeReadable( await this.applicationsSerivce.markDeleted(id, authToken), ); } @Post() async create( @Body() application: RegisterIndustryChangeApplicationDto, @Token() authToken: string, ) { const newApplication = await this.applicationsSerivce.create( application, authToken, ); return this.applicationsSerivce.makeReadable(newApplication); } }