smaller refactorings (mostly entitization)

This commit is contained in:
azivner
2018-04-01 11:05:09 -04:00
parent c9d73c6115
commit fad0ec757b
12 changed files with 69 additions and 56 deletions

19
src/entities/image.js Normal file
View File

@@ -0,0 +1,19 @@
"use strict";
const Entity = require('./entity');
const utils = require('../services/utils');
class Image extends Entity {
static get tableName() { return "images"; }
static get primaryKeyName() { return "imageId"; }
beforeSaving() {
if (!this.dateCreated) {
this.dateCreated = utils.nowDate();
}
this.dateModified = utils.nowDate();
}
}
module.exports = Image;

View File

@@ -2,6 +2,7 @@
const Entity = require('./entity');
const repository = require('../services/repository');
const utils = require('../services/utils');
class NoteImage extends Entity {
static get tableName() { return "note_images"; }
@@ -10,6 +11,18 @@ class NoteImage extends Entity {
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() {
if (!this.dateCreated) {
this.dateCreated = utils.nowDate();
}
this.dateModified = utils.nowDate();
}
}
module.exports = NoteImage;