väli committi

This commit is contained in:
arttu
2024-07-03 12:05:00 +03:00
committed by ShootingStar91
parent ce849270c6
commit e3fbcba7e3
2 changed files with 8 additions and 6 deletions
+2 -1
View File
@@ -102,7 +102,8 @@ export const processLocalityForEdit = async (editedLocality: EditDataType<Locali
const oldLocality = await getLocalityDetails(fixedEditedLocality.lid!)
// const validationErrors = validateEntireLocality(editedLocality)
// if (validationErrors.length > 0) return { validationErrors }
const result = write(editedLocality, 'now_loc', oldLocality!)
const testLoc = await getLocalityDetails(fixedEditedLocality.lid!)
const result = write(testLoc!, 'now_loc', oldLocality!)
return { result }
}
+6 -5
View File
@@ -27,11 +27,12 @@ type Item = { column: string; value: any }
type WriteItem = { table: string; type: 'add' | 'update' | 'delete'; items: Item[] }
const getFindFunction = (tableName: string, newItem: any) => (item: any) => {
if (tableName === 'now_ls') {
// todo this should be com species when it is fixed
if (item.species_id === newItem.species_id) return true
const matchFields = (fields: string[]) => {
return !fields.find(f => newItem[f] !== item[f])
}
return false // TODO add all types
const matches = { now_ls: ['species_id', 'lid'], now_proj: ['pid'], now_plr: ['lid', 'pid'], now_syn_loc: ['syn_id'] }
if (!matches[tableName]) console.log('Alert matcher missing for ', tableName)
return matchFields(matches[tableName])
}
// TODO change ignored fields to allowed fields. form those by taking prisma.model.fields, and adding the accepted relation fields.
@@ -83,7 +84,7 @@ export const write: WriteFunction = (data, tableName, oldObject) => {
.map(item => ({ column: relationField, value: item[idFieldName] }))
rowsToDelete.push(...toBeDeleted)
for (const item of value.filter(({ rowState }) => rowState !== 'removed')) {
const itemWithId = { ...item } // TODO add id here when join tables added
const itemWithId = { ...item, [ids[tableName]]: id }
// console.log('item', item, JSON.stringify(item))
writeTable(itemWithId, relationField, oldObj[relationField].find(getFindFunction(relationField, itemWithId)))
}