diff --git a/lib/www/server/lib/qc/shots/save-qc.js b/lib/www/server/lib/qc/shots/save-qc.js index ba69d54..0c9748a 100644 --- a/lib/www/server/lib/qc/shots/save-qc.js +++ b/lib/www/server/lib/qc/shots/save-qc.js @@ -5,20 +5,16 @@ async function saveShotsQC (projectId, results) { const client = await setSurvey(projectId); await transaction.begin(client); - async function deleteQCEvent (sequence, shot, qc_id) { - // NOTE that we delete from event_log_full - // because the event is readonly and we can't otherwise - // modify it via event_log (though it'd be nice to) + async function deleteQCEvents (sequence) { const text = ` DELETE FROM event_log_full - WHERE - sequence = $1 AND point = $2 - AND meta->>'qc_id' = $3; + WHERE sequence = $1 AND meta ? 'qc_id'; `; -// console.log("DELETE QUERY", projectId, sequence, shot, qc_id); - return await client.query(text, [ sequence, shot, qc_id ]); + const values = [ sequence ]; + + return await client.query(text, values); } async function updateQCEvent (sequence, shot, qc_id, result) { @@ -37,11 +33,11 @@ async function saveShotsQC (projectId, results) { }; for (const sequence in results) { + // Remove *all* QC events for this sequence + await deleteQCEvents(sequence); for (const shot in results[sequence]) { for (const qc_id in results[sequence][shot]) { const result = results[sequence][shot][qc_id]; - // Remove any existing event for this QC - await deleteQCEvent(sequence, shot, qc_id); if (result !== true) { // `true` means QC passed. Otherwise expect string or array. // Add or replace an existing event for this QC await updateQCEvent(sequence, shot, qc_id, result);