| 
									
										
										
										
											2018-03-31 10:51:37 -04:00
										 |  |  | const Note = require('../entities/note'); | 
					
						
							|  |  |  | const NoteRevision = require('../entities/note_revision'); | 
					
						
							| 
									
										
										
										
											2018-04-01 11:42:12 -04:00
										 |  |  | const Image = require('../entities/image'); | 
					
						
							| 
									
										
										
										
											2018-03-31 22:15:06 -04:00
										 |  |  | const NoteImage = require('../entities/note_image'); | 
					
						
							| 
									
										
										
										
											2018-03-31 10:51:37 -04:00
										 |  |  | const Branch = require('../entities/branch'); | 
					
						
							|  |  |  | const Label = require('../entities/label'); | 
					
						
							| 
									
										
										
										
											2018-04-01 12:03:21 -04:00
										 |  |  | const RecentNote = require('../entities/recent_note'); | 
					
						
							| 
									
										
										
										
											2018-04-01 17:38:24 -04:00
										 |  |  | const ApiToken = require('../entities/api_token'); | 
					
						
							| 
									
										
										
										
											2018-05-22 00:22:43 -04:00
										 |  |  | const Option = require('../entities/option'); | 
					
						
							| 
									
										
										
										
											2018-03-31 10:51:37 -04:00
										 |  |  | const repository = require('../services/repository'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createEntityFromRow(row) { | 
					
						
							|  |  |  |     let entity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (row.labelId) { | 
					
						
							|  |  |  |         entity = new Label(row); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (row.noteRevisionId) { | 
					
						
							|  |  |  |         entity = new NoteRevision(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-31 22:15:06 -04:00
										 |  |  |     else if (row.noteImageId) { | 
					
						
							|  |  |  |         entity = new NoteImage(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-01 11:42:12 -04:00
										 |  |  |     else if (row.imageId) { | 
					
						
							|  |  |  |         entity = new Image(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-01 12:03:21 -04:00
										 |  |  |     else if (row.branchId && row.notePath) { | 
					
						
							|  |  |  |         entity = new RecentNote(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-01 17:38:24 -04:00
										 |  |  |     else if (row.apiTokenId) { | 
					
						
							|  |  |  |         entity = new ApiToken(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-31 10:51:37 -04:00
										 |  |  |     else if (row.branchId) { | 
					
						
							|  |  |  |         entity = new Branch(row); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (row.noteId) { | 
					
						
							|  |  |  |         entity = new Note(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-22 00:22:43 -04:00
										 |  |  |     else if (row.name) { | 
					
						
							|  |  |  |         entity = new Option(row); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-31 10:51:37 -04:00
										 |  |  |     else { | 
					
						
							|  |  |  |         throw new Error('Unknown entity type for row: ' + JSON.stringify(row)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return entity; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | repository.setEntityConstructor(createEntityFromRow); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     createEntityFromRow | 
					
						
							|  |  |  | }; |