Some checks failed
Sync dev → Gitea / Mirror dev to Gitea (push) Has been cancelled
- Added a comment line to main.ts for deployment verification purposes
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { Body, Controller, Get, Param, Post, Put, Query, UseGuards } from "@nestjs/common";
|
|
import { Public } from "../common/decorators/public.decorator";
|
|
import { Roles } from "../common/decorators/roles.decorator";
|
|
import { RolesGuard } from "../common/guards/roles.guard";
|
|
import { TranslationsService } from "./translations.service";
|
|
|
|
@Controller("translations")
|
|
export class TranslationsController {
|
|
constructor(private translationsService: TranslationsService) {}
|
|
|
|
@Get("search")
|
|
@UseGuards(RolesGuard)
|
|
@Roles("admin")
|
|
async search(@Query("q") query: string) {
|
|
return this.translationsService.searchTranslations(query || "");
|
|
}
|
|
|
|
@Get(":key")
|
|
@Public()
|
|
async getTranslation(@Param("key") key: string) {
|
|
return this.translationsService.getTranslation(key);
|
|
}
|
|
|
|
@Post("batch")
|
|
async translateBatch(@Body() body: { items: { key: string; sourceText: string }[] }) {
|
|
return this.translationsService.translateBatch(body.items);
|
|
}
|
|
|
|
@Put(":key")
|
|
@UseGuards(RolesGuard)
|
|
@Roles("admin")
|
|
async setTranslation(
|
|
@Param("key") key: string,
|
|
@Body() body: { sourceText: string; translatedText: string },
|
|
) {
|
|
return this.translationsService.setTranslation(key, body.sourceText, body.translatedText);
|
|
}
|
|
}
|