/** @module entities/profile */ import { _baseRecord, allModules } from '..' import { profileSchema } from './profile.schema' /** Class representing a profile */ class Profile extends _baseRecord { /** * Create the profile. * @extends _baseRecord * @param {string} email * @param {object} profile - spread destructured args * @return {Profile} the profile instance object */ constructor({ email, ...profileData }) { super() this.type = this.constructor.name.toLowerCase() /** Fields */ this.email = email // ! required /** Pass destructured data to the module system */ Object.assign(this, profileData) return this } /** * validate this record * @return {boolean} is it valid or not? */ isValid() { const validate = profileSchema.validate(this) /** * Log out some useful error messages * TODO: Send validate.error to logging error handler */ if (validate.error) { console.error(`error: ${validate.error} - ${this.type} validation`) } /** validate(this) always returns something so force it to a bool */ return !validate.error ? true : false } } export { Profile }