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

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

上级 8ae52221
const url = require('url')
const { userCollection, EXTERNAL_DIRECT_CONNECT_PROVIDER } = require('../../common/constants') const { userCollection, EXTERNAL_DIRECT_CONNECT_PROVIDER } = require('../../common/constants')
const { ERROR } = require('../../common/error') const { ERROR } = require('../../common/error')
const { findUser } = require('../../lib/utils/account') const { findUser } = require('../../lib/utils/account')
...@@ -59,6 +60,14 @@ module.exports = async function (params = {}) { ...@@ -59,6 +60,14 @@ module.exports = async function (params = {}) {
status: { status: {
required: false, required: false,
type: 'number' type: 'number'
},
gender: {
required: false,
type: 'number'
},
avatar: {
required: false,
type: 'string'
} }
} }
...@@ -75,7 +84,9 @@ module.exports = async function (params = {}) { ...@@ -75,7 +84,9 @@ module.exports = async function (params = {}) {
mobile, mobile,
email, email,
tags, tags,
status status,
avatar,
gender
} = params } = params
if (!uid && !externalUid) { if (!uid && !externalUid) {
...@@ -101,6 +112,14 @@ module.exports = async function (params = {}) { ...@@ -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 = { const data = {
username, username,
...@@ -110,7 +129,9 @@ module.exports = async function (params = {}) { ...@@ -110,7 +129,9 @@ module.exports = async function (params = {}) {
mobile, mobile,
email, email,
tags, tags,
status status,
avatar,
gender
} }
const realData = Object.keys(data).reduce((res, key) => { const realData = Object.keys(data).reduce((res, key) => {
...@@ -153,6 +174,32 @@ module.exports = async function (params = {}) { ...@@ -153,6 +174,32 @@ module.exports = async function (params = {}) {
realData.password_secret_version = version 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) await userCollection.where(query).update(realData)
return { return {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册