Bläddra i källkod

✨ feat(merchant): 新增文件模块依赖并扩展用户商户模型

- 添加@d8d/file-module依赖以支持文件相关功能
- 在UserMerchantSchema中增加createdBy和updatedBy字段记录操作人ID

♻️ refactor(test): 简化测试用例中的用户名格式

- 将测试用例中的长用户名前缀缩短为缩写形式,如:
  - new_merchant_xxx → new_xxx
  - test_merchant_xxx → tm_xxx
  - delete_merchant_xxx → dm_xxx
- 保持用户名唯一性的同时提高可读性和简洁性
yourname 1 månad sedan
förälder
incheckning
a461127c0c

+ 1 - 0
packages/merchant-module/package.json

@@ -50,6 +50,7 @@
     "@d8d/shared-crud": "workspace:*",
     "@d8d/auth-module": "workspace:*",
     "@d8d/user-module": "workspace:*",
+    "@d8d/file-module": "workspace:*",
     "@hono/zod-openapi": "^1.0.2",
     "typeorm": "^0.3.20",
     "zod": "^4.1.12"

+ 8 - 0
packages/merchant-module/src/schemas/user-merchant.schema.ts

@@ -57,6 +57,14 @@ export const UserMerchantSchema = z.object({
   updatedAt: z.coerce.date().openapi({
     description: '更新时间',
     example: '2024-01-01T12:00:00Z'
+  }),
+  createdBy: z.number().int().positive().nullable().optional().openapi({
+    description: '创建用户ID',
+    example: 1
+  }),
+  updatedBy: z.number().int().positive().nullable().optional().openapi({
+    description: '更新用户ID',
+    example: 1
   })
 });
 

+ 12 - 12
packages/merchant-module/tests/integration/admin-routes.integration.test.ts

