From f965b35a2c652769d41dbe17882dbc2acf41985a Mon Sep 17 00:00:00 2001 From: FineArchs Date: Fri, 11 Oct 2024 14:15:44 +0900 Subject: [PATCH] type fix --- packages/backend/src/core/CustomEmojiService.ts | 6 +++--- .../src/server/api/endpoints/admin/emoji/update.ts | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts index 1e31d39f11..078351327f 100644 --- a/packages/backend/src/core/CustomEmojiService.ts +++ b/packages/backend/src/core/CustomEmojiService.ts @@ -114,20 +114,20 @@ export class CustomEmojiService implements OnApplicationShutdown { localOnly?: boolean; roleIdsThatCanBeUsedThisEmojiAsReaction?: MiRole['id'][]; }, moderator?: MiUser): Promise< - undefined + void | "NO_SUCH_EMOJI" | "SAME_NAME_EMOJI_EXISTS" > { const emoji = data.id ? await this.getEmojiById(data.id) - : await this.getEmojiByName(data.name); + : await this.getEmojiByName(data.name!); if (emoji === null) return "NO_SUCH_EMOJI"; const id = emoji.id; // IDと絵文字名が両方指定されている場合は絵文字名の変更を行うため重複チェックが必要 const doNameUpdate = data.id && data.name && (data.name !== emoji.name); if (doNameUpdate) { - const isDuplicate = await this.checkDuplicate(data.name); + const isDuplicate = await this.checkDuplicate(data.name!); if (isDuplicate) return "SAME_NAME_EMOJI_EXISTS"; } diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts index dca89c6578..2e6a662be2 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts @@ -6,7 +6,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { CustomEmojiService } from '@/core/CustomEmojiService.js'; -import type { DriveFilesRepository } from '@/models/_.js'; +import type { DriveFilesRepository, MiEmoji } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../../error.js'; @@ -78,9 +78,13 @@ export default class extends Endpoint { // eslint- if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); } + // JSON schemeのanyOfの型変換がうまくいっていないらしい + const required = { id: ps.id, name: ps.name } as + | { id: MiEmoji['id']; name?: string } + | { id?: MiEmoji['id']; name: string }; + const error = await this.customEmojiService.update({ - id: ps.id, - name: ps.name, + ...required, driveFile, category: ps.category, aliases: ps.aliases,