diff --git a/furniture-3d-system/src/server/services/__tests__/user.service.test.ts b/furniture-3d-system/src/server/services/__tests__/user.service.test.ts index bf7ffbe2..5906ecff 100644 --- a/furniture-3d-system/src/server/services/__tests__/user.service.test.ts +++ b/furniture-3d-system/src/server/services/__tests__/user.service.test.ts @@ -122,6 +122,16 @@ describe('userService master-data normalization', () => { })) }) + it('update 允许保存外部录入员业务类型', async () => { + await userService.update('user-1', { + businessRoles: ['EXTERNAL_INTAKE'], + }) + + expect(mockUpdateWithScalars).toHaveBeenCalledWith('user-1', expect.objectContaining({ + businessRoles: ['EXTERNAL_INTAKE'], + })) + }) + it('业务类型出现游离值时拒绝写入', async () => { await expect( userService.create({ diff --git a/furniture-3d-system/src/server/services/user.service.ts b/furniture-3d-system/src/server/services/user.service.ts index b0e839d9..fdcbd884 100644 --- a/furniture-3d-system/src/server/services/user.service.ts +++ b/furniture-3d-system/src/server/services/user.service.ts @@ -1,4 +1,5 @@ import { hashPassword, validatePasswordStrength, verifyPassword } from '@/lib/password' +import { BUSINESS_ACCOUNT_TYPE_OPTIONS } from '@/lib/business-account-types' import { AppError, ErrorCode } from '@/server/core/errors' import type { BusinessAccountType, EmployeeSourceStatus, Role, UserStatus } from '@prisma/client' import { departmentRepository } from '../repositories/department.repository' @@ -89,13 +90,9 @@ export interface UserDTO { const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ const NAME_REGEX = /^[\u4e00-\u9fa5a-zA-Z0-9_]{2,20}$/ const GENERIC_LOGIN_ERROR_MESSAGE = '账号或密码错误' -const BUSINESS_ROLE_SET = new Set([ - 'DESIGN', - 'PLANNING', - 'PURCHASING', - 'WAREHOUSE', - 'SUPPLIER', -]) +const BUSINESS_ROLE_SET = new Set( + BUSINESS_ACCOUNT_TYPE_OPTIONS.map((option) => option.value), +) function normalizeEmail(email: string): string { return email.trim().toLowerCase()