test(i18n): add translated page CRUD locale validation coverage
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
createPageInputSchema,
|
||||
updateNavigationItemInputSchema,
|
||||
updatePageInputSchema,
|
||||
upsertPageTranslationInputSchema,
|
||||
} from "@cms/content"
|
||||
|
||||
import { db } from "./client"
|
||||
@@ -54,6 +55,38 @@ export async function getPublishedPageBySlug(slug: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getPublishedPageBySlugForLocale(slug: string, locale: string) {
|
||||
const page = await db.page.findFirst({
|
||||
where: {
|
||||
slug,
|
||||
status: "published",
|
||||
},
|
||||
include: {
|
||||
translations: {
|
||||
where: {
|
||||
locale,
|
||||
},
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!page) {
|
||||
return null
|
||||
}
|
||||
|
||||
const translation = page.translations[0]
|
||||
|
||||
return {
|
||||
...page,
|
||||
title: translation?.title ?? page.title,
|
||||
summary: translation?.summary ?? page.summary,
|
||||
content: translation?.content ?? page.content,
|
||||
seoTitle: translation?.seoTitle ?? page.seoTitle,
|
||||
seoDescription: translation?.seoDescription ?? page.seoDescription,
|
||||
}
|
||||
}
|
||||
|
||||
export async function createPage(input: unknown) {
|
||||
const payload = createPageInputSchema.parse(input)
|
||||
|
||||
@@ -85,6 +118,33 @@ export async function deletePage(id: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function upsertPageTranslation(input: unknown) {
|
||||
const payload = upsertPageTranslationInputSchema.parse(input)
|
||||
const { pageId, locale, ...data } = payload
|
||||
|
||||
return db.pageTranslation.upsert({
|
||||
where: {
|
||||
pageId_locale: {
|
||||
pageId,
|
||||
locale,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
pageId,
|
||||
locale,
|
||||
...data,
|
||||
},
|
||||
update: data,
|
||||
})
|
||||
}
|
||||
|
||||
export async function listPageTranslations(pageId: string) {
|
||||
return db.pageTranslation.findMany({
|
||||
where: { pageId },
|
||||
orderBy: [{ locale: "asc" }],
|
||||
})
|
||||
}
|
||||
|
||||
export async function listNavigationMenus() {
|
||||
return db.navigationMenu.findMany({
|
||||
orderBy: [{ location: "asc" }, { name: "asc" }],
|
||||
|
||||
Reference in New Issue
Block a user