v0.0.4
This commit is contained in:
21
cloudfunctions/locationUpdate/index.js
Normal file
21
cloudfunctions/locationUpdate/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
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()
|
||||
const now = Date.now()
|
||||
const data = {
|
||||
openid: OPENID,
|
||||
location: event.location || null,
|
||||
visible: Boolean(event.visible),
|
||||
updatedAt: now
|
||||
}
|
||||
const existed = await db.collection('locations').where({ openid: OPENID }).limit(1).get()
|
||||
if (existed.data.length) await db.collection('locations').doc(existed.data[0]._id).update({ data })
|
||||
else await db.collection('locations').add({ data })
|
||||
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user