2018-03-31 22:15:06 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
|
|
|
const repository = require('../services/repository');
|
2018-04-02 20:46:46 -04:00
|
|
|
const dateUtils = require('../services/date_utils');
|
2018-03-31 22:15:06 -04:00
|
|
|
|
|
|
|
class NoteImage extends Entity {
|
|
|
|
static get tableName() { return "note_images"; }
|
|
|
|
static get primaryKeyName() { return "noteImageId"; }
|
2018-05-22 00:15:54 -04:00
|
|
|
static get syncedProperties() { return ["noteImageId", "noteId", "imageId", "isDeleted", "dateModified", "dateCreated"]; }
|
2018-03-31 22:15:06 -04:00
|
|
|
|
|
|
|
async getNote() {
|
|
|
|
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
|
|
|
}
|
2018-04-01 11:05:09 -04:00
|
|
|
|
|
|
|
async getImage() {
|
|
|
|
return await repository.getEntity("SELECT * FROM images WHERE imageId = ?", [this.imageId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeSaving() {
|
2018-04-02 20:30:00 -04:00
|
|
|
super.beforeSaving();
|
2018-04-01 17:38:24 -04:00
|
|
|
|
|
|
|
if (!this.isDeleted) {
|
|
|
|
this.isDeleted = false;
|
|
|
|
}
|
|
|
|
|
2018-04-01 11:05:09 -04:00
|
|
|
if (!this.dateCreated) {
|
2018-04-02 20:46:46 -04:00
|
|
|
this.dateCreated = dateUtils.nowDate();
|
2018-04-01 11:05:09 -04:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:46:46 -04:00
|
|
|
this.dateModified = dateUtils.nowDate();
|
2018-04-01 11:05:09 -04:00
|
|
|
}
|
2018-03-31 22:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NoteImage;
|