【发布时间】:2021-04-06 07:09:02
【问题描述】:
我这里有一些奇怪的问题。我有 2 种获取方法,一种是通过 companyId 获取员工列表并通过 StaffId 获取员工详细信息。第二种方法getStaffById 不起作用。如果我注释掉第一个获取方法getStaffByCompanyId,第二个按预期工作。看起来第一个 get 方法阻止了第二种方法。我在这里遗漏了什么吗?
@Controller('staff')
@ApiTags('Staff')
export class StaffController {
constructor(private staffService: StaffService) {}
@Get(':companyId')
@ApiResponse({
status: HttpStatus.OK,
description: 'Return staffs by id',
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Unauthorized',
type: Error,
})
@ApiResponse({
status: HttpStatus.UNPROCESSABLE_ENTITY,
description: 'Get particular staff details',
type: Error,
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'Internal server error',
type: Error,
})
@ApiResponse({
status: HttpStatus.BAD_GATEWAY,
description: 'Internal communication error',
type: Error,
})
@ApiOperation({
operationId: 'getStaffByCompanyId',
summary: 'Get staff list that attach to the company',
})
async getStaffByCompanyId(@Param('companyId') companyId: string): Promise<IStaff[]> {
return await this.staffService.getStaffByCompanyId(companyId);
}
@Get(':staffId')
@ApiResponse({
status: HttpStatus.OK,
description: 'Return staff by id',
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Unauthorized',
type: Error,
})
@ApiResponse({
status: HttpStatus.UNPROCESSABLE_ENTITY,
description: 'Get particular staff details',
type: Error,
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'Internal server error',
type: Error,
})
@ApiResponse({
status: HttpStatus.BAD_GATEWAY,
description: 'Internal communication error',
type: Error,
})
@ApiOperation({
operationId: 'getStaffById',
summary: 'Get staff profile details',
})
async getStaffById(@Param('staffId') staffId: string): Promise<IStaff> {
return await this.staffService.getStaffById(staffId);
}
}
【问题讨论】:
-
要添加到 Jay 响应中,您必须阅读 REST API 中的“资源”概念。因为员工和公司是不同的对象,他们应该有不同的路径