import { PosInfo } from '@/common/decorators/posInfo.decorator' import { TokenAccount } from '@/common/decorators/tokenInfo.decorator' import { Body, Controller, Get, Put, Res } from '@nestjs/common' import { ApiTags } from '@nestjs/swagger' import type { PosServiceGetAccessibleResponseDto, PosServiceGetInfoResponseDto, PosServiceGetMeResponseDto, } from './dto/pos-response.dto' import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto' import { PosService } from './pos.service' @ApiTags('Pos') @Controller('pos') export class PosController { constructor(private service: PosService) {} @Get() async getInfo( @PosInfo('pos_id') pos_id: string, @Res({ passthrough: true }) res, ): Promise { const result = await this.service.getInfo(pos_id) if (result) { // @ts-ignore res.cookie('posId', pos_id, { httpOnly: false, secure: process.env.NODE_ENV === 'production', sameSite: 'lax', maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days }) } return result } @Get('/accessible') async getAccessiblePos( @TokenAccount('account_id') account_id, ): Promise { return await this.service.getAccessible(account_id) } @Get('/me') async getMe( @TokenAccount('account_id') account_id, @PosInfo('pos_id') pos_id: string, ): Promise { return await this.service.getMe(account_id, pos_id) } @Put('update-password') async updatePassword( @TokenAccount('userId') consumerId: string, @TokenAccount('account_id') accountId: string, @Body() data: UpdatePosAccountPasswordDto, ) { return this.service.updatePassword(consumerId, accountId, data) } }