小程序修改
This commit is contained in:
@@ -1240,6 +1240,54 @@ export class AuthService {
|
||||
return this.buildSessionResponse(user, clientApp, user.deviceKey);
|
||||
}
|
||||
|
||||
async updateMiniWechatProfile(
|
||||
userId: bigint,
|
||||
input: { nickname?: string; avatarUrl?: string },
|
||||
) {
|
||||
const user = await this.assertActiveUser(userId);
|
||||
if (!user.wxOpenId) {
|
||||
throw new BadRequestException('请先完成微信授权');
|
||||
}
|
||||
|
||||
const data: {
|
||||
nickname?: string;
|
||||
avatarResourceId?: bigint;
|
||||
} = {};
|
||||
|
||||
const nickname = input.nickname?.trim();
|
||||
if (nickname && this.isDefaultNickname(user.nickname)) {
|
||||
data.nickname = nickname.slice(0, 64);
|
||||
}
|
||||
|
||||
const avatarUrl = input.avatarUrl?.trim();
|
||||
if (avatarUrl && !user.avatarResourceId) {
|
||||
const avatar = await this.prisma.commonResource.create({
|
||||
data: {
|
||||
ownerType: 'USER',
|
||||
ownerId: userId,
|
||||
bizType: 'AVATAR',
|
||||
mediaType: 'IMAGE',
|
||||
ossBucket: 'wechat',
|
||||
ossKey: `wx-avatar/${user.wxOpenId}`,
|
||||
url: avatarUrl,
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
});
|
||||
data.avatarResourceId = avatar.id;
|
||||
}
|
||||
|
||||
if (!data.nickname && !data.avatarResourceId) {
|
||||
return this.formatUserProfile(user);
|
||||
}
|
||||
|
||||
const updated = await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data,
|
||||
include: { avatar: true },
|
||||
});
|
||||
return this.formatUserProfile(updated);
|
||||
}
|
||||
|
||||
async bindUserWechat(
|
||||
userId: bigint,
|
||||
input: { code?: string; wxSessionKey?: string },
|
||||
|
||||
Reference in New Issue
Block a user