...
This commit is contained in:
@@ -1,31 +1,41 @@
|
||||
"use server";
|
||||
|
||||
import { CreateTranslationHistoryInput, TranslationHistoryQuery } from "./translator-action-dto";
|
||||
import {
|
||||
RepoInputCreateTranslationHistory,
|
||||
RepoInputSelectLatestTranslation,
|
||||
RepoOutputSelectLatestTranslation,
|
||||
} from "./translator-repository-dto";
|
||||
import prisma from "@/lib/db";
|
||||
|
||||
/**
|
||||
* 创建翻译历史记录
|
||||
*/
|
||||
export async function repoCreateTranslationHistory(data: CreateTranslationHistoryInput) {
|
||||
return prisma.translationHistory.create({
|
||||
data: data,
|
||||
});
|
||||
export async function repoSelectLatestTranslation(
|
||||
dto: RepoInputSelectLatestTranslation
|
||||
): Promise<RepoOutputSelectLatestTranslation> {
|
||||
const result = await prisma.translationHistory.findFirst({
|
||||
where: {
|
||||
sourceText: dto.sourceText,
|
||||
targetLanguage: dto.targetLanguage,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
id: result.id,
|
||||
translatedText: result.translatedText,
|
||||
sourceLanguage: result.sourceLanguage,
|
||||
targetLanguage: result.targetLanguage,
|
||||
sourceIpa: result.sourceIpa,
|
||||
targetIpa: result.targetIpa,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询最新的翻译记录
|
||||
* @param sourceText 源文本
|
||||
* @param targetLanguage 目标语言
|
||||
* @returns 最新的翻译记录,如果不存在则返回 null
|
||||
*/
|
||||
export async function repoSelectLatestTranslation(query: TranslationHistoryQuery) {
|
||||
return prisma.translationHistory.findFirst({
|
||||
where: {
|
||||
sourceText: query.sourceText,
|
||||
targetLanguage: query.targetLanguage,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
export async function repoCreateTranslationHistory(
|
||||
data: RepoInputCreateTranslationHistory
|
||||
) {
|
||||
return await prisma.translationHistory.create({
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user