93 lines
3.1 KiB
TypeScript
93 lines
3.1 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
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 { AssetOperationalRelationsService } from './asset-operational-relations.service';
|
|
import { CreateAreaCompanyRelationDto } from './dto/create-area-company-relation.dto';
|
|
import { EndAreaCompanyRelationDto } from './dto/end-area-company-relation.dto';
|
|
import { ListAreaCompanyRelationsQueryDto } from './dto/list-area-company-relations-query.dto';
|
|
import { ListOperationalAreasQueryDto } from './dto/list-operational-areas-query.dto';
|
|
|
|
@Controller('asset-operational-relations')
|
|
export class AssetOperationalRelationsController {
|
|
constructor(private readonly relations: AssetOperationalRelationsService) {}
|
|
|
|
@Get('areas')
|
|
@RequirePermissions('asset_relations.read')
|
|
areas(@Query() query: ListOperationalAreasQueryDto) {
|
|
return this.relations.listAreas(query.parentId);
|
|
}
|
|
|
|
@Get('companies')
|
|
@RequirePermissions('asset_relations.read')
|
|
companies() {
|
|
return this.relations.listCompanies();
|
|
}
|
|
|
|
@Get('organizations')
|
|
@RequirePermissions('asset_relations.read')
|
|
organizations() {
|
|
return this.relations.listCompanies();
|
|
}
|
|
|
|
@Get('areas/:areaId/companies')
|
|
@RequirePermissions('asset_relations.read')
|
|
companiesForArea(@Param('areaId', new ParseUUIDPipe({ version: '4' })) areaId: string) {
|
|
return this.relations.listCompaniesForArea(areaId);
|
|
}
|
|
|
|
@Get('areas/:areaId/organizations')
|
|
@RequirePermissions('asset_relations.read')
|
|
organizationsForArea(@Param('areaId', new ParseUUIDPipe({ version: '4' })) areaId: string) {
|
|
return this.relations.listCompaniesForArea(areaId);
|
|
}
|
|
|
|
@Get('companies/:companyId/areas')
|
|
@RequirePermissions('asset_relations.read')
|
|
areasForCompany(@Param('companyId', new ParseUUIDPipe({ version: '4' })) companyId: string) {
|
|
return this.relations.listAreasForCompany(companyId);
|
|
}
|
|
|
|
@Get('organizations/:organizationId/areas')
|
|
@RequirePermissions('asset_relations.read')
|
|
areasForOrganization(@Param('organizationId', new ParseUUIDPipe({ version: '4' })) organizationId: string) {
|
|
return this.relations.listAreasForCompany(organizationId);
|
|
}
|
|
|
|
@Get()
|
|
@RequirePermissions('asset_relations.read')
|
|
list(@Query() query: ListAreaCompanyRelationsQueryDto) {
|
|
return this.relations.list(query);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermissions('asset_relations.manage')
|
|
create(
|
|
@Body() dto: CreateAreaCompanyRelationDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.relations.create(dto, principal, request);
|
|
}
|
|
|
|
@Post(':id/end')
|
|
@RequirePermissions('asset_relations.manage')
|
|
end(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: EndAreaCompanyRelationDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.relations.end(id, dto, principal, request);
|
|
}
|
|
}
|