first commit
This commit is contained in:
55
cloudfunctions/deleteRoom/index.js
Normal file
55
cloudfunctions/deleteRoom/index.js
Normal file
@@ -0,0 +1,55 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
|
||||
const db = cloud.database()
|
||||
const _ = db.command
|
||||
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
const wxContext = cloud.getWXContext()
|
||||
const openid = wxContext.OPENID
|
||||
const { roomId } = event
|
||||
|
||||
if (!roomId) {
|
||||
return {
|
||||
success: false,
|
||||
msg: '房间ID不能为空'
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 查询房间信息
|
||||
const room = await db.collection('rooms').doc(roomId).get()
|
||||
|
||||
if (!room.data) {
|
||||
return {
|
||||
success: false,
|
||||
msg: '房间不存在'
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否是创建者
|
||||
if (room.data._openid !== openid) {
|
||||
return {
|
||||
success: false,
|
||||
msg: '只有创建者可以删除聚会'
|
||||
}
|
||||
}
|
||||
|
||||
// 删除房间
|
||||
await db.collection('rooms').doc(roomId).remove()
|
||||
|
||||
return {
|
||||
success: true,
|
||||
msg: '删除成功'
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return {
|
||||
success: false,
|
||||
msg: '删除失败',
|
||||
error: err
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user