const { cloud, db } = require("../config/database");
const user = db.collection("user");

// 修改数据库信息云函数入口函数
exports.main = async (event, context) => {
  try {
    // 获取基础信息
    const wxContext = cloud.getWXContext();
    const userData = await user.where({
      _openid: wxContext.OPENID
    }).get();
    return {
      code: 0,
      data: userData.data[0] || {}
    }
  } catch (e) {
    return {
      code: 1,
      errMsg: e
    }
  }
}