159 lines
5.7 KiB
TypeScript
159 lines
5.7 KiB
TypeScript
import { Body, Controller, Get, Param, ParseUUIDPipe, Post, Query, Req, UploadedFile, UseInterceptors } from '@nestjs/common';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { RequirePermissions } from '../authorization/decorators/require-permissions.decorator';
|
|
import { CurrentAuth } from '../auth/decorators/current-auth.decorator';
|
|
import type { AuthPrincipal, RequestWithContext } from '../common/http/request-context';
|
|
import { AssetImportsService, MAX_ASSET_IMPORT_BYTES, type UploadedImportFile } from './asset-imports.service';
|
|
import { ApplyAssetImportPlanDto } from './dto/apply-asset-import-plan.dto';
|
|
import { CancelAssetImportDto } from './dto/cancel-asset-import.dto';
|
|
import { CreateAssetImportPlanDto } from './dto/create-asset-import-plan.dto';
|
|
import { ResolveAssetImportPlanItemDto } from './dto/resolve-asset-import-plan-item.dto';
|
|
import { RollbackAssetImportPlanDto } from './dto/rollback-asset-import-plan.dto';
|
|
import { ListAssetImportPlanItemsQueryDto } from './dto/list-asset-import-plan-items-query.dto';
|
|
import { ListAssetImportReviewsQueryDto } from './dto/list-asset-import-reviews-query.dto';
|
|
import { ListAssetImportRowsQueryDto } from './dto/list-asset-import-rows-query.dto';
|
|
import { ListAssetImportsQueryDto } from './dto/list-asset-imports-query.dto';
|
|
import { UploadAssetImportDto } from './dto/upload-asset-import.dto';
|
|
|
|
@Controller('asset-imports')
|
|
export class AssetImportsController {
|
|
constructor(private readonly imports: AssetImportsService) {}
|
|
|
|
@Get()
|
|
@RequirePermissions('asset_imports.read')
|
|
list(@Query() query: ListAssetImportsQueryDto) {
|
|
return this.imports.list(query);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermissions('asset_imports.manage')
|
|
@UseInterceptors(FileInterceptor('file', { limits: { fileSize: MAX_ASSET_IMPORT_BYTES, files: 1 } }))
|
|
upload(
|
|
@Body() dto: UploadAssetImportDto,
|
|
@UploadedFile() file: UploadedImportFile | undefined,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.upload(dto, file, principal, request);
|
|
}
|
|
|
|
@Get('context/organizations')
|
|
@RequirePermissions('asset_imports.read')
|
|
organizations(@Query('search') search?: string) {
|
|
return this.imports.organizationOptions(search);
|
|
}
|
|
|
|
@Get('reviews')
|
|
@RequirePermissions('asset_imports.read')
|
|
reviews(@Query() query: ListAssetImportReviewsQueryDto) {
|
|
return this.imports.reviews(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermissions('asset_imports.read')
|
|
get(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
|
|
return this.imports.get(id);
|
|
}
|
|
|
|
@Get(':id/plan')
|
|
@RequirePermissions('asset_imports.read')
|
|
plan(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
|
|
return this.imports.plan(id);
|
|
}
|
|
|
|
@Get(':id/plan/items')
|
|
@RequirePermissions('asset_imports.read')
|
|
planItems(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Query() query: ListAssetImportPlanItemsQueryDto,
|
|
) {
|
|
return this.imports.planItems(id, query);
|
|
}
|
|
|
|
@Post(':id/plan')
|
|
@RequirePermissions('asset_imports.manage')
|
|
generatePlan(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: CreateAssetImportPlanDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.generatePlan(id, dto, principal, request);
|
|
}
|
|
|
|
@Post(':id/plan/items/:itemId/resolve')
|
|
@RequirePermissions('asset_imports.manage')
|
|
resolvePlanItem(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Param('itemId', new ParseUUIDPipe({ version: '4' })) itemId: string,
|
|
@Body() dto: ResolveAssetImportPlanItemDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.resolvePlanItem(id, itemId, dto, principal, request);
|
|
}
|
|
|
|
@Post(':id/apply-safe')
|
|
@RequirePermissions('asset_imports.apply')
|
|
applySafePlan(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: ApplyAssetImportPlanDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.applySafePlan(id, dto, principal, request);
|
|
}
|
|
|
|
@Post(':id/apply')
|
|
@RequirePermissions('asset_imports.apply')
|
|
applyPlan(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: ApplyAssetImportPlanDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.applyPlan(id, dto, principal, request);
|
|
}
|
|
|
|
@Post(':id/rollback')
|
|
@RequirePermissions('asset_imports.apply')
|
|
rollbackPlan(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: RollbackAssetImportPlanDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.rollbackPlan(id, dto, principal, request);
|
|
}
|
|
|
|
@Get(':id/rows')
|
|
@RequirePermissions('asset_imports.read')
|
|
rows(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Query() query: ListAssetImportRowsQueryDto,
|
|
) {
|
|
return this.imports.rows(id, query);
|
|
}
|
|
|
|
@Post(':id/reconcile')
|
|
@RequirePermissions('asset_imports.manage')
|
|
reconcile(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.reconcile(id, principal, request);
|
|
}
|
|
|
|
@Post(':id/cancel')
|
|
@RequirePermissions('asset_imports.manage')
|
|
cancel(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: CancelAssetImportDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.imports.cancel(id, dto, principal, request);
|
|
}
|
|
}
|