| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | const sql = require('./sql'); | 
					
						
							|  |  |  | const source_id = require('./source_id'); | 
					
						
							|  |  |  | const utils = require('./utils'); | 
					
						
							| 
									
										
										
										
											2017-12-13 20:34:21 -05:00
										 |  |  | const sync = require('./sync'); | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addNoteSync(noteId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes", noteId, sourceId) | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addNoteTreeSync(noteTreeId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes_tree", noteTreeId, sourceId) | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addNoteReorderingSync(parentNoteTreeId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes_reordering", parentNoteTreeId, sourceId) | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addNoteHistorySync(noteHistoryId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes_history", noteHistoryId, sourceId); | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addOptionsSync(optName, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("options", optName, sourceId); | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addRecentNoteSync(notePath, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("recent_notes", notePath, sourceId); | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:24:08 -05:00
										 |  |  | async function addEntitySync(entityName, entityId, sourceId) { | 
					
						
							| 
									
										
										
										
											2017-12-13 20:34:21 -05:00
										 |  |  |     if (sync.isSyncSetup) { | 
					
						
							|  |  |  |         await sql.replace("sync", { | 
					
						
							|  |  |  |             entity_name: entityName, | 
					
						
							|  |  |  |             entity_id: entityId, | 
					
						
							|  |  |  |             sync_date: utils.nowDate(), | 
					
						
							|  |  |  |             source_id: sourceId || source_id.currentSourceId | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     addNoteSync, | 
					
						
							|  |  |  |     addNoteTreeSync, | 
					
						
							|  |  |  |     addNoteReorderingSync, | 
					
						
							|  |  |  |     addNoteHistorySync, | 
					
						
							|  |  |  |     addOptionsSync, | 
					
						
							|  |  |  |     addRecentNoteSync | 
					
						
							|  |  |  | }; |