mirror of
https://github.com/hexastack/hexabot
synced 2025-05-08 14:54:45 +00:00
fix: delete translation and refresh
This commit is contained in:
parent
6652629995
commit
c174d9d145
@ -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<Translation> {
|
||||
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<DeleteResult> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user