52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { Controller, Post, Body, UseGuards, HttpCode, HttpStatus } from '@nestjs/common'
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger'
|
|
import { AuthorizationApplicationService } from '@/application/services'
|
|
import { GrantProvinceCompanyCommand, GrantCityCompanyCommand } from '@/application/commands'
|
|
import { GrantProvinceCompanyDto, GrantCityCompanyDto } from '@/api/dto/request'
|
|
import { CurrentUser } from '@/shared/decorators'
|
|
import { JwtAuthGuard } from '@/shared/guards'
|
|
|
|
@ApiTags('Admin Authorization')
|
|
@Controller('admin/authorizations')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
export class AdminAuthorizationController {
|
|
constructor(private readonly applicationService: AuthorizationApplicationService) {}
|
|
|
|
@Post('province-company')
|
|
@HttpCode(HttpStatus.CREATED)
|
|
@ApiOperation({ summary: '授权正式省公司(管理员)' })
|
|
@ApiResponse({ status: 201, description: '授权成功' })
|
|
async grantProvinceCompany(
|
|
@CurrentUser() user: { userId: string },
|
|
@Body() dto: GrantProvinceCompanyDto,
|
|
): Promise<{ message: string }> {
|
|
const command = new GrantProvinceCompanyCommand(
|
|
dto.userId,
|
|
dto.provinceCode,
|
|
dto.provinceName,
|
|
user.userId,
|
|
)
|
|
await this.applicationService.grantProvinceCompany(command)
|
|
return { message: '正式省公司授权成功' }
|
|
}
|
|
|
|
@Post('city-company')
|
|
@HttpCode(HttpStatus.CREATED)
|
|
@ApiOperation({ summary: '授权正式市公司(管理员)' })
|
|
@ApiResponse({ status: 201, description: '授权成功' })
|
|
async grantCityCompany(
|
|
@CurrentUser() user: { userId: string },
|
|
@Body() dto: GrantCityCompanyDto,
|
|
): Promise<{ message: string }> {
|
|
const command = new GrantCityCompanyCommand(
|
|
dto.userId,
|
|
dto.cityCode,
|
|
dto.cityName,
|
|
user.userId,
|
|
)
|
|
await this.applicationService.grantCityCompany(command)
|
|
return { message: '正式市公司授权成功' }
|
|
}
|
|
}
|