From 2922ab59b1a03d3ea6bb07e90945e2bf32c038bd Mon Sep 17 00:00:00 2001 From: chenruilong Date: Fri, 24 Feb 2023 15:21:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(uni-id-co):=20updateUserInfoByExternal=20?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E4=BF=AE=E6=94=B9=E5=A4=B4=E5=83=8F=E3=80=81?= =?UTF-8?q?=E6=80=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/external/update-user-info.js | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/update-user-info.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/update-user-info.js index f23a916..e966069 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/update-user-info.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/update-user-info.js @@ -1,3 +1,4 @@ +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 { -- GitLab