2017-11-17 10:50:00 +08:00
|
|
|
const sql = require('./sql');
|
|
|
|
const source_id = require('./source_id');
|
|
|
|
const utils = require('./utils');
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addNoteSync(noteId, sourceId) {
|
|
|
|
await addEntitySync("notes", noteId, sourceId)
|
2017-11-17 10:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addNoteTreeSync(noteTreeId, sourceId) {
|
|
|
|
await addEntitySync("notes_tree", noteTreeId, sourceId)
|
2017-11-17 10:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addNoteReorderingSync(parentNoteTreeId, sourceId) {
|
|
|
|
await addEntitySync("notes_reordering", parentNoteTreeId, sourceId)
|
2017-11-17 10:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addNoteHistorySync(noteHistoryId, sourceId) {
|
|
|
|
await addEntitySync("notes_history", noteHistoryId, sourceId);
|
2017-11-17 10:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addOptionsSync(optName, sourceId) {
|
|
|
|
await addEntitySync("options", optName, sourceId);
|
2017-11-17 10:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addRecentNoteSync(notePath, sourceId) {
|
|
|
|
await addEntitySync("recent_notes", notePath, sourceId);
|
2017-11-17 10:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
async function addEntitySync(entityName, entityId, sourceId) {
|
|
|
|
await sql.replace("sync", {
|
2017-11-17 10:50:00 +08:00
|
|
|
entity_name: entityName,
|
|
|
|
entity_id: entityId,
|
2017-12-11 01:56:59 +08:00
|
|
|
sync_date: utils.nowDate(),
|
2017-11-17 10:50:00 +08:00
|
|
|
source_id: sourceId || source_id.currentSourceId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
addNoteSync,
|
|
|
|
addNoteTreeSync,
|
|
|
|
addNoteReorderingSync,
|
|
|
|
addNoteHistorySync,
|
|
|
|
addOptionsSync,
|
|
|
|
addRecentNoteSync
|
|
|
|
};
|