You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
866 B
40 lines
866 B
1 year ago
|
const db = uniCloud.database()
|
||
|
module.exports = async function ({
|
||
|
data = {},
|
||
|
success = true,
|
||
|
type = 'login'
|
||
|
} = {}) {
|
||
|
const now = Date.now()
|
||
|
const uniIdLogCollection = db.collection('uni-id-log')
|
||
|
const requiredDataKeyList = ['user_id', 'username', 'email', 'mobile']
|
||
|
const dataCopy = {}
|
||
|
for (let i = 0; i < requiredDataKeyList.length; i++) {
|
||
|
const key = requiredDataKeyList[i]
|
||
|
if (key in data && typeof data[key] === 'string') {
|
||
|
dataCopy[key] = data[key]
|
||
|
}
|
||
|
}
|
||
|
const {
|
||
|
appId,
|
||
|
clientIP,
|
||
|
deviceId,
|
||
|
userAgent
|
||
|
} = this.getUniversalClientInfo()
|
||
|
const logData = {
|
||
|
appid: appId,
|
||
|
device_id: deviceId,
|
||
|
ip: clientIP,
|
||
|
type,
|
||
|
ua: userAgent,
|
||
|
create_date: now,
|
||
|
...dataCopy
|
||
|
}
|
||
|
|
||
|
if (success) {
|
||
|
logData.state = 1
|
||
|
} else {
|
||
|
logData.state = 0
|
||
|
}
|
||
|
return uniIdLogCollection.add(logData)
|
||
|
}
|