diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-team-leaveTeam/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-team-leaveTeam/index.js index da3b08a68be15adf30970606e8020c32717c5ab9..f219a09230560765786e7d7b04f20bdf6879f7a1 100644 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-team-leaveTeam/index.js +++ b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-team-leaveTeam/index.js @@ -49,37 +49,39 @@ exports.main = async (event, context) => { const res = await collection.doc(event.userId).update({ team_id: "" }) - if (res.updated === 1 && res1.affectedDocs != 1) { + if (res.updated === 1) { const activity = db.collection('mustgo-team-activity') let res2 = await activity.where({ team_id: teamid }).get() - var arr = new Array; - arr = res2.data + const registration = db.collection('mustgo-registration') + let res3 = await registration.where({ + owner_id: event.userId + }).get() + var arr = new Array; + arr = res3.data for (var i = 0; i < arr.length; i++) { - const res = await activitycollection.doc(arr[i]["_id"]).update({ - enrollment: arr[i]["enrollment"]-1 + + let res4 = await activity.where({ + _id:arr[i]["team_activity_id"] + }).get() + + const res = await activitycollection.doc(arr[i]["team_activity_id"]).update({ + enrollment: res4.data[0]["enrollment"] - 1 }) - const tmp = await registration.where({ - team_activity_id: arr[i]["_id"] + const restep = await registration.where({ + _id:arr[i]["_id"] }).remove() } - return { "code": 200, "message": "退出小队成功", "data": {} } - } else { - return { - "code": 200, - "message": "退出小队成功", - "data": {} - } - } + } } return { "code": 400,