Draft
As a system administrator, I want to replicate the merchant module with multi-tenant support, so that merchants can be managed in a tenant-isolated environment while maintaining full compatibility with the existing single-tenant system.
@d8d/merchant-module as @d8d/merchant-module-mt with proper package configurationMerchantMt with tenant ID field and table name merchants_mt[ ] Replicate merchant module as multi-tenant version (AC: 1)
packages/merchant-module to packages/merchant-module-mt@d8d/merchant-module-mt@d8d/user-module with @d8d/user-module-mt@d8d/auth-module with @d8d/auth-module-mt@d8d/file-module with @d8d/file-module-mt[ ] Update multi-tenant merchant entity (AC: 2)
MerchantMt entity with table name merchants_mttenantId field with proper TypeORM configuration[ ] Update multi-tenant merchant service (AC: 3, 4)
MerchantServiceMt service extending GenericCrudService[ ] Update multi-tenant route configurations (AC: 3)
[ ] Update Schema definitions (AC: 3)
MerchantSchemaMtUserMerchantSchemaMtAdminMerchantSchemaMt[ ] Implement tenant data isolation API tests (AC: 7)
packages/merchant-module-mt/tests/integration/user-routes.integration.test.tspackages/merchant-module-mt/tests/integration/admin-routes.integration.test.tstenant-isolation.integration.test.ts[ ] Validate single-tenant system integrity (AC: 5, 6)
[ ] Execute performance benchmark tests (AC: 8)
Critical lessons learned from Story 007.006 (Address Module):
.mt.ts suffix for multi-tenant files [Source: epic-007-multi-tenant-package-replication.md#最佳实践]fileParallelism: false in vitest config to avoid database conflicts [Source: epic-007-multi-tenant-package-replication.md#技术挑战和解决方案]Merchant Entity Structure:
merchants_mt (multi-tenant version)tenantId (required, indexed)name, username, password, phone, realname, loginNum, loginTime, loginIp, lastLoginTime, lastLoginIp, state, rsaPublicKey, aesKey [Source: source-tree.md#商户管理模块]createdBy, updatedBy [Source: source-tree.md#商户管理模块]createdAt, updatedAt [Source: source-tree.md#商户管理模块]User Routes:
/api/merchants (user-specific)authMiddleware from @d8d/auth-module-mt [Source: source-tree.md#商户管理模块]userIdField: 'createdBy' [Source: source-tree.md#商户管理模块]['name', 'username', 'realname', 'phone'] [Source: source-tree.md#商户管理模块]Admin Routes:
/api/admin/merchants (full access)authMiddleware from @d8d/auth-module-mt [Source: source-tree.md#商户管理模块]Merchant Service Methods:
updateLoginStats(merchantId, loginTime, loginIp): Update merchant login statistics [Source: source-tree.md#商户管理模块]findByUsername(username): Find merchant by username with tenant filtering [Source: source-tree.md#商户管理模块]getByState(state): Get merchants by state with tenant filtering [Source: source-tree.md#商户管理模块]Source Files to Create:
packages/merchant-module-mt/src/entities/merchant.mt.entity.ts (multi-tenant entity)packages/merchant-module-mt/src/services/merchant.mt.service.ts (multi-tenant service)packages/merchant-module-mt/src/routes/user-routes.mt.ts (multi-tenant user routes)packages/merchant-module-mt/src/routes/admin-routes.mt.ts (multi-tenant admin routes)packages/merchant-module-mt/src/schemas/merchant.mt.schema.ts (multi-tenant schemas)packages/merchant-module-mt/tests/integration/tenant-isolation.integration.test.ts (tenant isolation tests)Files to Remove (Single-tenant cleanup):
.mt.ts suffix in multi-tenant packageDatabase Indexing:
tenantId field for performance [Source: epic-007-multi-tenant-package-replication.md#数据库迁移策略]Authentication Integration:
authMiddleware from @d8d/auth-module-mt that extracts tenant ID from user context [Source: epic-007-multi-tenant-package-replication.md#租户上下文管理]Testing Standards:
packages/merchant-module-mt/tests/integration/ [Source: testing-strategy.md#集成测试]Specific Testing Requirements:
| Date | Version | Description | Author |
|---|---|---|---|
| 2025-11-14 | 1.0 | Initial story creation with comprehensive lessons learned from previous stories | Bob (Scrum Master) |
This section will be populated by the development agent during implementation
This section will be populated by the QA agent during quality assurance review