Преглед изворни кода

✨ feat(supplier): 增加用户名长度限制至50个字符

- 修改数据库实体中username字段长度从20调整为50
- 更新所有相关schema验证规则,将max限制改为50
- 调整错误提示信息为"用户名最多50个字符"

♻️ refactor(test): 优化测试用例中用户名生成方式

- 将测试中使用Date.now()生成用户名的方式替换为随机数
- 减少因时间戳导致的测试数据冲突问题,提高测试稳定性

🔧 chore(config): 更新命令白名单配置

- 添加"pnpm --filter * test:integration:*"命令到允许列表
- 支持带filter参数的集成测试命令执行

📦 build(deps): 添加file-module依赖

- 在supplier-module中引入@d8d/file-module工作区依赖
yourname пре 1 месец
родитељ
комит
c0d1a91a42

+ 2 - 1
.claude/settings.local.json

@@ -45,7 +45,8 @@
       "Bash(pnpm run test:integration:*)",
       "Bash(pnpm install:*)",
       "Bash(cat:*)",
-      "Bash(pnpm test:integration:*)"
+      "Bash(pnpm test:integration:*)",
+      "Bash(pnpm --filter * test:integration:*)"
     ],
     "deny": [],
     "ask": []

+ 1 - 1
packages/supplier-module/src/entities/supplier.entity.ts

