index.js 854 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
'use strict';
exports.main = async (event, context) => {
	const db = uniCloud.database()
	let ans
	await db.collection('mustgo-team')
		.where({
			name: new RegExp(event.teamname, 'i') //模糊查询条件
		})
		.get()
		.then((res) => {
			// console.log(res)
			ans = res
			// res 为数据库查询结果
		}).catch((err) => {

		})
		
		
	var list = new Array;
	var arr = new Array;
	arr = ans.data;
	if (ans.affectedDocs >= 0) {
		for (var i = 0; i < arr.length; i++) {
			var team = {
				teamId: arr[i]["_id"],
				teamName: arr[i]["name"],
				createrId: arr[i]["owner_id"],
				discription: arr[i]["description"],
			}
			list.push(team);
		}
		return {
			"code": 200,
			"message": "成功返回小队列表",
			"data": {
				"teamList": list
			}
		}
	}
	return {
		"code": 400,
		"message": "返回小队列表失败",
		"data": {}
	}
};