選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

profile.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /** @module entities/profile */
  2. import { _baseRecord, allModules } from '..'
  3. import { profileSchema } from './profile.schema'
  4. /** Class representing a profile */
  5. class Profile extends _baseRecord {
  6. /**
  7. * Create the profile.
  8. * @extends _baseRecord
  9. * @param {string} email
  10. * @param {object} profile - spread destructured args
  11. * @return {Profile} the profile instance object
  12. */
  13. constructor({ email, ...profileData }) {
  14. super()
  15. this.type = this.constructor.name.toLowerCase()
  16. /** Fields */
  17. this.email = email // ! required
  18. /** Pass destructured data to the module system */
  19. Object.assign(this, profileData)
  20. return this
  21. }
  22. /**
  23. * validate this record
  24. * @return {boolean} is it valid or not?
  25. */
  26. isValid() {
  27. const validate = profileSchema.validate(this)
  28. /**
  29. * Log out some useful error messages
  30. * TODO: Send validate.error to logging error handler
  31. */
  32. if (validate.error) {
  33. console.error(`error: ${validate.error} - ${this.type} validation`)
  34. }
  35. /** validate(this) always returns something so force it to a bool */
  36. return !validate.error ? true : false
  37. }
  38. }
  39. export { Profile }