test: 意见反馈浏览器端功能测试 + service populate 保护

Playwright 测试 (api.browser.spec.ts):
- POST /api/feedback 401 (无 token)
- POST /api/feedback 400 (空内容)
- POST /api/feedback 201 (有效数据)
- GET /api/feedback 403 (非管理员)
- GET /api/feedback 200 (管理员)

测试通过用读写 .env 获取 JWT_SECRET 签名 token

fix: findAll 增加 populate try/catch 防止用户被删除后列表崩溃
This commit is contained in:
yuzhiran
2026-07-06 11:45:34 +08:00
parent 4180eae944
commit e9036d2979
2 changed files with 70 additions and 6 deletions
@@ -13,11 +13,13 @@ export class FeedbackService {
async findAll(page = 1, limit = 20) {
const skip = (page - 1) * limit
const [items, total] = await Promise.all([
this.model.find().sort({ createdAt: -1 }).skip(skip).limit(limit).populate('userId', 'nickname phone email').lean(),
this.model.countDocuments(),
])
return { items, total, page, limit }
const items = await this.model.find().sort({ createdAt: -1 }).skip(skip).limit(limit).lean()
let populated: any[] = items
try {
populated = await this.model.populate(items, { path: 'userId', select: 'nickname phone email' })
} catch {}
const total = await this.model.countDocuments()
return { items: populated, total, page, limit }
}
async markResolved(id: string) {