index.js 1017 字节
Newer Older
L
ljw 已提交
1 2 3
'use strict';
exports.main = async (event, context) => {
	const db = uniCloud.database()
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
	
	const usercollection = db.collection('mustgo-user')
	let res1 = await usercollection.where({
		_id: event.userId
	}).get()
	if (res1.affectedDocs <= 0) {
		return {
			"code": 400,
			"message": "发起小队活动失败",
			"data": {}
		}
	}
	let teamid
	if (res1.affectedDocs == 1) {
		teamid = res1.data[0]["team_id"]
	}
	
L
ljw 已提交
21 22 23 24 25 26 27 28 29 30 31
	const collection = db.collection('mustgo-team-activity')
	const res = await collection.add({
		title: event.title,
		content: event.content,
		start_date: event.startDate,
		end_date: event.endDate,
		owner_id: event.userId,
		place: event.place,
		status: 0,
		participants: event.participants,
		contact: event.contact,
32
		team_id: teamid
L
ljw 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	})
	if (res.id.length > 0)
		return {
			"code": 200,
			"message": "发起小队活动成功",
			"data": {
				"activityId": res.id
			}
		}

	//返回数据给客户端
	return {
		"code": 400,
		"message": "发起小队活动失败",
		"data": {}
	}
};