From e02a3d9b58919b13c9e38446810268ada0d8437a Mon Sep 17 00:00:00 2001 From: enlineawork Date: Mon, 7 Sep 2026 21:14:09 -0300 Subject: [PATCH] F4: expose inventory function catalog and history --- .../inventory-function.controller.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 api-v3/src/asset-master/inventory-function.controller.ts diff --git a/api-v3/src/asset-master/inventory-function.controller.ts b/api-v3/src/asset-master/inventory-function.controller.ts new file mode 100644 index 0000000..618d5c4 --- /dev/null +++ b/api-v3/src/asset-master/inventory-function.controller.ts @@ -0,0 +1,69 @@ +import { + Body, + Controller, + Get, + Param, + ParseUUIDPipe, + Patch, + Post, + Query, + Req, +} from '@nestjs/common'; +import { CurrentAuth } from '../auth/decorators/current-auth.decorator'; +import { RequirePermissions } from '../authorization/decorators/require-permissions.decorator'; +import type { AuthPrincipal, RequestWithContext } from '../common/http/request-context'; +import { + ChangeInventoryFunctionDto, + CreateInventoryFunctionDto, + UpdateInventoryFunctionDto, +} from './dto/inventory-function.dto'; +import { InventoryFunctionService } from './inventory-function.service'; + +@Controller() +export class InventoryFunctionController { + constructor(private readonly functions: InventoryFunctionService) {} + + @Get('inventory-functions') + @RequirePermissions('assets.read') + list(@Query('includeInactive') includeInactive?: string) { + return this.functions.list(includeInactive === 'true'); + } + + @Post('inventory-functions') + @RequirePermissions('asset_types.manage') + create( + @Body() dto: CreateInventoryFunctionDto, + @CurrentAuth() principal: AuthPrincipal, + @Req() request: RequestWithContext, + ) { + return this.functions.create(dto, principal, request); + } + + @Patch('inventory-functions/:id') + @RequirePermissions('asset_types.manage') + update( + @Param('id', new ParseUUIDPipe({ version: '4' })) id: string, + @Body() dto: UpdateInventoryFunctionDto, + @CurrentAuth() principal: AuthPrincipal, + @Req() request: RequestWithContext, + ) { + return this.functions.update(id, dto, principal, request); + } + + @Get('assets/:id/function-history') + @RequirePermissions('assets.read_history') + history(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) { + return this.functions.getForAsset(id); + } + + @Post('assets/:id/function') + @RequirePermissions('assets.update') + change( + @Param('id', new ParseUUIDPipe({ version: '4' })) id: string, + @Body() dto: ChangeInventoryFunctionDto, + @CurrentAuth() principal: AuthPrincipal, + @Req() request: RequestWithContext, + ) { + return this.functions.changeForAsset(id, dto, principal, request); + } +}