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