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

14 lines
478 B
JavaScript

const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()
exports.main = async () => {
const { OPENID } = cloud.getWXContext()
if (!OPENID) throw new Error('no openid in wx context')
const res = await db.collection('drafts').where({ openid: OPENID }).limit(1).get()
if (!res.data.length) return { draft: null }
const record = res.data[0]
return { draft: record.draft || null, updatedAt: record.updatedAt }
}