first commit
This commit is contained in:
5
cloudfunctions/updateRoomInfo/config.json
Normal file
5
cloudfunctions/updateRoomInfo/config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"permissions": {
|
||||
"openapi": []
|
||||
}
|
||||
}
|
||||
52
cloudfunctions/updateRoomInfo/index.js
Normal file
52
cloudfunctions/updateRoomInfo/index.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
|
||||
const db = cloud.database()
|
||||
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
const wxContext = cloud.getWXContext()
|
||||
const openid = wxContext.OPENID
|
||||
|
||||
const { roomId, name, meetTime, keywords } = event
|
||||
|
||||
if (!roomId) {
|
||||
return {
|
||||
success: false,
|
||||
msg: '房间ID不能为空'
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建更新数据
|
||||
const updateData = {}
|
||||
if (name !== undefined) {
|
||||
updateData.name = name
|
||||
}
|
||||
if (meetTime !== undefined) {
|
||||
updateData.meetTime = meetTime
|
||||
}
|
||||
if (keywords !== undefined) {
|
||||
updateData.keywords = keywords
|
||||
}
|
||||
|
||||
// 更新房间信息
|
||||
await db.collection('rooms').doc(roomId).update({
|
||||
data: updateData
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
msg: '更新成功'
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return {
|
||||
success: false,
|
||||
msg: '更新失败',
|
||||
error: err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
cloudfunctions/updateRoomInfo/package.json
Normal file
9
cloudfunctions/updateRoomInfo/package.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "updateRoomInfo",
|
||||
"version": "1.0.0",
|
||||
"description": "更新聚会信息(名称、时间)",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "~3.0.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user