From 592c51d1a5d6d1ca45f6c3ce6e88a0541fc7f328 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 12 Apr 2018 18:31:29 -0400 Subject: [PATCH] fix note reordering sync again --- src/routes/api/sync.js | 2 +- src/services/consistency_checks.js | 10 ---------- src/services/sync_update.js | 10 ++++++---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index b90266048..5854dedeb 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -68,7 +68,7 @@ async function update(req) { const entities = req.body.entities; for (const {sync, entity} of entities) { - await syncUpdateService.updateEntity(sync.entityName, entity, sourceId); + await syncUpdateService.updateEntity(sync, entity, sourceId); } } diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 07722805f..bc764db3f 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -197,16 +197,6 @@ async function runAllChecks() { AND images.isDeleted = 1`, "Note image is not deleted while image is deleted for noteImageId", errorList); - await runCheck(` - SELECT - noteId - FROM - notes - WHERE - isDeleted = 0 - AND (title IS NULL OR content IS NULL)`, - "Note has null title or text", errorList); - await runCheck(` SELECT noteId diff --git a/src/services/sync_update.js b/src/services/sync_update.js index c4c358027..6fc7632bf 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -3,7 +3,9 @@ const log = require('./log'); const eventLogService = require('./event_log'); const syncTableService = require('./sync_table'); -async function updateEntity(entityName, entity, sourceId) { +async function updateEntity(sync, entity, sourceId) { + const {entityName} = sync; + if (entityName === 'notes') { await updateNote(entity, sourceId); } @@ -14,7 +16,7 @@ async function updateEntity(entityName, entity, sourceId) { await updateNoteRevision(entity, sourceId); } else if (entityName === 'note_reordering') { - await updateNoteReordering(entity, sourceId); + await updateNoteReordering(sync.entityId, entity, sourceId); } else if (entityName === 'options') { await updateOptions(entity, sourceId); @@ -94,13 +96,13 @@ async function updateNoteRevision(entity, sourceId) { }); } -async function updateNoteReordering(entity, sourceId) { +async function updateNoteReordering(entityId, entity, sourceId) { await sql.transactional(async () => { Object.keys(entity).forEach(async key => { await sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", [entity[key], key]); }); - await syncTableService.addNoteReorderingSync(entity.parentNoteId, sourceId); + await syncTableService.addNoteReorderingSync(entityId, sourceId); }); }