Skip to content

Commit

Permalink
fix (backend): 여러 개 연합하는 코드가 날라가서 다시 맞춰왔습니다
Browse files Browse the repository at this point in the history
왜 날라간 거지
  • Loading branch information
HotoRas committed Sep 22, 2024
1 parent e0baac1 commit 8265f35
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions packages/backend/src/core/AvatarDecorationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,15 @@ export class AvatarDecorationService implements OnApplicationShutdown {
});

const userData = await res.json() as Partial<MiUser>;
const avatarDecorations = userData.avatarDecorations?.[0];
const userAvatarDecorations = userData.avatarDecorations ?? undefined;

if (!avatarDecorations) {
if (!userAvatarDecorations || userAvatarDecorations.length === 0) {
const updates = {} as Partial<MiUser>;
updates.avatarDecorations = [];
await this.usersRepository.update({ id: user.id }, updates);
return;
}

const avatarDecorationId = avatarDecorations.id;
const instanceHost = instance?.host;
const decorationApiUrl = `https://${instanceHost}/api/get-avatar-decorations`;
const allRes = await this.httpRequestService.send(decorationApiUrl, {
Expand All @@ -160,41 +159,46 @@ export class AvatarDecorationService implements OnApplicationShutdown {
body: JSON.stringify({}),
});
const allDecorations = await allRes.json() as MiAvatarDecoration[];
let name;
let description;
for (const decoration of allDecorations) {
if (decoration.id === avatarDecorationId) {
name = decoration.name;
description = decoration.description;
break;

const updates = {} as Partial<MiUser>;
updates.avatarDecorations = [];
for (const avatarDecoration of userAvatarDecorations) {
let name;
let description;
const avatarDecorationId = avatarDecoration.id;
for (const decoration of allDecorations) {
if (decoration.id === avatarDecorationId) {
name = decoration.name;
description = decoration.description;
break;
}
}
const existingDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
remoteId: avatarDecorationId,
});
const decorationData = {
name: name,
description: description,
url: this.getProxiedUrl(avatarDecoration.url as string, 'static'),
remoteId: avatarDecorationId,
host: userHost,
};
if (existingDecoration == null) {
await this.create(decorationData);
} else {
await this.update(existingDecoration.id, decorationData);
}
const findDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
remoteId: avatarDecorationId,
});
updates.avatarDecorations.push({
id: findDecoration?.id ?? '',
angle: avatarDecoration.angle ?? 0,
flipH: avatarDecoration.flipH ?? false,
});
}
const existingDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
remoteId: avatarDecorationId,
});
const decorationData = {
name: name,
description: description,
url: this.getProxiedUrl(avatarDecorations.url as string, 'static'),
remoteId: avatarDecorationId,
host: userHost,
};
if (existingDecoration == null) {
await this.create(decorationData);
} else {
await this.update(existingDecoration.id, decorationData);
}
const findDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
remoteId: avatarDecorationId,
});
const updates = {} as Partial<MiUser>;
updates.avatarDecorations = [{
id: findDecoration?.id ?? '',
angle: avatarDecorations.angle ?? 0,
flipH: avatarDecorations.flipH ?? false,
}];
await this.usersRepository.update({ id: user.id }, updates);
}

Expand Down

0 comments on commit 8265f35

Please sign in to comment.