v0.0.4
This commit is contained in:
17
cloudfunctions/petList/index.js
Normal file
17
cloudfunctions/petList/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
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 }
|
||||
}
|
||||
|
||||
9
cloudfunctions/petList/package.json
Normal file
9
cloudfunctions/petList/package.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "petList",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "latest"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user