diff --git a/package.json b/package.json index 7280540..3626d18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "faims3-datamodel", - "version": "1.1.3", + "version": "1.1.4", "description": "Database access layer for FAIMS3", "main": "./build/src/index.js", "exports": { diff --git a/src/data_storage/index.ts b/src/data_storage/index.ts index ca88ab1..58153db 100644 --- a/src/data_storage/index.ts +++ b/src/data_storage/index.ts @@ -44,7 +44,7 @@ import { import {shouldDisplayRecord} from '../index'; import { addNewRevisionFromForm, - createNewRecord, + createNewRecordIfMissing, generateFAIMSRevisionID, getRecord, getRevision, @@ -89,8 +89,7 @@ export async function upsertFAIMSData( } const revision_id = generateFAIMSRevisionID(); if (record.revision_id === null) { - // console.info('New record', record); - await createNewRecord(project_id, record, revision_id); + await createNewRecordIfMissing(project_id, record, revision_id); await addNewRevisionFromForm(project_id, record, revision_id); } else { // console.info('Update existing record', record); diff --git a/src/data_storage/internals.ts b/src/data_storage/internals.ts index 073982c..d87ec70 100644 --- a/src/data_storage/internals.ts +++ b/src/data_storage/internals.ts @@ -491,7 +491,9 @@ async function addNewAttributeValuePairs( return avp_map; } -export async function createNewRecord( +// add a new empty record if not already present +// used to initialise a new record before data is added with addNewRevisionFromForm +export async function createNewRecordIfMissing( project_id: ProjectID, record: Record, revision_id: RevisionID @@ -509,9 +511,8 @@ export async function createNewRecord( try { await dataDB.put(new_encoded_record); } catch (err) { - // TODO: add proper error handling for conflicts - console.warn(err); - throw Error('failed to create record document'); + // if there was an error then the document exists + // already which is fine } }