UNPKG

mgm

Version:

My generic modules

33 lines (26 loc) 700 B
module.exports = class BaseEntity { constructor() { this.id = ''; this.dataCadastro = ''; } transform(object) { Object.keys(object).forEach(key => { this[key] = object[key]; }); return this; } transformAll(objects) { let transformedObjects = []; objects.forEach(object => { transformedObjects.push(new this.constructor().transform(object)); }); return transformedObjects; } setAttribute(attributeName, attributeValue) { if(this[attributeName] === undefined){ throw new Error(`${attributeName} not finded in ${this.constructor.name}`); } this[attributeName] = attributeValue; return this; } }