1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| // src/lib/cms/cms-repository.ts
export async function updateCmsEntry(
entryId: string,
data: UpdateCmsEntryInput,
userId: string
) {
const db = getDB();
// 获取当前版本以确定新版本号
const currentEntry = await db.query.cmsEntryTable.findFirst({
where: eq(cmsEntryTable.id, entryId),
});
const newVersionNumber = (currentEntry?.version || 0) + 1;
// 创建版本快照
await db.insert(cmsEntryVersionTable).values({
entryId,
versionNumber: newVersionNumber,
title: data.title ?? currentEntry?.title ?? "",
content: data.content ?? currentEntry?.content ?? "",
slug: data.slug ?? currentEntry?.slug,
excerpt: data.excerpt ?? currentEntry?.excerpt,
seoTitle: data.seoTitle ?? currentEntry?.seoTitle,
seoDescription: data.seoDescription ?? currentEntry?.seoDescription,
status: data.status ?? currentEntry?.status ?? "draft",
createdBy: userId,
changeDescription: data.changeDescription,
});
// 更新 Entry
await db
.update(cmsEntryTable)
.set({
...data,
version: newVersionNumber,
updatedAt: new Date(),
})
.where(eq(cmsEntryTable.id, entryId));
}
|