Notes/src/entities/note_image.js

35 lines
1000 B
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
class NoteImage extends Entity {
static get tableName() { return "note_images"; }
static get primaryKeyName() { return "noteImageId"; }
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]);
}
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;
}
if (!this.dateCreated) {
2018-04-02 20:46:46 -04:00
this.dateCreated = dateUtils.nowDate();
}
2018-04-02 20:46:46 -04:00
this.dateModified = dateUtils.nowDate();
}
2018-03-31 22:15:06 -04:00
}
module.exports = NoteImage;