| 
									
										
										
										
											2017-10-21 21:10:33 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 11:05:09 -04:00
										 |  |  | const repository = require('../../services/repository'); | 
					
						
							| 
									
										
										
										
											2019-09-07 10:11:59 +02:00
										 |  |  | const noteCacheService = require('../../services/note_cache'); | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 13:56:46 -04:00
										 |  |  | async function getNoteRevisions(req) { | 
					
						
							| 
									
										
										
										
											2019-11-01 19:21:48 +01:00
										 |  |  |     const {noteId} = req.params; | 
					
						
							| 
									
										
										
										
											2019-09-08 09:17:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return await repository.getEntities(`
 | 
					
						
							|  |  |  |         SELECT note_revisions.* | 
					
						
							|  |  |  |         FROM note_revisions  | 
					
						
							|  |  |  |         WHERE noteId = ?  | 
					
						
							| 
									
										
										
										
											2019-11-01 19:21:48 +01:00
										 |  |  |         ORDER BY utcDateCreated DESC`, [noteId]);
 | 
					
						
							| 
									
										
										
										
											2019-09-08 09:17:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 19:21:48 +01:00
										 |  |  | async function getNoteRevision(req) { | 
					
						
							| 
									
										
										
										
											2019-11-01 20:00:56 +01:00
										 |  |  |     const noteRevision = await repository.getNoteRevision(req.params.noteRevisionId); | 
					
						
							| 
									
										
										
										
											2019-09-08 09:17:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 20:00:56 +01:00
										 |  |  |     await noteRevision.getContent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return noteRevision; | 
					
						
							| 
									
										
										
										
											2018-03-30 13:56:46 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-07 10:11:59 +02:00
										 |  |  | async function getEditedNotesOnDate(req) { | 
					
						
							|  |  |  |     const date = req.params.date; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const notes = await repository.getEntities(`
 | 
					
						
							|  |  |  |         select distinct notes.* | 
					
						
							|  |  |  |         from notes | 
					
						
							|  |  |  |         left join note_revisions using (noteId) | 
					
						
							|  |  |  |         where substr(notes.dateCreated, 0, 11) = ? | 
					
						
							|  |  |  |            or substr(notes.dateModified, 0, 11) = ? | 
					
						
							| 
									
										
										
										
											2019-11-01 19:21:48 +01:00
										 |  |  |            or substr(note_revisions.dateLastEdited, 0, 11) = ?`, [date, date, date]);
 | 
					
						
							| 
									
										
										
										
											2019-09-07 10:11:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (const note of notes) { | 
					
						
							|  |  |  |         const notePath = noteCacheService.getNotePath(note.noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         note.notePath = notePath ? notePath.notePath : null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return notes; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 13:56:46 -04:00
										 |  |  | module.exports = { | 
					
						
							| 
									
										
										
										
											2019-09-07 10:11:59 +02:00
										 |  |  |     getNoteRevisions, | 
					
						
							| 
									
										
										
										
											2019-11-01 19:21:48 +01:00
										 |  |  |     getNoteRevision, | 
					
						
							| 
									
										
										
										
											2019-09-07 10:11:59 +02:00
										 |  |  |     getEditedNotesOnDate | 
					
						
							| 
									
										
										
										
											2018-03-30 13:56:46 -04:00
										 |  |  | }; |