diff --git a/api/src/i18n/controllers/translation.controller.ts b/api/src/i18n/controllers/translation.controller.ts index 9c966709..1c81e82b 100644 --- a/api/src/i18n/controllers/translation.controller.ts +++ b/api/src/i18n/controllers/translation.controller.ts @@ -8,9 +8,12 @@ */ import { + BadRequestException, Body, Controller, + Delete, Get, + HttpCode, NotFoundException, Param, Patch, @@ -25,6 +28,7 @@ import { CsrfInterceptor } from '@/interceptors/csrf.interceptor'; import { LoggerService } from '@/logger/logger.service'; import { SettingService } from '@/setting/services/setting.service'; import { BaseController } from '@/utils/generics/base-controller'; +import { DeleteResult } from '@/utils/generics/base-repository'; import { PageQueryDto } from '@/utils/pagination/pagination-query.dto'; import { PageQueryPipe } from '@/utils/pagination/pagination-query.pipe'; import { SearchFilterPipe } from '@/utils/pipes/search-filter.pipe'; @@ -138,4 +142,23 @@ export class TranslationController extends BaseController { str: { $nin: strings }, }); } + + /** + * Deletes a translation by its ID. + * @param id - The ID of the translation to be deleted. + * @returns A Promise that resolves to the deletion result. + */ + @CsrfCheck(true) + @Delete(':id') + @HttpCode(204) + async deleteOne(@Param('id') id: string): Promise { + const result = await this.translationService.deleteOne(id); + if (result.deletedCount === 0) { + this.logger.warn(`Unable to delete Translation by id ${id}`); + throw new BadRequestException( + `Unable to delete Translation with ID ${id}`, + ); + } + return result; + } } diff --git a/frontend/src/components/translations/index.tsx b/frontend/src/components/translations/index.tsx index 5dcca2f0..7f44a621 100644 --- a/frontend/src/components/translations/index.tsx +++ b/frontend/src/components/translations/index.tsx @@ -69,8 +69,8 @@ export const Translations = () => { onError: () => { toast.error(t("message.internal_server_error")); }, - onSuccess: (data) => { - if (data.acknowledged && data.deletedCount > 0) refreshTranslations(); + onSuccess: () => { + refreshTranslations(); toast.success(t("message.success_translation_refresh")); }, });