Skip to content

Commit

Permalink
Merge pull request #4 from FAIMS/fix-bad-save-message
Browse files Browse the repository at this point in the history
Prevent error message when creating records
  • Loading branch information
stevecassidy authored May 24, 2024
2 parents 8728d01 + 1e08518 commit d16e68f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 2 additions & 3 deletions src/data_storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
import {shouldDisplayRecord} from '../index';
import {
addNewRevisionFromForm,
createNewRecord,
createNewRecordIfMissing,
generateFAIMSRevisionID,
getRecord,
getRevision,
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/data_storage/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down

0 comments on commit d16e68f

Please sign in to comment.