diff --git a/src/elder-svc/dto.ts b/src/elder-svc/dto.ts index 0d6f593..675f788 100644 --- a/src/elder-svc/dto.ts +++ b/src/elder-svc/dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { ArrayNotEmpty, IsArray, IsIn, IsNotEmpty, IsString } from 'class-validator'; +import { IsArray, IsIn, IsNotEmpty, IsString } from 'class-validator'; /** 老人个人项目库整表覆盖入参:care_mode 为整库统一护理方式,svc_ids 落本机构 L4。 */ export class PutElderSvcDto { @@ -12,9 +12,8 @@ export class PutElderSvcDto { @IsIn(['inst_medical', 'inst_nursing', 'home_org', 'home_individual']) careMode!: string; - @ApiProperty({ description: '本机构 L4 项目库 svc_org.id 列表', type: [String] }) + @ApiProperty({ description: '本机构 L4 项目库 svc_org.id 列表(可空,空数组=清空项目库)', type: [String] }) @IsArray() - @ArrayNotEmpty() @IsString({ each: true }) svcIds!: string[]; } diff --git a/src/elder-svc/elder-svc.service.spec.ts b/src/elder-svc/elder-svc.service.spec.ts index efca83d..3340d6a 100644 --- a/src/elder-svc/elder-svc.service.spec.ts +++ b/src/elder-svc/elder-svc.service.spec.ts @@ -101,6 +101,23 @@ describe('ElderSvcService', () => { expect(res).toHaveLength(2); }); + it('put 空 svcIds 清空项目库:软删旧行、不写新行、返回空', async () => { + const elderSvcUpdateMany = vi.fn().mockResolvedValue({ count: 2 }); + const elderSvcCreate = vi.fn(); + const { service } = makeService({ elderSvcUpdateMany, elderSvcCreate }); + + const res = await runWithRequestContext(ctx, () => + service.put('e1', { careMode: 'inst_medical', svcIds: [] }), + ); + + expect(elderSvcUpdateMany).toHaveBeenCalledWith({ + where: { elderId: 'e1' }, + data: { deletedAt: expect.any(Date) }, + }); + expect(elderSvcCreate).not.toHaveBeenCalled(); + expect(res).toEqual([]); + }); + it('put 老人不存在 → ELDER_NOT_FOUND', async () => { const elderFindFirst = vi.fn().mockResolvedValue(null); const { service, elderSvcUpdateMany, elderSvcCreate } = makeService({ elderFindFirst });