import { Controller, Get, Post, Put, Delete, Param, Body, Query, UseGuards, } from '@nestjs/common'; import { ObjectService } from './object.service'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; import { CurrentUser } from '../auth/current-user.decorator'; import { TenantId } from '../tenant/tenant.decorator'; @Controller('runtime/objects') @UseGuards(JwtAuthGuard) export class RuntimeObjectController { constructor(private objectService: ObjectService) {} @Get(':objectApiName/records') async getRecords( @TenantId() tenantId: string, @Param('objectApiName') objectApiName: string, @CurrentUser() user: any, @Query() query: any, ) { return this.objectService.getRecords( tenantId, objectApiName, user.userId, query, ); } @Get(':objectApiName/records/:id') async getRecord( @TenantId() tenantId: string, @Param('objectApiName') objectApiName: string, @Param('id') id: string, @CurrentUser() user: any, ) { return this.objectService.getRecord( tenantId, objectApiName, id, user.userId, ); } @Post(':objectApiName/records') async createRecord( @TenantId() tenantId: string, @Param('objectApiName') objectApiName: string, @Body() data: any, @CurrentUser() user: any, ) { return this.objectService.createRecord( tenantId, objectApiName, data, user.userId, ); } @Put(':objectApiName/records/:id') async updateRecord( @TenantId() tenantId: string, @Param('objectApiName') objectApiName: string, @Param('id') id: string, @Body() data: any, @CurrentUser() user: any, ) { return this.objectService.updateRecord( tenantId, objectApiName, id, data, user.userId, ); } @Delete(':objectApiName/records/:id') async deleteRecord( @TenantId() tenantId: string, @Param('objectApiName') objectApiName: string, @Param('id') id: string, @CurrentUser() user: any, ) { return this.objectService.deleteRecord( tenantId, objectApiName, id, user.userId, ); } @Post(':objectApiName/records/bulk-delete') async deleteRecords( @TenantId() tenantId: string, @Param('objectApiName') objectApiName: string, @Body() body: { recordIds?: string[]; ids?: string[] }, @CurrentUser() user: any, ) { const recordIds: string[] = body?.recordIds || body?.ids || []; return this.objectService.deleteRecords( tenantId, objectApiName, recordIds, user.userId, ); } }