0.0.9.0
This commit is contained in:
@@ -24,10 +24,10 @@ export async function recordMemberHistory(params: {
|
||||
const nextVersion = (lastHistory?.version || 0) + 1
|
||||
|
||||
// 计算变更的字段
|
||||
let changes: Record<string, { old: any, new: any }> | null = null
|
||||
let changes: Record<string, { old: any, new: any }> | undefined = undefined
|
||||
|
||||
if (changeType === 'UPDATE' && oldData) {
|
||||
changes = {}
|
||||
const tempChanges: Record<string, { old: any, new: any }> = {}
|
||||
const fieldsToTrack = [
|
||||
'fullName', 'surname', 'givenName', 'gender', 'birthDate', 'deathDate',
|
||||
'birthPlace', 'ancestralHome', 'generation', 'bio', 'phone', 'email',
|
||||
@@ -43,14 +43,16 @@ export async function recordMemberHistory(params: {
|
||||
// 比较值是否真的变化了
|
||||
const isChanged = JSON.stringify(oldValue) !== JSON.stringify(newValue)
|
||||
if (isChanged) {
|
||||
changes[field] = { old: oldValue, new: newValue }
|
||||
tempChanges[field] = { old: oldValue, new: newValue }
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有实际变更,不记录
|
||||
if (Object.keys(changes).length === 0) {
|
||||
if (Object.keys(tempChanges).length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
changes = tempChanges
|
||||
}
|
||||
|
||||
// 创建历史记录
|
||||
@@ -62,7 +64,7 @@ export async function recordMemberHistory(params: {
|
||||
snapshot: newData,
|
||||
changedBy,
|
||||
changeType,
|
||||
changes,
|
||||
changes: changes || undefined,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user