Notes/src/entities/note_image.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

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 {
static get entityName() { return "note_images"; }
2018-03-31 22:15:06 -04:00
static get primaryKeyName() { return "noteImageId"; }
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]);
}
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;
}
if (!this.dateCreated) {
2018-04-02 20:46:46 -04:00
this.dateCreated = dateUtils.nowDate();
}
super.beforeSaving();
if (this.isChanged) {
this.dateModified = dateUtils.nowDate();
}
}
2018-03-31 22:15:06 -04:00
}
module.exports = NoteImage;