flnxi-Wu/lib/material-log.ts
2026-05-28 23:27:15 +08:00

50 lines
957 B
TypeScript

import { prisma } from '@/lib/prisma'
type MaterialLogChanges = Record<
string,
{
oldValue: unknown
newValue: unknown
}
>
type MaterialSnapshot = Record<string, unknown>
/**
* 历史兼容入口:日志表结构由 Prisma migration 负责,运行期不再建表/改表。
*/
export async function ensureMaterialLogsTable() {
return
}
interface CreateMaterialLogParams {
materialId: string
userId: string
action: string
changes?: MaterialLogChanges | null
materialSnapshot?: MaterialSnapshot | null
}
export async function createMaterialLog({
materialId,
userId,
action,
changes = null,
materialSnapshot = null,
}: CreateMaterialLogParams) {
try {
await (prisma as any).materialLog.create({
data: {
materialId,
userId,
action,
changes,
materialSnapshot,
},
})
} catch (error) {
console.error('[MaterialLog] Failed to create log:', error)
}
}