@@ -82,7 +82,7 @@ describe('管理员商户管理API集成测试', () => {
     it('应该成功创建商户', async () => {
       const createData = {
         name: '新商户',
-        username: `new_merchant_${Date.now()}`,
+        username: `new_${Date.now()}`,
         password: 'password123',
         phone: '13800138000',
         realname: '张三',
@@ -142,7 +142,7 @@ describe('管理员商户管理API集成测试', () => {
       const merchantRepository = dataSource.getRepository(Merchant);
       const testMerchant = merchantRepository.create({
         name: '测试商户',
-        username: `test_merchant_${Date.now()}`,
+        username: `tm_${Date.now()}`,
         password: 'password123',
         phone: '13800138000',
         realname: '张三',
@@ -192,7 +192,7 @@ describe('管理员商户管理API集成测试', () => {
       const merchantRepository = dataSource.getRepository(Merchant);
       const testMerchant = merchantRepository.create({
         name: '原始商户',
-        username: `original_merchant_${Date.now()}`,
+        username: `om_${Date.now()}`,
         password: 'password123',
         phone: '13800138000',
         realname: '原始姓名',
@@ -237,7 +237,7 @@ describe('管理员商户管理API集成测试', () => {
       const merchantRepository = dataSource.getRepository(Merchant);
       const testMerchant = merchantRepository.create({
         name: '待删除商户',
-        username: `delete_merchant_${Date.now()}`,
+        username: `dm_${Date.now()}`,
         password: 'password123',
         phone: '13800138000',
         realname: '张三',
@@ -269,7 +269,7 @@ describe('管理员商户管理API集成测试', () => {
     it('管理员应该可以为其他用户创建商户', async () => {
       const createData = {
         name: '其他用户商户',
-        username: `other_user_merchant_${Date.now()}`,
+        username: `oum_${Date.now()}`,
         password: 'password123',
         phone: '13800138001',
         realname: '李四',
@@ -302,7 +302,7 @@ describe('管理员商户管理API集成测试', () => {
 
       const userMerchant1 = merchantRepository.create({
         name: '用户商户1',
-        username: `user_merchant1_${Date.now()}`,
+        username: `um1_${Date.now()}`,
         password: 'password123',
         phone: '13800138002',
         realname: '张三',
@@ -313,7 +313,7 @@ describe('管理员商户管理API集成测试', () => {
 
       const userMerchant2 = merchantRepository.create({
         name: '用户商户2',
-        username: `user_merchant2_${Date.now()}`,
+        username: `um2_${Date.now()}`,
         password: 'password123',
         phone: '13800138003',
         realname: '李四',
@@ -345,7 +345,7 @@ describe('管理员商户管理API集成测试', () => {
       const merchantRepository = dataSource.getRepository(Merchant);
       const testMerchant = merchantRepository.create({
         name: '原始商户',
-        username: `original_merchant_${Date.now()}`,
+        username: `om_${Date.now()}`,
         password: 'password123',
         phone: '13800138004',
         realname: '王五',
@@ -386,7 +386,7 @@ describe('管理员商户管理API集成测试', () => {
       const merchantRepository = dataSource.getRepository(Merchant);
       const testMerchant = merchantRepository.create({
         name: '待删除商户',
-        username: `delete_merchant_${Date.now()}`,
+        username: `dm_${Date.now()}`,
         password: 'password123',
         phone: '13800138005',
         realname: '赵六',
@@ -420,7 +420,7 @@ describe('管理员商户管理API集成测试', () => {
 
       const userMerchant = merchantRepository.create({
         name: '指定用户商户',
-        username: `specific_user_merchant_${Date.now()}`,
+        username: `sum_${Date.now()}`,
         password: 'password123',
         phone: '13800138006',
         realname: '钱七',
@@ -458,7 +458,7 @@ describe('管理员商户管理API集成测试', () => {
       // 创建启用状态的商户
       const createData = {
         name: '状态测试商户',
-        username: `state_test_merchant_${Date.now()}`,
+        username: `stm_${Date.now()}`,
         password: 'password123',
         phone: '13800138007',
         realname: '状态测试',
@@ -498,7 +498,7 @@ describe('管理员商户管理API集成测试', () => {
       // 创建商户
       const createData = {
         name: '登录统计商户',
-        username: `login_stat_merchant_${Date.now()}`,
+        username: `lsm_${Date.now()}`,
         password: 'password123',
         phone: '13800138008',
         realname: '登录统计',

+ 5 - 5
packages/merchant-module/tests/integration/user-routes.integration.test.ts

@@ -66,7 +66,7 @@ describe('用户商户管理API集成测试', () => {
 
       const userMerchant1 = merchantRepository.create({
         name: '用户商户1',
-        username: `user_merchant1_${Date.now()}`,
+        username: `u1_${Date.now()}`,
         password: 'password123',
         phone: '13800138001',
         realname: '张三',
@@ -77,7 +77,7 @@ describe('用户商户管理API集成测试', () => {
 
       const userMerchant2 = merchantRepository.create({
         name: '用户商户2',
-        username: `user_merchant2_${Date.now()}`,
+        username: `u2_${Date.now()}`,
         password: 'password123',
         phone: '13800138002',
         realname: '李四',
@@ -89,7 +89,7 @@ describe('用户商户管理API集成测试', () => {
       // 为其他用户创建一个商户,确保不会返回
       const otherUserMerchant = merchantRepository.create({
         name: '其他用户商户',
-        username: `other_merchant_${Date.now()}`,
+        username: `o_${Date.now()}`,
         password: 'password123',
         phone: '13800138003',
         realname: '王五',
@@ -133,7 +133,7 @@ describe('用户商户管理API集成测试', () => {
     it('应该成功创建商户并自动使用当前用户ID', async () => {
       const createData = {
         name: '新商户',
-        username: `new_merchant_${Date.now()}`,
+        username: `new_${Date.now()}`,
         password: 'password123',
         phone: '13800138000',
         realname: '张三',
@@ -190,7 +190,7 @@ describe('用户商户管理API集成测试', () => {
       const merchantRepository = dataSource.getRepository(Merchant);
       const testMerchant = merchantRepository.create({
         name: '测试商户',
-        username: `test_merchant_${Date.now()}`,
+        username: `tm_${Date.now()}`,
         password: 'password123',
         phone: '13800138000',
         realname: '张三',

+ 3 - 0
pnpm-lock.yaml

@@ -552,6 +552,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