Files
dukang/.cursor/rules/backend-nestjs.mdc
T
2026-07-01 15:04:53 +08:00

52 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: 杜康好客 NestJS 后端编码规范
globs: server/**/*.ts
alwaysApply: false
---
# 后端规范
## 模块目录
```
server/dukang-api/src/
├── modules/{iam,trade,benefit,catalog,store,redeem,settlement,ops,analytics,health}/
├── common/{guards,decorators,interceptors,filters,prisma,redis}/
├── integrations/{pay,sms,delivery}/
└── jobs/
```
## 新接口流程
1. 在 **OWNER 模块** 建 `dto/`、`*.service.ts`、`*.controller.ts`
2. Service 只写本模块 Prisma 表
3. 跨域 inject 其他 Module 的 exported Service
4. Controller 加对应 Guard`JwtAuthGuard`、`PhoneVerifiedGuard` 等)
5. 响应 `{ code: 0, message: 'ok', data }`
6. 同步 `packages/shared-types`
## Controller 示例
```typescript
@Controller('trade/orders')
@UseGuards(JwtAuthGuard)
export class TradeController {
constructor(private readonly tradeService: TradeService) {}
}
```
## 鉴权路由前缀
| 端 | 前缀 |
|----|------|
| C 端 | `/auth`, `/user`, `/catalog`, `/trade`, `/benefit`, `/redeem`, `/stores` |
| 门店 | `/shop/auth`, `/shop/redeem`, `/shop/store` |
| 合伙人 | `/partner/*` |
| 总部 | `/admin/*` |
## 数据约定
- 埋点 → `log_user_analytics`;业务审计 → `common_event`
- 支付 → `log_third_party` + `user_order.pay_*`(无 payments 表)
- 核销码 → Redis 5min(无 DB 表)