create-dp-koa 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +50 -0
  2. package/index.mjs +97 -0
  3. package/package.json +33 -0
  4. package/template/.env.development +9 -0
  5. package/template/.env.production +12 -0
  6. package/template/.github/workflows/ci-cd.yml +182 -0
  7. package/template/.trae/documents/controller_development_plan.md +386 -0
  8. package/template/.trae/skills/00-backend-core.skill.md +50 -0
  9. package/template/.trae/skills/01-backend-skill-router.skill.md +55 -0
  10. package/template/.trae/skills/10-backend-api.skill.md +54 -0
  11. package/template/.trae/skills/11-backend-controller-recipes.skill.md +107 -0
  12. package/template/.trae/skills/20-backend-repository.skill.md +25 -0
  13. package/template/.trae/skills/21-backend-service.skill.md +135 -0
  14. package/template/.trae/skills/25-backend-comments-and-doc.skill.md +97 -0
  15. package/template/.trae/skills/30-backend-validation.skill.md +320 -0
  16. package/template/.trae/skills/40-backend-error-logging.skill.md +21 -0
  17. package/template/.trae/skills/50-backend-bootstrap-lifecycle.skill.md +90 -0
  18. package/template/.trae/skills/60-backend-router-registration.skill.md +71 -0
  19. package/template/.trae/skills/70-backend-middleware.skill.md +98 -0
  20. package/template/.trae/skills/80-backend-utils-and-libs.skill.md +90 -0
  21. package/template/.trae/skills/85-backend-plugins.rule.md +64 -0
  22. package/template/.trae/skills/90-backend-testing.skill.md +29 -0
  23. package/template/.trae/skills/README.md +49 -0
  24. package/template/.vscode/launch.json +38 -0
  25. package/template/.vscode/settings.json +1 -0
  26. package/template/Dockerfile +36 -0
  27. package/template/README.md +229 -0
  28. package/template/docker-compose.yml +135 -0
  29. package/template/docs/API_DOCUMENTATION.md +837 -0
  30. package/template/docs/ARCHITECTURE_REFACTOR.md +109 -0
  31. package/template/docs/CACHE_MIGRATION_GUIDE.md +142 -0
  32. package/template/docs/DEPLOYMENT_GUIDE.md +1062 -0
  33. package/template/docs/DEVELOPMENT_GUIDE.md +1097 -0
  34. package/template/docs/DOCUMENTATION_CLEANUP_REPORT.md +166 -0
  35. package/template/docs/DOCUMENTATION_COMPLETION_REPORT.md +223 -0
  36. package/template/docs/DOCUMENTATION_INDEX.md +294 -0
  37. package/template/docs/DOCUMENTATION_STRUCTURE.md +221 -0
  38. package/template/docs/ENTERPRISE_ANNOTATION_SYSTEM_GUIDE.md +2069 -0
  39. package/template/docs/ENTERPRISE_DATABASE_ARCHITECTURE.md +318 -0
  40. package/template/docs/ENTERPRISE_DEPLOYMENT_GUIDE.md +547 -0
  41. package/template/docs/ENTERPRISE_ERROR_HANDLING_GUIDE.md +357 -0
  42. package/template/docs/ENTERPRISE_LOGGING_SYSTEM_GUIDE.md +494 -0
  43. package/template/docs/ENVIRONMENT_CONFIG_EXAMPLE.md +69 -0
  44. package/template/docs/FINAL_IMPLEMENTATION_SUMMARY.md +206 -0
  45. package/template/docs/HEALTH_CHECK_ROUTE_FIX.md +134 -0
  46. package/template/docs/IMPLEMENTATION_CHECKLIST.md +204 -0
  47. package/template/docs/INSTALLATION_GUIDE.md +611 -0
  48. package/template/docs/INTERCEPTOR_TESTING_REPORT.md +226 -0
  49. package/template/docs/INTERCEPTOR_TESTING_SCRIPTS.md +143 -0
  50. package/template/docs/LOGGING_OPTIMIZATION_GUIDE.md +126 -0
  51. package/template/docs/MEMORY_DATABASE_GUIDE.md +212 -0
  52. package/template/docs/NEW_ROUTER_INTEGRATION_GUIDE.md +345 -0
  53. package/template/docs/NEW_ROUTER_INTEGRATION_SUMMARY.md +259 -0
  54. package/template/docs/NEW_ROUTER_USAGE_GUIDE.md +364 -0
  55. package/template/docs/QUICK_START.md +268 -0
  56. package/template/docs/ROUTE_SLASH_COMPATIBILITY_FIX.md +191 -0
  57. package/template/docs/SERVICE_INTERCEPTOR_GUIDE.md +243 -0
  58. package/template/docs/SERVICE_LAYER_INDEX.md +205 -0
  59. package/template/docs/SERVICE_PATTERN_GUIDE.md +270 -0
  60. package/template/docs/SERVICE_RETURN_VALUE_SPECIFICATION.md +466 -0
  61. package/template/docs/SWAGGER_DEBUG_MODE_GUIDE.md +80 -0
  62. package/template/docs/SWAGGER_INTEGRATION_GUIDE.md +416 -0
  63. package/template/docs/TRANSACTION_MANAGER_USAGE.md +360 -0
  64. package/template/docs/TROUBLESHOOTING.md +869 -0
  65. package/template/env.production.example +62 -0
  66. package/template/jest.config.js +34 -0
  67. package/template/package-lock.json +13240 -0
  68. package/template/package.json +119 -0
  69. package/template/patches/typeorm+0.3.25.patch +22 -0
  70. package/template/scripts/sync-template.mjs +84 -0
  71. package/template/scripts/test-annotation-system.sh +48 -0
  72. package/template/scripts/test-core-functionality.sh +28 -0
  73. package/template/src/annotations/decorators/ConfigManagement.ts +9 -0
  74. package/template/src/annotations/decorators/DistributedTracing.ts +9 -0
  75. package/template/src/annotations/decorators/EnterprisePerformance.ts +9 -0
  76. package/template/src/annotations/decorators/PerformanceMonitor.ts +32 -0
  77. package/template/src/annotations/decorators/SecurityAudit.ts +9 -0
  78. package/template/src/annotations/index.ts +50 -0
  79. package/template/src/annotations/processors/ConfigManagementProcessor.ts +369 -0
  80. package/template/src/annotations/processors/DistributedTracingProcessor.ts +288 -0
  81. package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +189 -0
  82. package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +101 -0
  83. package/template/src/annotations/processors/SecurityAuditProcessor.ts +345 -0
  84. package/template/src/annotations/processors/SwaggerProcessor.ts +612 -0
  85. package/template/src/annotations/processors/index.ts +10 -0
  86. package/template/src/app.ts +123 -0
  87. package/template/src/controllers/base.controller.ts +41 -0
  88. package/template/src/controllers/cacheManagement.controller.ts +131 -0
  89. package/template/src/controllers/captcha.controller.ts +57 -0
  90. package/template/src/controllers/demo/AnnotationDemoController.ts +118 -0
  91. package/template/src/controllers/example/EnterpriseExampleController.ts +297 -0
  92. package/template/src/controllers/example/ExampleController.ts +110 -0
  93. package/template/src/controllers/example/NewAnnotationExampleController.ts +159 -0
  94. package/template/src/controllers/example/SwaggerExampleController.ts +205 -0
  95. package/template/src/controllers/example/TransactionExample.controller.ts +336 -0
  96. package/template/src/controllers/health.controller.ts +235 -0
  97. package/template/src/controllers/home/register.controller.ts +58 -0
  98. package/template/src/controllers/home/ytGoods.controller.ts +92 -0
  99. package/template/src/controllers/home/ytShop.controller.ts +135 -0
  100. package/template/src/controllers/home/ytUser.controller.ts +89 -0
  101. package/template/src/controllers/logManagement.controller.ts +396 -0
  102. package/template/src/controllers/public/emailSend.controller.ts +65 -0
  103. package/template/src/controllers/public/ytUserAuth.controller.ts +174 -0
  104. package/template/src/controllers/testData.controller.ts +253 -0
  105. package/template/src/dto/controller/example/NewAnnotationExampleController.dto.ts +73 -0
  106. package/template/src/dto/controller/home/emailSend.controller.dto.ts +40 -0
  107. package/template/src/dto/controller/home/register.controller.dto.ts +45 -0
  108. package/template/src/dto/controller/home/ytGoods.controller.dto.ts +55 -0
  109. package/template/src/dto/controller/home/ytShop.controller.dto.ts +69 -0
  110. package/template/src/dto/controller/home/ytUser.controller.dto.ts +44 -0
  111. package/template/src/dto/controller/public/ytUserAuth.controller.dto.ts +63 -0
  112. package/template/src/dto/goods.dto.ts +212 -0
  113. package/template/src/dto/service/ytService.dto.ts +13 -0
  114. package/template/src/dto/user.dto.ts +177 -0
  115. package/template/src/entity/base.entity.ts +13 -0
  116. package/template/src/entity/columnTypes.ts +13 -0
  117. package/template/src/entity/goodsImagesUnlockKey.entity.ts +33 -0
  118. package/template/src/entity/goodsUnlocker.entity.ts +34 -0
  119. package/template/src/entity/index.ts +15 -0
  120. package/template/src/entity/shop.entity.ts +52 -0
  121. package/template/src/entity/shopUser.entity.ts +41 -0
  122. package/template/src/entity/ytGoods.entity.ts +94 -0
  123. package/template/src/entity/ytUser.entity.ts +96 -0
  124. package/template/src/examples/InterceptorExampleRunner.ts +284 -0
  125. package/template/src/examples/ServiceInterceptorExample.ts +214 -0
  126. package/template/src/examples/SwaggerProcessorExample.ts +169 -0
  127. package/template/src/examples/TransactionManagerDemo.ts +377 -0
  128. package/template/src/examples/cacheExamples.ts +155 -0
  129. package/template/src/framework/decorator/controller.ts +311 -0
  130. package/template/src/framework/decorator/processor/AnnotationDecorators.ts +100 -0
  131. package/template/src/framework/decorator/processor/AnnotationProcessor.ts +156 -0
  132. package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +45 -0
  133. package/template/src/framework/decorator/processor/AnnotationRegistry.ts +117 -0
  134. package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +95 -0
  135. package/template/src/framework/decorator/processor/ProcessorManager.ts +76 -0
  136. package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +126 -0
  137. package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +207 -0
  138. package/template/src/framework/decorator/refactored/DecoratorFactory.ts +99 -0
  139. package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +125 -0
  140. package/template/src/framework/decorator/refactored/DecoratorValidator.ts +128 -0
  141. package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +139 -0
  142. package/template/src/framework/decorator/refactored/index.ts +98 -0
  143. package/template/src/framework/decorator/swagger.ts +150 -0
  144. package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +375 -0
  145. package/template/src/framework/interceptors/ServiceCallInterceptor.ts +348 -0
  146. package/template/src/framework/interceptors/index.ts +19 -0
  147. package/template/src/framework/plugins/registry.ts +63 -0
  148. package/template/src/framework/plugins/types.ts +15 -0
  149. package/template/src/framework/types/ServiceResult.ts +151 -0
  150. package/template/src/framework/types/index.ts +16 -0
  151. package/template/src/framework/utils/CacheManager.ts +430 -0
  152. package/template/src/framework/utils/CacheService.ts +248 -0
  153. package/template/src/framework/utils/DtoValidator.ts +164 -0
  154. package/template/src/framework/utils/MigrationHelper.ts +179 -0
  155. package/template/src/framework/utils/MigrationManager.ts +256 -0
  156. package/template/src/framework/utils/NewRouter.ts +207 -0
  157. package/template/src/framework/utils/TransactionManager.ts +172 -0
  158. package/template/src/framework/utils/bootstrap.ts +445 -0
  159. package/template/src/framework/utils/cache.ts +269 -0
  160. package/template/src/framework/utils/databaseConfig.ts +148 -0
  161. package/template/src/framework/utils/db.ts +39 -0
  162. package/template/src/framework/utils/dbMonitor.ts +106 -0
  163. package/template/src/framework/utils/dynamicSwagger.ts +410 -0
  164. package/template/src/framework/utils/function.ts +61 -0
  165. package/template/src/framework/utils/gracefulShutdown.ts +131 -0
  166. package/template/src/framework/utils/logger.ts +388 -0
  167. package/template/src/framework/utils/metrics.ts +182 -0
  168. package/template/src/framework/utils/router.ts +417 -0
  169. package/template/src/framework/utils/swagger.ts +184 -0
  170. package/template/src/framework/utils/testDb.ts +19 -0
  171. package/template/src/framework/utils/token.ts +23 -0
  172. package/template/src/framework/utils/transform.ts +17 -0
  173. package/template/src/libs/aokEmailSender.ts +42 -0
  174. package/template/src/libs/captcha.ts +37 -0
  175. package/template/src/libs/cos.ts +45 -0
  176. package/template/src/libs/mCache.ts +7 -0
  177. package/template/src/libs/serviceValidate.ts +3 -0
  178. package/template/src/libs/tecentSms.ts +51 -0
  179. package/template/src/middlewares/a.middleware.ts +6 -0
  180. package/template/src/middlewares/error.middleware.ts +14 -0
  181. package/template/src/middlewares/logging.middleware.ts +187 -0
  182. package/template/src/middlewares/static.middleware.ts +79 -0
  183. package/template/src/middlewares/swagger.middleware.ts +70 -0
  184. package/template/src/middlewares/token.middleware.ts +32 -0
  185. package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +172 -0
  186. package/template/src/migrations/index.ts +6 -0
  187. package/template/src/plugins/weboffice/core/context.ts +47 -0
  188. package/template/src/plugins/weboffice/core/errors.ts +51 -0
  189. package/template/src/plugins/weboffice/core/types.ts +63 -0
  190. package/template/src/plugins/weboffice/core/utils.ts +7 -0
  191. package/template/src/plugins/weboffice/entities/index.ts +3 -0
  192. package/template/src/plugins/weboffice/entities/webofficeFile.entity.ts +28 -0
  193. package/template/src/plugins/weboffice/entities/webofficeFileVersion.entity.ts +29 -0
  194. package/template/src/plugins/weboffice/http/routes.ts +179 -0
  195. package/template/src/plugins/weboffice/index.ts +23 -0
  196. package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +274 -0
  197. package/template/src/repository/UserRepository.ts +122 -0
  198. package/template/src/repository/base/BaseRepository.ts +124 -0
  199. package/template/src/repository/interfaces/IBaseRepository.ts +67 -0
  200. package/template/src/routers/index.ts +49 -0
  201. package/template/src/service/base.service.ts +116 -0
  202. package/template/src/service/paramValidateTest.service.ts +139 -0
  203. package/template/src/service/ytGoods.service.ts +42 -0
  204. package/template/src/service/ytShop.service.ts +90 -0
  205. package/template/src/service/ytUser.service.ts +451 -0
  206. package/template/src/test/swaggerParameterTest.ts +90 -0
  207. package/template/src/utils/testDataInitializer.ts +296 -0
  208. package/template/static/output.json +15203 -0
  209. package/template/test/controllers/controllers.test.ts +173 -0
  210. package/template/test/controllers/example/ExampleController.test.ts +222 -0
  211. package/template/test/controllers/example/NewAnnotationExampleController.test.ts +200 -0
  212. package/template/test/framework/TransactionManagerDemo.test.ts +363 -0
  213. package/template/test/framework/annotation/AnnotationDecorators.test.ts +222 -0
  214. package/template/test/framework/annotation/AnnotationExecutor.test.ts +246 -0
  215. package/template/test/framework/annotation/AnnotationProcessor.test.ts +179 -0
  216. package/template/test/framework/annotation/CustomProcessors.test.ts +313 -0
  217. package/template/test/framework/annotation/DefaultProcessors.test.ts +371 -0
  218. package/template/test/framework/annotation/NewRouter.test.ts +272 -0
  219. package/template/test/framework/annotation/ProcessorManager.test.ts +248 -0
  220. package/template/test/framework/annotation/setup.ts +26 -0
  221. package/template/test/framework/cache.test.ts +101 -0
  222. package/template/test/framework/databaseConfig.test.ts +142 -0
  223. package/template/test/integration/integration.test.ts +153 -0
  224. package/template/test/plugins/weboffice/http.routes.int.test.ts +61 -0
  225. package/template/test/service/business.test.ts +87 -0
  226. package/template/test/service/paramValidateTest.service.test.ts +184 -0
  227. package/template/test/service/ytUser.service.test.ts +566 -0
  228. package/template/test/setup.ts +20 -0
  229. package/template/test/setupAfterEnv.ts +14 -0
  230. package/template/test/utils/testHelpers.ts +220 -0
  231. package/template/test_output.txt +0 -0
  232. package/template/tsconfig.build.json +17 -0
  233. package/template/tsconfig.json +31 -0
  234. package/template/webpack.config.js +71 -0
  235. package/template/yarn.lock +7354 -0
