| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | const sql = require('./sql'); | 
					
						
							|  |  |  | const source_id = require('./source_id'); | 
					
						
							|  |  |  | const utils = require('./utils'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function addNoteSync(noteId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes", noteId, sourceId) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function addNoteTreeSync(noteId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes_tree", noteId, sourceId) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 22:18:25 -05:00
										 |  |  | async function addNoteReorderingSync(parentNoteId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes_reordering", parentNoteId, sourceId) | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function addNoteHistorySync(noteHistoryId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("notes_history", noteHistoryId, sourceId); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function addOptionsSync(optName, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("options", optName, sourceId); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  | async function addRecentNoteSync(noteTreeId, sourceId) { | 
					
						
							|  |  |  |     await addEntitySync("recent_notes", noteTreeId, sourceId); | 
					
						
							| 
									
										
										
										
											2017-11-16 21:50:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function addEntitySync(entityName, entityId, sourceId) { | 
					
						
							|  |  |  |     await sql.replace("sync", { | 
					
						
							|  |  |  |         entity_name: entityName, | 
					
						
							|  |  |  |         entity_id: entityId, | 
					
						
							|  |  |  |         sync_date: utils.nowTimestamp(), | 
					
						
							|  |  |  |         source_id: sourceId || source_id.currentSourceId | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     addNoteSync, | 
					
						
							|  |  |  |     addNoteTreeSync, | 
					
						
							|  |  |  |     addNoteReorderingSync, | 
					
						
							|  |  |  |     addNoteHistorySync, | 
					
						
							|  |  |  |     addOptionsSync, | 
					
						
							|  |  |  |     addRecentNoteSync | 
					
						
							|  |  |  | }; |