import { Body, Controller, Get, Param, Post, Put, UploadedFile, UseInterceptors, } from '@nestjs/common'; import { EventEmitter2 } from '@nestjs/event-emitter'; import { FileInterceptor } from '@nestjs/platform-express'; import { plainToClass } from 'class-transformer'; import { memoryStorage } from 'multer'; import { ClientUpdateBidDto } from '../../dto/bid/client-update-bid.dto'; import { CreateBidDto } from '../../dto/bid/create-bid.dto'; import { UpdateStatusByPriceDto } from '../../dto/bid/update-status-by-price.dto'; import { Bid } from '../../entities/bid.entity'; import { WebBid } from '../../entities/wed-bid.entity'; import { BidsService } from '../../services/bids.service'; import { WebBidsService } from '../../services/web-bids.service'; import { Event } from '../../utils/events'; import AppResponse from '@/response/app-response'; @Controller('bids') export class BidsController { constructor( private readonly bidsService: BidsService, private readonly eventEmitter: EventEmitter2, private readonly webBidService: WebBidsService, ) {} @Get() index() { return this.bidsService.clientIndex(); } @Post() create(@Body() data: CreateBidDto) { return this.bidsService.create(data); } @Put(':id') update(@Param('id') id: Bid['id'], @Body() data: ClientUpdateBidDto) { return this.bidsService.clientUpdate(id, data); } @Post('out-bid/:id') outBidStatus(@Param('id') id: Bid['id']) { return this.bidsService.outBid(id); } @Post('update-status/:id') updateStatusByPrice( @Param('id') id: Bid['id'], @Body() data: UpdateStatusByPriceDto, ) { return this.bidsService.updateStatusByPrice(id, data); } @Post('update-status-work/:type/:id') @UseInterceptors(FileInterceptor('image', { storage: memoryStorage() })) async updateStatusWork( @Param('id') id: Bid['id'], @Param('type') type: string, @UploadedFile() image: Express.Multer.File, ) { return this.bidsService.updateStatusWork(id, type, image); } @Post('test') async test(@Body('code') code: string) { const webBid = await this.webBidService.webBidRepo.findOne({ // where: { id: 9 }, where: { id: 8 }, }); this.eventEmitter.emit(Event.verifyCode(webBid), { code, // name: 'LAWSONS', name: 'LANGTONS', web_bid: plainToClass(WebBid, webBid), }); return AppResponse.toResponse({ code }); } }