refactor: P0-1/2/4 解耦修复 - 拆分过耦合文件 + dashboard 解耦
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import "server-only"
|
||||
|
||||
import { cache } from "react"
|
||||
import { and, asc, eq, inArray, like, or, sql, isNull, type SQL } from "drizzle-orm"
|
||||
import { and, asc, count, eq, inArray, like, or, sql, isNull, type SQL } from "drizzle-orm"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
|
||||
import { db } from "@/shared/db"
|
||||
@@ -417,12 +417,28 @@ export async function reorderChapters(chapterId: string, newIndex: number, paren
|
||||
if (ch.order !== i || (ch.id === chapterId && ch.parentId !== parentId)) {
|
||||
await tx
|
||||
.update(chapters)
|
||||
.set({
|
||||
.set({
|
||||
order: i,
|
||||
parentId: ch.id === chapterId ? parentId : ch.parentId
|
||||
parentId: ch.id === chapterId ? parentId : ch.parentId
|
||||
})
|
||||
.where(eq(chapters.id, ch.id))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export type TextbooksDashboardStats = {
|
||||
textbookCount: number
|
||||
chapterCount: number
|
||||
}
|
||||
|
||||
export const getTextbooksDashboardStats = cache(async (): Promise<TextbooksDashboardStats> => {
|
||||
const [textbookCountRow, chapterCountRow] = await Promise.all([
|
||||
db.select({ value: count() }).from(textbooks),
|
||||
db.select({ value: count() }).from(chapters),
|
||||
])
|
||||
return {
|
||||
textbookCount: Number(textbookCountRow[0]?.value ?? 0),
|
||||
chapterCount: Number(chapterCountRow[0]?.value ?? 0),
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user