Files
Pawer/cloudfunctions/petList/index.js
2026-06-18 14:33:50 +08:00

18 lines
495 B
JavaScript

const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()
exports.main = async event => {
const { OPENID } = cloud.getWXContext()
let ownerId = event.ownerId
if (!ownerId) {
const user = await db.collection('users').where({ openid: OPENID }).limit(1).get()
ownerId = user.data[0]?._id
}
const res = ownerId ? await db.collection('pets').where({ ownerId }).limit(20).get() : { data: [] }
return { list: res.data }
}