/** @module entities/profile */ import { _baseRecord } from '../index.js' import { profileSchema } from './profile.schema.js' /** 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() { console.log('this :=>', this) const validate = profileSchema.validate(this) /** * Log out some useful error messages * TODO: Send validate.error to logging error handler */ if (validate.error) { console.error(`[Profile Entitiy error]: ${validate.error}`) } /** validate(this) always returns something so force it to a bool */ return !validate.error ? true : false } } export { Profile }