You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /** @module survey/survey */
  2. import { _baseRecord } from '..'
  3. import { surveySchema } from './survey.schema'
  4. class Survey extends _baseRecord {
  5. constructor(questionSteps, roles) {
  6. super()
  7. this.type = this.constructor.name.toLowerCase()
  8. /** Fields */
  9. this.steps = [
  10. ...questionSteps
  11. ] // ! required
  12. this.roleTree = roles
  13. return this
  14. }
  15. setRoleResponses(position) {
  16. const roleStep = this.steps.filter(step => step.response_key_prompt == 'role')[0]
  17. roleStep.responses = this.roleTree[position]
  18. console.log(roleStep)
  19. console.log(this.roleTree[position])
  20. }
  21. isValid() {
  22. const validate = surveySchema.validate(this)
  23. /**
  24. * Log out some useful error messages
  25. */
  26. if (validate.error) {
  27. console.error(`error: ${validate.error} - ${this.type} validation`)
  28. }
  29. /** validate(this) always returns something so force it to a bool */
  30. return !validate.error ? true : false
  31. }
  32. }
  33. export { Survey }