'use strict';
const {
	getUserId
} = require('user-common')
exports.main = async (event, context) => {

	let user_id = await getUserId(event.token)
	console.log(user_id);
	const watermark = event.watermark
	if (user_id) {
		watermark.user_id = user_id
		const collection = uniCloud.database().collection("user_watermark");
		const res = await collection.where({
			user_id: user_id,
			system_id: watermark.system_id
		}).get()
		if (res.data && res.data.length > 0) {
			await collection.doc(res.data[0]._id).update(watermark)
		} else {
			await collection.add(watermark)
		}
	}
	//返回数据给客户端
	return true
};
