import { Controller, Get, Param, Post, Query, Req, UseGuards, } from '@nestjs/common'; import { EntityJSONService } from '../service/entity_json.service'; import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard'; @Controller('entity-json') export class EntityJSONController { constructor(private readonly entityJSONService: EntityJSONService) {} @Get('/:entityType') @UseGuards(JwtAuthGuard) async getEntityJson( @Param('entityType') entityType: string, @Req() req: Request & { user: any }, @Query('mode') mode?: 'flat_json' | 'dropdown', ) { const loggedInUser = req.user?.userData; return this.entityJSONService.getAttributeForFlatJSON( entityType, loggedInUser, mode, ); } @Post('/update-json/:entityId') @UseGuards(JwtAuthGuard) async updateEntityJson( @Param('entityId') entityId: string, @Query('entityType') entityType: string, @Req() req: Request & { user: any }, ) { const loggedInUser = req.user?.userData; return this.entityJSONService.updateEntityJSON( entityType, Number(entityId), loggedInUser, ); } }