70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
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);
|
|
}
|
|
}
|