Browse Source

fix: 修复 disabled-person 服务中已删除状态的标签返回 undefined 问题

- 修复 findAllForCompany 和 findOneForCompany 方法中 workStatusLabel 计算逻辑
- 使用 nullish coalescing 确保无效状态(如已删除的 not_working)返回 '未知状态'
- 修复测试文件中的类型问题

Co-Authored-By: Claude <noreply@anthropic.com>
yourname 1 week ago
parent
commit
d555fa36e7

+ 4 - 2
allin-packages/disability-module/src/services/disabled-person.service.ts

@@ -601,7 +601,8 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
     // 转换结果格式 - 注意:PostgreSQL列名是小写的
     // 转换结果格式 - 注意:PostgreSQL列名是小写的
     const data = rawResults.map((row) => {
     const data = rawResults.map((row) => {
       const workStatus = row.workstatus as WorkStatus | undefined;
       const workStatus = row.workstatus as WorkStatus | undefined;
-      const workStatusLabel = workStatus ? workStatusLabelMap[workStatus] : '未知状态';
+      // 使用 nullish coalescing 确保无效状态返回 '未知状态'
+      const workStatusLabel = workStatus !== undefined ? (workStatusLabelMap[workStatus] ?? '未知状态') : '未知状态';
 
 
       return {
       return {
         personId: row.personid,
         personId: row.personid,
@@ -681,7 +682,8 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
 
 
     // 确定工作状态
     // 确定工作状态
     const workStatus = latestOrderPerson?.workStatus as WorkStatus | undefined;
     const workStatus = latestOrderPerson?.workStatus as WorkStatus | undefined;
-    const workStatusLabel = workStatus ? workStatusLabelMap[workStatus] : '未知状态';
+    // 使用 nullish coalescing 确保无效状态返回 '未知状态'
+    const workStatusLabel = workStatus !== undefined ? (workStatusLabelMap[workStatus] ?? '未知状态') : '未知状态';
 
 
     return {
     return {
       personId: person.id,
       personId: person.id,

+ 2 - 3
allin-packages/disability-module/tests/unit/find-persons-with-company.test.ts

@@ -1,6 +1,5 @@
 import { describe, it, expect, beforeEach, vi } from 'vitest';
 import { describe, it, expect, beforeEach, vi } from 'vitest';
 import { DisabledPersonService } from '../../src/services/disabled-person.service';
 import { DisabledPersonService } from '../../src/services/disabled-person.service';
-import { DisabledPerson } from '../../src/entities/disabled-person.entity';
 import { Repository, DataSource } from 'typeorm';
 import { Repository, DataSource } from 'typeorm';
 import { OrderPerson } from '@d8d/allin-order-module/entities';
 import { OrderPerson } from '@d8d/allin-order-module/entities';
 
 
@@ -34,12 +33,12 @@ describe('DisabledPersonService - findPersonsWithCompany', () => {
 
 
     // 创建 DataSource 模拟
     // 创建 DataSource 模拟
     mockDataSource = {
     mockDataSource = {
-      getRepository: vi.fn((entity) => {
+      getRepository: vi.fn((entity: any) => {
         if (entity === OrderPerson) {
         if (entity === OrderPerson) {
           return mockOrderPersonRepository;
           return mockOrderPersonRepository;
         }
         }
         return {};
         return {};
-      })
+      }) as any
     };
     };
 
 
     // @ts-ignore - 创建实例
     // @ts-ignore - 创建实例