提交 2922ab59 编写于 作者: C chenruilong

feat(uni-id-co): updateUserInfoByExternal 允许修改头像、性别

上级 8ae52221
const url = require('url')
const { userCollection, EXTERNAL_DIRECT_CONNECT_PROVIDER } = require('../../common/constants')
const { ERROR } = require('../../common/error')
const { findUser } = require('../../lib/utils/account')
......@@ -59,6 +60,14 @@ module.exports = async function (params = {}) {
status: {
required: false,
type: 'number'
},
gender: {
required: false,
type: 'number'
},
avatar: {
required: false,
type: 'string'
}
}
......@@ -75,7 +84,9 @@ module.exports = async function (params = {}) {
mobile,
email,
tags,
status
status,
avatar,
gender
} = params
if (!uid && !externalUid) {
......@@ -101,6 +112,14 @@ module.exports = async function (params = {}) {
}
}
const users = await userCollection.where(query).get()
const user = users.data && users.data[0]
if (!user) {
throw {
errCode: ERROR.ACCOUNT_NOT_EXISTS
}
}
// 更新的用户数据字段
const data = {
username,
......@@ -110,7 +129,9 @@ module.exports = async function (params = {}) {
mobile,
email,
tags,
status
status,
avatar,
gender
}
const realData = Object.keys(data).reduce((res, key) => {
......@@ -153,6 +174,32 @@ module.exports = async function (params = {}) {
realData.password_secret_version = version
}
if (avatar) {
// eslint-disable-next-line n/no-deprecated-api
const avatarPath = url.parse(avatar).pathname
const extName = avatarPath.indexOf('.') > -1 ? avatarPath.split('.').pop() : ''
realData.avatar_file = {
name: avatarPath,
extname: extName,
url: avatar
}
}
if (user.identities.length) {
const identity = user.identities.find(item => item.provider === EXTERNAL_DIRECT_CONNECT_PROVIDER)
if (identity) {
identity.userInfo = {
avatar,
gender,
nickname
}
}
realData.identities = user.identities
}
await userCollection.where(query).update(realData)
return {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册