修复动态发布与互动问题

This commit is contained in:
2026-06-23 18:43:03 +08:00
parent 702b578e1e
commit cda8685956
151 changed files with 4993 additions and 914 deletions

View File

@@ -2,6 +2,7 @@ const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()
const MAX_PETS_PER_USER = 10
exports.main = async event => {
const { OPENID } = cloud.getWXContext()
@@ -20,8 +21,12 @@ exports.main = async event => {
return { petId: event.pet._id }
}
const countRes = await db.collection('pets').where({ ownerId: users.data[0]._id }).count()
if ((countRes.total || 0) >= MAX_PETS_PER_USER) {
throw new Error(`最多只能添加 ${MAX_PETS_PER_USER} 只宠物`)
}
pet.createdAt = Date.now()
const result = await db.collection('pets').add({ data: pet })
return { petId: result._id }
}