@@ -8,7 +8,7 @@ export class Supplier {
   @Column({ name: 'name', type: 'varchar', length: 255, nullable: true, comment: '供货商名称' })
   name!: string | null;
 
-  @Column({ name: 'username', type: 'varchar', length: 20, unique: true, comment: '用户名' })
+  @Column({ name: 'username', type: 'varchar', length: 50, unique: true, comment: '用户名' })
   username!: string;
 
   @Column({ name: 'password', type: 'varchar', length: 255, comment: '密码' })

+ 3 - 3
packages/supplier-module/src/schemas/admin-supplier.schema.ts

@@ -6,7 +6,7 @@ export const AdminSupplierSchema = z.object({
     description: '供货商名称',
     example: '供应商A'
   }),
-  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
+  username: z.string().min(1, '用户名不能为空').max(50, '用户名最多50个字符').openapi({
     description: '用户名',
     example: 'supplier001'
   }),
@@ -65,7 +65,7 @@ export const CreateAdminSupplierDto = z.object({
     description: '供货商名称',
     example: '供应商A'
   }),
-  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
+  username: z.string().min(1, '用户名不能为空').max(50, '用户名最多50个字符').openapi({
     description: '用户名',
     example: 'supplier001'
   }),
@@ -96,7 +96,7 @@ export const UpdateAdminSupplierDto = z.object({
     description: '供货商名称',
     example: '供应商A'
   }),
-  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').optional().openapi({
+  username: z.string().min(1, '用户名不能为空').max(50, '用户名最多50个字符').optional().openapi({
     description: '用户名',
     example: 'supplier001'
   }),

+ 3 - 3
packages/supplier-module/src/schemas/user-supplier.schema.ts

@@ -6,7 +6,7 @@ export const UserSupplierSchema = z.object({
     description: '供货商名称',
     example: '供应商A'
   }),
-  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
+  username: z.string().min(1, '用户名不能为空').max(50, '用户名最多50个字符').openapi({
     description: '用户名',
     example: 'supplier001'
   }),
@@ -61,7 +61,7 @@ export const CreateUserSupplierDto = z.object({
     description: '供货商名称',
     example: '供应商A'
   }),
-  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
+  username: z.string().min(1, '用户名不能为空').max(50, '用户名最多50个字符').openapi({
     description: '用户名',
     example: 'supplier001'
   }),
@@ -88,7 +88,7 @@ export const UpdateUserSupplierDto = z.object({
     description: '供货商名称',
     example: '供应商A'
   }),
-  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').optional().openapi({
+  username: z.string().min(1, '用户名不能为空').max(50, '用户名最多50个字符').optional().openapi({
     description: '用户名',
     example: 'supplier001'
   }),

+ 14 - 14
packages/supplier-module/tests/integration/admin-routes.integration.test.ts

@@ -26,7 +26,7 @@ describe('管理员供应商管理API集成测试', () => {
     // 创建测试用户
     const userRepository = dataSource.getRepository(UserEntity);
     testUser = userRepository.create({
-      username: `test_user_${Date.now()}`,
+      username: `test_user_${Math.floor(Math.random() * 100000)}`,
       password: 'test_password',
       nickname: '测试用户',
       registrationSource: 'web'
@@ -35,7 +35,7 @@ describe('管理员供应商管理API集成测试', () => {
 
     // 创建测试管理员用户
     testAdmin = userRepository.create({
-      username: `test_admin_${Date.now()}`,
+      username: `test_admin_${Math.floor(Math.random() * 100000)}`,
       password: 'admin_password',
       nickname: '测试管理员',
       registrationSource: 'web'
@@ -82,7 +82,7 @@ describe('管理员供应商管理API集成测试', () => {
     it('应该成功创建供应商', async () => {
       const createData = {
         name: '管理员创建供应商',
-        username: `admin_created_supplier_${Date.now()}`,
+        username: `admin_created_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138000',
         realname: '管理员创建供应商',
@@ -144,7 +144,7 @@ describe('管理员供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '测试供应商详情',
-        username: `test_supplier_detail_${Date.now()}`,
+        username: `test_supplier_detail_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13600136000',
         realname: '测试供应商详情',
@@ -199,7 +199,7 @@ describe('管理员供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '原始供应商',
-        username: `original_supplier_${Date.now()}`,
+        username: `original_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13500135000',
         realname: '原始供应商',
@@ -249,7 +249,7 @@ describe('管理员供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '待删除供应商',
-        username: `delete_supplier_${Date.now()}`,
+        username: `delete_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13400134000',
         realname: '待删除供应商',
@@ -286,7 +286,7 @@ describe('管理员供应商管理API集成测试', () => {
     it('管理员应该可以为其他用户创建供应商', async () => {
       const createData = {
         name: '为其他用户创建供应商',
-        username: `other_user_supplier_${Date.now()}`,
+        username: `other_user_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138001',
         realname: '为其他用户创建供应商',
@@ -319,7 +319,7 @@ describe('管理员供应商管理API集成测试', () => {
 
       const userSupplier1 = supplierRepository.create({
         name: '用户供应商1',
-        username: `user_supplier1_${Date.now()}`,
+        username: `user_supplier1_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138002',
         realname: '用户供应商1',
@@ -335,7 +335,7 @@ describe('管理员供应商管理API集成测试', () => {
 
       const userSupplier2 = supplierRepository.create({
         name: '用户供应商2',
-        username: `user_supplier2_${Date.now()}`,
+        username: `user_supplier2_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138003',
         realname: '用户供应商2',
@@ -372,7 +372,7 @@ describe('管理员供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '原始供应商',
-        username: `original_supplier_admin_${Date.now()}`,
+        username: `original_supplier_admin_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138004',
         realname: '原始供应商',
@@ -418,7 +418,7 @@ describe('管理员供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '待删除供应商',
-        username: `delete_supplier_admin_${Date.now()}`,
+        username: `delete_supplier_admin_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138005',
         realname: '待删除供应商',
@@ -457,7 +457,7 @@ describe('管理员供应商管理API集成测试', () => {
 
       const userSupplier = supplierRepository.create({
         name: '指定用户供应商',
-        username: `specified_user_supplier_${Date.now()}`,
+        username: `specified_user_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138006',
         realname: '指定用户供应商',
@@ -500,7 +500,7 @@ describe('管理员供应商管理API集成测试', () => {
       // 创建启用状态的供应商
       const createData = {
         name: '状态测试供应商',
-        username: `status_test_supplier_${Date.now()}`,
+        username: `status_test_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138007',
         realname: '状态测试供应商',
@@ -543,7 +543,7 @@ describe('管理员供应商管理API集成测试', () => {
       // 创建供应商
       const createData = {
         name: '登录统计供应商',
-        username: `login_stat_supplier_${Date.now()}`,
+        username: `login_stat_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138008',
         realname: '登录统计供应商',

+ 16 - 16
packages/supplier-module/tests/integration/user-routes.integration.test.ts

@@ -27,7 +27,7 @@ describe('用户供应商管理API集成测试', () => {
     // 创建测试用户
     const userRepository = dataSource.getRepository(UserEntity);
     testUser = userRepository.create({
-      username: `test_user_${Date.now()}`,
+      username: `test_user_${Math.floor(Math.random() * 100000)}`,
       password: 'test_password',
       nickname: '测试用户',
       registrationSource: 'web'
@@ -36,7 +36,7 @@ describe('用户供应商管理API集成测试', () => {
 
     // 创建其他用户
     otherUser = userRepository.create({
-      username: `other_user_${Date.now()}`,
+      username: `other_user_${Math.floor(Math.random() * 100000)}`,
       password: 'other_password',
       nickname: '其他用户',
       registrationSource: 'web'
@@ -66,7 +66,7 @@ describe('用户供应商管理API集成测试', () => {
 
       const userSupplier1 = supplierRepository.create({
         name: '用户供应商1',
-        username: `user_supplier1_${Date.now()}`,
+        username: `user_supplier1_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138001',
         realname: '用户供应商1',
@@ -82,7 +82,7 @@ describe('用户供应商管理API集成测试', () => {
 
       const userSupplier2 = supplierRepository.create({
         name: '用户供应商2',
-        username: `user_supplier2_${Date.now()}`,
+        username: `user_supplier2_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138002',
         realname: '用户供应商2',
@@ -99,7 +99,7 @@ describe('用户供应商管理API集成测试', () => {
       // 为其他用户创建一个供应商,确保不会返回
       const otherUserSupplier = supplierRepository.create({
         name: '其他用户供应商',
-        username: `other_supplier_${Date.now()}`,
+        username: `other_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138003',
         realname: '其他用户供应商',
@@ -148,7 +148,7 @@ describe('用户供应商管理API集成测试', () => {
     it('应该成功创建供应商并自动使用当前用户ID', async () => {
       const createData = {
         name: '测试供应商',
-        username: `test_supplier_${Date.now()}`,
+        username: `test_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138000',
         realname: '测试供应商',
@@ -207,7 +207,7 @@ describe('用户供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '测试供应商详情',
-        username: `test_supplier_detail_${Date.now()}`,
+        username: `test_supplier_detail_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13600136000',
         realname: '测试供应商详情',
@@ -249,7 +249,7 @@ describe('用户供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const otherUserSupplier = supplierRepository.create({
         name: '其他用户供应商',
-        username: `other_supplier_detail_${Date.now()}`,
+        username: `other_supplier_detail_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13600136001',
         realname: '其他用户供应商',
@@ -296,7 +296,7 @@ describe('用户供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '原始供应商',
-        username: `original_supplier_${Date.now()}`,
+        username: `original_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13500135000',
         realname: '原始供应商',
@@ -344,7 +344,7 @@ describe('用户供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const otherUserSupplier = supplierRepository.create({
         name: '其他用户供应商',
-        username: `other_supplier_update_${Date.now()}`,
+        username: `other_supplier_update_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13500135001',
         realname: '其他用户供应商',
@@ -386,7 +386,7 @@ describe('用户供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const testSupplier = supplierRepository.create({
         name: '待删除供应商',
-        username: `delete_supplier_${Date.now()}`,
+        username: `delete_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13400134000',
         realname: '待删除供应商',
@@ -424,7 +424,7 @@ describe('用户供应商管理API集成测试', () => {
       const supplierRepository = dataSource.getRepository(Supplier);
       const otherUserSupplier = supplierRepository.create({
         name: '其他用户供应商',
-        username: `other_supplier_delete_${Date.now()}`,
+        username: `other_supplier_delete_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13400134001',
         realname: '其他用户供应商',
@@ -460,7 +460,7 @@ describe('用户供应商管理API集成测试', () => {
 
       const userSupplier = supplierRepository.create({
         name: '用户供应商',
-        username: `user_supplier_perm_${Date.now()}`,
+        username: `user_supplier_perm_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138004',
         realname: '用户供应商',
@@ -476,7 +476,7 @@ describe('用户供应商管理API集成测试', () => {
 
       const otherUserSupplier = supplierRepository.create({
         name: '其他用户供应商',
-        username: `other_supplier_perm_${Date.now()}`,
+        username: `other_supplier_perm_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138005',
         realname: '其他用户供应商',
@@ -547,7 +547,7 @@ describe('用户供应商管理API集成测试', () => {
       // 创建启用状态的供应商
       const createData = {
         name: '状态测试供应商',
-        username: `status_test_supplier_${Date.now()}`,
+        username: `status_test_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138006',
         realname: '状态测试供应商',
@@ -590,7 +590,7 @@ describe('用户供应商管理API集成测试', () => {
       // 创建供应商
       const createData = {
         name: '登录统计供应商',
-        username: `login_stat_supplier_${Date.now()}`,
+        username: `login_stat_supplier_${Math.floor(Math.random() * 100000)}`,
         password: 'password123',
         phone: '13800138007',
         realname: '登录统计供应商',

+ 3 - 0
pnpm-lock.yaml

@@ -873,6 +873,9 @@ importers:
       '@d8d/auth-module':
         specifier: workspace:*
         version: link:../auth-module
+      '@d8d/file-module':
+        specifier: workspace:*
+        version: link:../file-module
       '@d8d/shared-crud':
         specifier: workspace:*
         version: link:../shared-crud