鉴权改为登录态回库校验,新增 tokenValidAfter 失效时间,支持密码变更与 seed 重置后旧 token 立即失效 患者字段由 idCardHash 统一迁移为 idCard,新增身份证标准化逻辑并同步 C 端生命周期查询参数 组织模块增加小组删除限制(有成员时返回 409)并补充中文错误消息 任务取消接口支持可选 reason 字段(先透传事件层) 补齐 Prisma 迁移、文档说明和 E2E 用例(含设备模块与 token 失效场景)
103 lines
2.7 KiB
TypeScript
103 lines
2.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiOperation,
|
|
ApiParam,
|
|
ApiTags,
|
|
} from '@nestjs/swagger';
|
|
import { AccessTokenGuard } from '../../auth/access-token.guard.js';
|
|
import { CurrentActor } from '../../auth/current-actor.decorator.js';
|
|
import { Roles } from '../../auth/roles.decorator.js';
|
|
import { RolesGuard } from '../../auth/roles.guard.js';
|
|
import type { ActorContext } from '../../common/actor-context.js';
|
|
import { Role } from '../../generated/prisma/enums.js';
|
|
import { CreateDeviceDto } from '../dto/create-device.dto.js';
|
|
import { DeviceQueryDto } from '../dto/device-query.dto.js';
|
|
import { UpdateDeviceDto } from '../dto/update-device.dto.js';
|
|
import { DevicesService } from '../devices.service.js';
|
|
|
|
/**
|
|
* B 端设备控制器:仅管理员可访问设备 CRUD。
|
|
*/
|
|
@ApiTags('设备管理(B端)')
|
|
@ApiBearerAuth('bearer')
|
|
@Controller('b/devices')
|
|
@UseGuards(AccessTokenGuard, RolesGuard)
|
|
export class BDevicesController {
|
|
constructor(private readonly devicesService: DevicesService) {}
|
|
|
|
/**
|
|
* 查询设备列表。
|
|
*/
|
|
@Get()
|
|
@Roles(Role.SYSTEM_ADMIN, Role.HOSPITAL_ADMIN)
|
|
@ApiOperation({ summary: '查询设备列表' })
|
|
findAll(@CurrentActor() actor: ActorContext, @Query() query: DeviceQueryDto) {
|
|
return this.devicesService.findAll(actor, query);
|
|
}
|
|
|
|
/**
|
|
* 查询设备详情。
|
|
*/
|
|
@Get(':id')
|
|
@Roles(Role.SYSTEM_ADMIN, Role.HOSPITAL_ADMIN)
|
|
@ApiOperation({ summary: '查询设备详情' })
|
|
@ApiParam({ name: 'id', description: '设备 ID' })
|
|
findOne(
|
|
@CurrentActor() actor: ActorContext,
|
|
@Param('id', ParseIntPipe) id: number,
|
|
) {
|
|
return this.devicesService.findOne(actor, id);
|
|
}
|
|
|
|
/**
|
|
* 创建设备。
|
|
*/
|
|
@Post()
|
|
@Roles(Role.SYSTEM_ADMIN, Role.HOSPITAL_ADMIN)
|
|
@ApiOperation({ summary: '创建设备' })
|
|
create(@CurrentActor() actor: ActorContext, @Body() dto: CreateDeviceDto) {
|
|
return this.devicesService.create(actor, dto);
|
|
}
|
|
|
|
/**
|
|
* 更新设备。
|
|
*/
|
|
@Patch(':id')
|
|
@Roles(Role.SYSTEM_ADMIN, Role.HOSPITAL_ADMIN)
|
|
@ApiOperation({ summary: '更新设备' })
|
|
@ApiParam({ name: 'id', description: '设备 ID' })
|
|
update(
|
|
@CurrentActor() actor: ActorContext,
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@Body() dto: UpdateDeviceDto,
|
|
) {
|
|
return this.devicesService.update(actor, id, dto);
|
|
}
|
|
|
|
/**
|
|
* 删除设备。
|
|
*/
|
|
@Delete(':id')
|
|
@Roles(Role.SYSTEM_ADMIN, Role.HOSPITAL_ADMIN)
|
|
@ApiOperation({ summary: '删除设备' })
|
|
@ApiParam({ name: 'id', description: '设备 ID' })
|
|
remove(
|
|
@CurrentActor() actor: ActorContext,
|
|
@Param('id', ParseIntPipe) id: number,
|
|
) {
|
|
return this.devicesService.remove(actor, id);
|
|
}
|
|
}
|