2018-01-30 07:34:59 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-30 12:17:44 +08:00
|
|
|
const utils = require('../services/utils');
|
2018-04-01 11:08:22 +08:00
|
|
|
const repository = require('../services/repository');
|
2018-01-30 12:17:44 +08:00
|
|
|
|
2018-01-30 07:34:59 +08:00
|
|
|
class Entity {
|
2018-04-01 23:42:12 +08:00
|
|
|
constructor(row = {}) {
|
2018-03-31 21:07:58 +08:00
|
|
|
utils.assertArguments(row);
|
2018-01-30 07:34:59 +08:00
|
|
|
|
|
|
|
for (const key in row) {
|
|
|
|
this[key] = row[key];
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 11:08:22 +08:00
|
|
|
|
2018-04-03 08:30:00 +08:00
|
|
|
beforeSaving() {
|
|
|
|
if (!this[this.constructor.primaryKeyName]) {
|
|
|
|
this[this.constructor.primaryKeyName] = utils.newEntityId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 11:08:22 +08:00
|
|
|
async save() {
|
|
|
|
await repository.updateEntity(this);
|
|
|
|
}
|
2018-01-30 07:34:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Entity;
|