2018-03-31 22:15:06 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
|
|
|
const repository = require('../services/repository');
|
2018-04-01 11:05:09 -04:00
|
|
|
const utils = require('../services/utils');
|
2018-03-31 22:15:06 -04:00
|
|
|
|
|
|
|
class NoteImage extends Entity {
|
|
|
|
static get tableName() { return "note_images"; }
|
|
|
|
static get primaryKeyName() { return "noteImageId"; }
|
|
|
|
|
|
|
|
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-01 17:38:24 -04:00
|
|
|
if (!this.noteImageId) {
|
|
|
|
this.noteImageId = utils.newNoteImageId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.isDeleted) {
|
|
|
|
this.isDeleted = false;
|
|
|
|
}
|
|
|
|
|
2018-04-01 11:05:09 -04:00
|
|
|
if (!this.dateCreated) {
|
|
|
|
this.dateCreated = utils.nowDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dateModified = utils.nowDate();
|
|
|
|
}
|
2018-03-31 22:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NoteImage;
|