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
|
|
|
|
2018-08-22 23:37:06 +02:00
|
|
|
/**
|
|
|
|
* This class represents image's placement in the note(s). One image may be placed into several notes.
|
|
|
|
*
|
|
|
|
* @param {string} noteImageId
|
|
|
|
* @param {string} noteId
|
|
|
|
* @param {string} imageId
|
|
|
|
* @param {boolean} isDeleted
|
|
|
|
* @param {string} dateModified
|
|
|
|
* @param {string} dateCreated
|
|
|
|
*
|
|
|
|
* @extends Entity
|
|
|
|
*/
|
2018-03-31 22:15:06 -04:00
|
|
|
class NoteImage extends Entity {
|
2018-08-16 23:00:04 +02:00
|
|
|
static get entityName() { return "note_images"; }
|
2018-03-31 22:15:06 -04:00
|
|
|
static get primaryKeyName() { return "noteImageId"; }
|
2018-08-12 20:04:48 +02:00
|
|
|
static get hashedProperties() { return ["noteImageId", "noteId", "imageId", "isDeleted", "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-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-08-06 08:59:26 +02:00
|
|
|
super.beforeSaving();
|
2018-08-12 20:04:48 +02:00
|
|
|
|
|
|
|
if (this.isChanged) {
|
|
|
|
this.dateModified = dateUtils.nowDate();
|
|
|
|
}
|
2018-04-01 11:05:09 -04:00
|
|
|
}
|
2018-03-31 22:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NoteImage;
|