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.

profile.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const Schwifty = require('@hapipal/schwifty')
  2. const profileSchema = require('../schemas/profile')
  3. const TagAssociationModel = require('./tag-association')
  4. const ResponseModel = require('./response')
  5. const UserModel = require('./user')
  6. module.exports = class Profile extends Schwifty.Model {
  7. static get tableName() {
  8. return 'profiles'
  9. }
  10. static get relationMappings() {
  11. return {
  12. tags: {
  13. relation: Schwifty.Model.HasManyRelation,
  14. modelClass: TagAssociationModel,
  15. join: {
  16. from: 'tag_associations.profile_id',
  17. to: 'profiles.profile_id',
  18. },
  19. },
  20. responses: {
  21. relation: Schwifty.Model.HasManyRelation,
  22. modelClass: ResponseModel,
  23. join: {
  24. from: 'responses.profile_id',
  25. to: 'profiles.profile_id',
  26. },
  27. },
  28. user: {
  29. relation: Schwifty.Model.BelongsToOneRelation,
  30. modelClass: UserModel,
  31. join: {
  32. from: 'users.user_id',
  33. to: 'profiles.user_id',
  34. },
  35. },
  36. }
  37. }
  38. static get joiSchema() {
  39. return profileSchema.single
  40. }
  41. }