@@ -0,0 +1,212 @@
1
+ import { IsNotEmpty, IsOptional, IsString, IsNumber, IsEnum, IsArray, IsBoolean, MinLength, MaxLength, Min, Max, IsInt } from 'class-validator';
2
+ import { YtGoodsStatusEnum } from '@src/entity/ytGoods.entity';
3
+ import { ShopStatusEnum } from '@src/entity/shop.entity';
4
+
5
+ /**
6
+ * 创建商品DTO
7
+ */
8
+ export class CreateGoodsDto {
9
+ @IsNotEmpty({ message: '商品名称不能为空' })
10
+ @IsString({ message: '商品名称必须是字符串' })
11
+ @MaxLength(200, { message: '商品名称长度不能超过200个字符' })
12
+ name: string;
13
+
14
+ @IsNotEmpty({ message: '店铺ID不能为空' })
15
+ @IsInt({ message: '店铺ID必须是整数' })
16
+ @Min(1, { message: '店铺ID不能小于1' })
17
+ shopId: number;
18
+
19
+ @IsOptional()
20
+ @IsArray({ message: '相册必须是数组' })
21
+ albums?: string[];
22
+
23
+ @IsNotEmpty({ message: '价格不能为空' })
24
+ @IsNumber({}, { message: '价格必须是数字' })
25
+ @Min(0, { message: '价格不能小于0' })
26
+ price: number;
27
+
28
+ @IsOptional()
29
+ @IsArray({ message: '标签必须是数组' })
30
+ tags?: string[];
31
+
32
+ @IsOptional()
33
+ @IsString({ message: '描述必须是字符串' })
34
+ @MaxLength(1000, { message: '描述长度不能超过1000个字符' })
35
+ description?: string;
36
+
37
+ @IsOptional()
38
+ @IsString({ message: '内容必须是字符串' })
39
+ content?: string;
40
+
41
+ @IsOptional()
42
+ @IsArray({ message: '内容图片必须是数组' })
43
+ imagesContent?: string[];
44
+
45
+ @IsOptional()
46
+ @IsEnum(YtGoodsStatusEnum, { message: '状态必须是有效的枚举值' })
47
+ status?: YtGoodsStatusEnum;
48
+ }
49
+
50
+ /**
51
+ * 更新商品DTO
52
+ */
53
+ export class UpdateGoodsDto {
54
+ @IsOptional()
55
+ @IsString({ message: '商品名称必须是字符串' })
56
+ @MaxLength(200, { message: '商品名称长度不能超过200个字符' })
57
+ name?: string;
58
+
59
+ @IsOptional()
60
+ @IsArray({ message: '相册必须是数组' })
61
+ albums?: string[];
62
+
63
+ @IsOptional()
64
+ @IsNumber({}, { message: '价格必须是数字' })
65
+ @Min(0, { message: '价格不能小于0' })
66
+ price?: number;
67
+
68
+ @IsOptional()
69
+ @IsArray({ message: '标签必须是数组' })
70
+ tags?: string[];
71
+
72
+ @IsOptional()
73
+ @IsString({ message: '描述必须是字符串' })
74
+ @MaxLength(1000, { message: '描述长度不能超过1000个字符' })
75
+ description?: string;
76
+
77
+ @IsOptional()
78
+ @IsString({ message: '内容必须是字符串' })
79
+ content?: string;
80
+
81
+ @IsOptional()
82
+ @IsArray({ message: '内容图片必须是数组' })
83
+ imagesContent?: string[];
84
+
85
+ @IsOptional()
86
+ @IsEnum(YtGoodsStatusEnum, { message: '状态必须是有效的枚举值' })
87
+ status?: YtGoodsStatusEnum;
88
+ }
89
+
90
+ /**
91
+ * 商品查询DTO
92
+ */
93
+ export class QueryGoodsDto {
94
+ @IsOptional()
95
+ @IsString({ message: '搜索关键词必须是字符串' })
96
+ @MaxLength(100, { message: '搜索关键词长度不能超过100个字符' })
97
+ keyword?: string;
98
+
99
+ @IsOptional()
100
+ @IsInt({ message: '店铺ID必须是整数' })
101
+ @Min(1, { message: '店铺ID不能小于1' })
102
+ shopId?: number;
103
+
104
+ @IsOptional()
105
+ @IsEnum(YtGoodsStatusEnum, { message: '状态必须是有效的枚举值' })
106
+ status?: YtGoodsStatusEnum;
107
+
108
+ @IsOptional()
109
+ @IsNumber({}, { message: '最低价格必须是数字' })
110
+ @Min(0, { message: '最低价格不能小于0' })
111
+ minPrice?: number;
112
+
113
+ @IsOptional()
114
+ @IsNumber({}, { message: '最高价格必须是数字' })
115
+ @Min(0, { message: '最高价格不能小于0' })
116
+ maxPrice?: number;
117
+
118
+ @IsOptional()
119
+ @IsArray({ message: '标签过滤必须是数组' })
120
+ tags?: string[];
121
+
122
+ @IsOptional()
123
+ @IsInt({ message: '页码必须是整数' })
124
+ @Min(1, { message: '页码不能小于1' })
125
+ page?: number = 1;
126
+
127
+ @IsOptional()
128
+ @IsInt({ message: '每页数量必须是整数' })
129
+ @Min(1, { message: '每页数量不能小于1' })
130
+ @Max(100, { message: '每页数量不能大于100' })
131
+ pageSize?: number = 10;
132
+
133
+ @IsOptional()
134
+ @IsString({ message: '排序字段必须是字符串' })
135
+ sortBy?: string = 'id';
136
+
137
+ @IsOptional()
138
+ @IsString({ message: '排序方向必须是字符串' })
139
+ sortOrder?: 'ASC' | 'DESC' = 'DESC';
140
+ }
141
+
142
+ /**
143
+ * 创建店铺DTO
144
+ */
145
+ export class CreateShopDto {
146
+ @IsNotEmpty({ message: '店铺名称不能为空' })
147
+ @IsString({ message: '店铺名称必须是字符串' })
148
+ @MaxLength(100, { message: '店铺名称长度不能超过100个字符' })
149
+ name: string;
150
+
151
+ @IsOptional()
152
+ @IsString({ message: '描述必须是字符串' })
153
+ @MaxLength(1000, { message: '描述长度不能超过1000个字符' })
154
+ description?: string;
155
+
156
+ @IsOptional()
157
+ @IsEnum(ShopStatusEnum, { message: '状态必须是有效的枚举值' })
158
+ status?: ShopStatusEnum;
159
+ }
160
+
161
+ /**
162
+ * 更新店铺DTO
163
+ */
164
+ export class UpdateShopDto {
165
+ @IsOptional()
166
+ @IsString({ message: '店铺名称必须是字符串' })
167
+ @MaxLength(100, { message: '店铺名称长度不能超过100个字符' })
168
+ name?: string;
169
+
170
+ @IsOptional()
171
+ @IsString({ message: '描述必须是字符串' })
172
+ @MaxLength(1000, { message: '描述长度不能超过1000个字符' })
173
+ description?: string;
174
+
175
+ @IsOptional()
176
+ @IsEnum(ShopStatusEnum, { message: '状态必须是有效的枚举值' })
177
+ status?: ShopStatusEnum;
178
+ }
179
+
180
+ /**
181
+ * 商品解锁DTO
182
+ */
183
+ export class UnlockGoodsDto {
184
+ @IsNotEmpty({ message: '商品ID不能为空' })
185
+ @IsInt({ message: '商品ID必须是整数' })
186
+ @Min(1, { message: '商品ID不能小于1' })
187
+ goodsId: number;
188
+
189
+ @IsNotEmpty({ message: '解锁密钥不能为空' })
190
+ @IsString({ message: '解锁密钥必须是字符串' })
191
+ @MinLength(1, { message: '解锁密钥不能为空' })
192
+ key: string;
193
+ }
194
+
195
+ /**
196
+ * 创建解锁密钥DTO
197
+ */
198
+ export class CreateUnlockKeyDto {
199
+ @IsNotEmpty({ message: '商品ID不能为空' })
200
+ @IsInt({ message: '商品ID必须是整数' })
201
+ @Min(1, { message: '商品ID不能小于1' })
202
+ goodsId: number;
203
+
204
+ @IsNotEmpty({ message: '密钥不能为空' })
205
+ @IsString({ message: '密钥必须是字符串' })
206
+ @MinLength(1, { message: '密钥不能为空' })
207
+ key: string;
208
+
209
+ @IsOptional()
210
+ @IsBoolean({ message: '是否已使用必须是布尔值' })
211
+ isUse?: boolean = false;
212
+ }
@@ -0,0 +1,13 @@
1
+ import { IsNotEmpty, IsNumber, Max, Min } from "class-validator";
2
+
3
+ /**
4
+ * 测试验证服务DTO
5
+ */
6
+ export class TestValidateServiceDto {
7
+
8
+ @IsNotEmpty({ message: 'ID不能为空' })
9
+ @IsNumber({}, { message: 'ID必须是数字' })
10
+ @Min(1, { message: 'ID不能小于1' })
11
+ @Max(1000000, { message: 'ID不能大于1000000' })
12
+ id:number
13
+ }
@@ -0,0 +1,177 @@
1
+ import { IsEmail, IsNotEmpty, IsOptional, IsString, MinLength, MaxLength, IsEnum, IsNumber, IsBoolean, IsArray, IsInt, Min, Max } from 'class-validator';
2
+ import { YtUserTypeEnum, YtUserStatusEnum } from '@src/entity/ytUser.entity';
3
+
4
+ /**
5
+ * 创建用户DTO
6
+ */
7
+ export class CreateUserDto {
8
+ @IsNotEmpty({ message: '昵称不能为空' })
9
+ @IsString({ message: '昵称必须是字符串' })
10
+ @MaxLength(50, { message: '昵称长度不能超过50个字符' })
11
+ nickName: string;
12
+
13
+ @IsNotEmpty({ message: '手机号不能为空' })
14
+ @IsString({ message: '手机号必须是字符串' })
15
+ @MaxLength(20, { message: '手机号长度不能超过20个字符' })
16
+ telnumber: string;
17
+
18
+ @IsNotEmpty({ message: '邮箱不能为空' })
19
+ @IsEmail({}, { message: '邮箱格式不正确' })
20
+ @MaxLength(100, { message: '邮箱长度不能超过100个字符' })
21
+ email: string;
22
+
23
+ @IsNotEmpty({ message: '密码不能为空' })
24
+ @IsString({ message: '密码必须是字符串' })
25
+ @MinLength(6, { message: '密码长度不能少于6个字符' })
26
+ @MaxLength(100, { message: '密码长度不能超过100个字符' })
27
+ password: string;
28
+
29
+ @IsOptional()
30
+ @IsEnum(YtUserTypeEnum, { message: '用户类型必须是有效的枚举值' })
31
+ userType?: YtUserTypeEnum;
32
+
33
+ @IsOptional()
34
+ @IsInt({ message: '性别必须是整数' })
35
+ @Min(0, { message: '性别值不能小于0' })
36
+ @Max(2, { message: '性别值不能大于2' })
37
+ gender?: number;
38
+
39
+ @IsOptional()
40
+ @IsInt({ message: '年龄必须是整数' })
41
+ @Min(0, { message: '年龄不能小于0' })
42
+ @Max(150, { message: '年龄不能大于150' })
43
+ age?: number;
44
+
45
+ @IsOptional()
46
+ @IsString({ message: '星座必须是字符串' })
47
+ @MaxLength(20, { message: '星座长度不能超过20个字符' })
48
+ constellation?: string;
49
+
50
+ @IsOptional()
51
+ @IsString({ message: '头像必须是字符串' })
52
+ @MaxLength(500, { message: '头像URL长度不能超过500个字符' })
53
+ avatar?: string;
54
+
55
+ @IsOptional()
56
+ @IsEnum(YtUserStatusEnum, { message: '状态必须是有效的枚举值' })
57
+ status?: YtUserStatusEnum;
58
+ }
59
+
60
+ /**
61
+ * 更新用户DTO
62
+ */
63
+ export class UpdateUserDto {
64
+ @IsOptional()
65
+ @IsString({ message: '昵称必须是字符串' })
66
+ @MaxLength(50, { message: '昵称长度不能超过50个字符' })
67
+ nickName?: string;
68
+
69
+ @IsOptional()
70
+ @IsString({ message: '手机号必须是字符串' })
71
+ @MaxLength(20, { message: '手机号长度不能超过20个字符' })
72
+ telnumber?: string;
73
+
74
+ @IsOptional()
75
+ @IsEmail({}, { message: '邮箱格式不正确' })
76
+ @MaxLength(100, { message: '邮箱长度不能超过100个字符' })
77
+ email?: string;
78
+
79
+ @IsOptional()
80
+ @IsEnum(YtUserTypeEnum, { message: '用户类型必须是有效的枚举值' })
81
+ userType?: YtUserTypeEnum;
82
+
83
+ @IsOptional()
84
+ @IsInt({ message: '性别必须是整数' })
85
+ @Min(0, { message: '性别值不能小于0' })
86
+ @Max(2, { message: '性别值不能大于2' })
87
+ gender?: number;
88
+
89
+ @IsOptional()
90
+ @IsInt({ message: '年龄必须是整数' })
91
+ @Min(0, { message: '年龄不能小于0' })
92
+ @Max(150, { message: '年龄不能大于150' })
93
+ age?: number;
94
+
95
+ @IsOptional()
96
+ @IsString({ message: '星座必须是字符串' })
97
+ @MaxLength(20, { message: '星座长度不能超过20个字符' })
98
+ constellation?: string;
99
+
100
+ @IsOptional()
101
+ @IsString({ message: '头像必须是字符串' })
102
+ @MaxLength(500, { message: '头像URL长度不能超过500个字符' })
103
+ avatar?: string;
104
+
105
+ @IsOptional()
106
+ @IsEnum(YtUserStatusEnum, { message: '状态必须是有效的枚举值' })
107
+ status?: YtUserStatusEnum;
108
+ }
109
+
110
+ /**
111
+ * 用户查询DTO
112
+ */
113
+ export class QueryUserDto {
114
+ @IsOptional()
115
+ @IsString({ message: '搜索关键词必须是字符串' })
116
+ @MaxLength(100, { message: '搜索关键词长度不能超过100个字符' })
117
+ keyword?: string;
118
+
119
+ @IsOptional()
120
+ @IsEnum(YtUserTypeEnum, { message: '用户类型必须是有效的枚举值' })
121
+ userType?: YtUserTypeEnum;
122
+
123
+ @IsOptional()
124
+ @IsEnum(YtUserStatusEnum, { message: '状态必须是有效的枚举值' })
125
+ status?: YtUserStatusEnum;
126
+
127
+ @IsOptional()
128
+ @IsInt({ message: '页码必须是整数' })
129
+ @Min(1, { message: '页码不能小于1' })
130
+ page?: number = 1;
131
+
132
+ @IsOptional()
133
+ @IsInt({ message: '每页数量必须是整数' })
134
+ @Min(1, { message: '每页数量不能小于1' })
135
+ @Max(100, { message: '每页数量不能大于100' })
136
+ pageSize?: number = 10;
137
+
138
+ @IsOptional()
139
+ @IsString({ message: '排序字段必须是字符串' })
140
+ sortBy?: string = 'id';
141
+
142
+ @IsOptional()
143
+ @IsString({ message: '排序方向必须是字符串' })
144
+ sortOrder?: 'ASC' | 'DESC' = 'DESC';
145
+ }
146
+
147
+ /**
148
+ * 用户登录DTO
149
+ */
150
+ export class LoginUserDto {
151
+ @IsNotEmpty({ message: '登录凭证不能为空' })
152
+ @IsString({ message: '登录凭证必须是字符串' })
153
+ credential: string; // 可以是邮箱或手机号
154
+
155
+ @IsNotEmpty({ message: '密码不能为空' })
156
+ @IsString({ message: '密码必须是字符串' })
157
+ password: string;
158
+ }
159
+
160
+ /**
161
+ * 修改密码DTO
162
+ */
163
+ export class ChangePasswordDto {
164
+ @IsNotEmpty({ message: '当前密码不能为空' })
165
+ @IsString({ message: '当前密码必须是字符串' })
166
+ currentPassword: string;
167
+
168
+ @IsNotEmpty({ message: '新密码不能为空' })
169
+ @IsString({ message: '新密码必须是字符串' })
170
+ @MinLength(6, { message: '新密码长度不能少于6个字符' })
171
+ @MaxLength(100, { message: '新密码长度不能超过100个字符' })
172
+ newPassword: string;
173
+
174
+ @IsNotEmpty({ message: '确认密码不能为空' })
175
+ @IsString({ message: '确认密码必须是字符串' })
176
+ confirmPassword: string;
177
+ }
@@ -0,0 +1,13 @@
1
+ import { CreateDateColumn, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
2
+
3
+ export class BaseEntity {
4
+ @PrimaryGeneratedColumn ()
5
+ id: number;
6
+
7
+
8
+ @UpdateDateColumn()
9
+ updateDate:Date
10
+
11
+ @CreateDateColumn()
12
+ createDate: Date
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 实体列类型:SQLite + PostgreSQL/MySQL 兼容
3
+ *
4
+ * 单元测试/内存库使用 SQLite(db_memory=1),调试/生产使用 PostgreSQL 或 MySQL。
5
+ * SQLite 用 datetime,PostgreSQL 不支持 datetime 仅支持 timestamp,MySQL 两者都支持。
6
+ * 故日期时间列按环境返回不同类型。
7
+ *
8
+ * 使用方式:@Column({ type: getDateTimeColumnType(), nullable: true })
9
+ */
10
+ /** 返回 TypeORM 日期时间列类型:SQLite 用 datetime,PostgreSQL/MySQL 用 timestamp */
11
+ export function getDateTimeColumnType(): "datetime" | "timestamp" {
12
+ return Number(process.env.db_memory) === 1 ? "datetime" : "timestamp";
13
+ }
@@ -0,0 +1,33 @@
1
+ import { BaseEntity } from "@src/entity/base.entity";
2
+ import { Column, Entity, Index, ManyToOne, JoinColumn } from "typeorm";
3
+ import { YtGoodsEntity } from "@src/entity/ytGoods.entity";
4
+
5
+ @Entity({
6
+ name: "goods_images_unlock_key"
7
+ })
8
+ export class GoodsImagesUnlockKeyEntity extends BaseEntity {
9
+
10
+ @Column({ default: "" })
11
+ key: string
12
+
13
+ @Column({
14
+ type: "integer",
15
+ default: 0,
16
+ })
17
+ goodsId: number
18
+
19
+ @Column({
20
+ type: "boolean",
21
+ default: false,
22
+ })
23
+ isUse: boolean
24
+
25
+ // 关系定义
26
+ /**
27
+ * 关联的商品
28
+ */
29
+ @ManyToOne(() => YtGoodsEntity, goods => goods.unlockKeys)
30
+ @JoinColumn({ name: 'goodsId' })
31
+ goods: YtGoodsEntity;
32
+
33
+ }
@@ -0,0 +1,34 @@
1
+ import { Column, Entity, Index, ManyToOne, JoinColumn } from "typeorm";
2
+ import { BaseEntity } from "@src/entity/base.entity";
3
+ import { YtGoodsEntity } from "@src/entity/ytGoods.entity";
4
+ import { YtUserEntity } from "@src/entity/ytUser.entity";
5
+
6
+ @Entity({
7
+ name: "yt_goods_unlock"
8
+ })
9
+ export class YtGoodsUnlockerEntity extends BaseEntity {
10
+
11
+ @Index()
12
+ @Column({ default: 0 })
13
+ goodsId: number;
14
+
15
+ @Index()
16
+ @Column({ default: 0 })
17
+ ytUserId: number;
18
+
19
+ // 关系定义
20
+ /**
21
+ * 关联的商品
22
+ */
23
+ @ManyToOne(() => YtGoodsEntity, goods => goods.unlockRecords)
24
+ @JoinColumn({ name: 'goodsId' })
25
+ goods: YtGoodsEntity;
26
+
27
+ /**
28
+ * 关联的用户
29
+ */
30
+ @ManyToOne(() => YtUserEntity, user => user.unlockedGoods)
31
+ @JoinColumn({ name: 'ytUserId' })
32
+ user: YtUserEntity;
33
+
34
+ }
@@ -0,0 +1,15 @@
1
+ import { GoodsImagesUnlockKeyEntity } from "@src/entity/goodsImagesUnlockKey.entity";
2
+ import { YtGoodsUnlockerEntity } from "@src/entity/goodsUnlocker.entity";
3
+ import { ShopEntity } from "@src/entity/shop.entity";
4
+ import { ShopAndUserEntity } from "@src/entity/shopUser.entity";
5
+ import { YtGoodsEntity } from "@src/entity/ytGoods.entity";
6
+ import { YtUserEntity } from "@src/entity/ytUser.entity";
7
+
8
+ export default [
9
+ YtUserEntity,
10
+ YtGoodsEntity,
11
+ YtGoodsUnlockerEntity,
12
+ GoodsImagesUnlockKeyEntity,
13
+ ShopEntity,
14
+ ShopAndUserEntity,
15
+ ]
@@ -0,0 +1,52 @@
1
+ import { Column, Entity, OneToMany, OneToOne } from "typeorm";
2
+ import { BaseEntity } from "@src/entity/base.entity";
3
+ import { YtGoodsEntity } from "@src/entity/ytGoods.entity";
4
+ import { ShopAndUserEntity } from "@src/entity/shopUser.entity";
5
+
6
+
7
+ export enum ShopStatusEnum {
8
+ CHECKING = "CHECKING", // 审核中
9
+ NORMAL = "NORMAL",
10
+ FORBIDDEN = "FORBIDDEN",
11
+ }
12
+
13
+
14
+ @Entity({
15
+ name: "shop"
16
+ })
17
+ export class ShopEntity extends BaseEntity {
18
+
19
+ @Column({
20
+ default: "",
21
+ })
22
+ name: string;
23
+
24
+
25
+ @Column({
26
+ default:""
27
+ })
28
+ description:string;
29
+
30
+
31
+ @Column({
32
+ type: "varchar",
33
+ length: 50,
34
+ default: ShopStatusEnum.NORMAL
35
+ })
36
+ status: ShopStatusEnum;
37
+
38
+ // 关系定义
39
+ /**
40
+ * 店铺的商品列表
41
+ */
42
+ @OneToMany(() => YtGoodsEntity, goods => goods.shop)
43
+ goods: YtGoodsEntity[];
44
+
45
+ /**
46
+ * 店铺与用户的关系
47
+ */
48
+ @OneToOne(() => ShopAndUserEntity, shopUser => shopUser.shop)
49
+ userRelation: ShopAndUserEntity;
50
+
51
+
52
+ }
@@ -0,0 +1,41 @@
1
+ import { Column, Entity, Index, ManyToOne, JoinColumn } from "typeorm";
2
+ import { BaseEntity } from "@src/entity/base.entity";
3
+ import { ShopEntity } from "@src/entity/shop.entity";
4
+ import { YtUserEntity } from "@src/entity/ytUser.entity";
5
+
6
+ @Entity({
7
+ name: "shop_and_user"
8
+ })
9
+ export class ShopAndUserEntity extends BaseEntity {
10
+
11
+ @Index()
12
+ @Column({
13
+ default: 0,
14
+ type: "integer"
15
+ })
16
+ shopId: number;
17
+
18
+
19
+ @Index()
20
+ @Column({
21
+ default: 0,
22
+ type: "integer"
23
+ })
24
+ userId: number
25
+
26
+ // 关系定义
27
+ /**
28
+ * 关联的店铺
29
+ */
30
+ @ManyToOne(() => ShopEntity, shop => shop.userRelation)
31
+ @JoinColumn({ name: 'shopId' })
32
+ shop: ShopEntity;
33
+
34
+ /**
35
+ * 关联的用户
36
+ */
37
+ @ManyToOne(() => YtUserEntity, user => user.shopRelation)
38
+ @JoinColumn({ name: 'userId' })
39
+ user: YtUserEntity;
40
+
41
+ }