修复动态发布与互动问题
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user