2018-04-01 11:05:09 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
2018-04-02 20:46:46 -04:00
|
|
|
const dateUtils = require('../services/date_utils');
|
2018-04-01 11:05:09 -04:00
|
|
|
|
2018-08-22 23:37:06 +02:00
|
|
|
/**
|
|
|
|
* This class represents image data.
|
|
|
|
*
|
|
|
|
* @param {string} imageId
|
|
|
|
* @param {string} format
|
|
|
|
* @param {string} checksum
|
|
|
|
* @param {string} name
|
|
|
|
* @param {blob} data
|
|
|
|
* @param {boolean} isDeleted
|
|
|
|
* @param {string} dateModified
|
|
|
|
* @param {string} dateCreated
|
|
|
|
*
|
|
|
|
* @extends Entity
|
|
|
|
*/
|
2018-04-01 11:05:09 -04:00
|
|
|
class Image extends Entity {
|
2018-08-16 23:00:04 +02:00
|
|
|
static get entityName() { return "images"; }
|
2018-04-01 11:05:09 -04:00
|
|
|
static get primaryKeyName() { return "imageId"; }
|
2018-08-12 20:04:48 +02:00
|
|
|
static get hashedProperties() { return ["imageId", "format", "checksum", "name", "isDeleted", "dateCreated"]; }
|
2018-04-01 11:05:09 -04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Image;
|