Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

profile.service.js 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. import { db } from '../utils/db'
  2. import { Profile } from '../entities/profile'
  3. /**
  4. * Get Profiles associated with a single user from the database and
  5. * create a class from the data and
  6. * validate the incoming against the schema
  7. * @param {number} userId
  8. * @returns {array} instantiated Profile objects (see: /entites/profile)
  9. */
  10. const fetchProfilesByUserId = async userId => {
  11. const profilesForUserId = await db.get(`/user/${userId}/profiles`)
  12. const validProfileInstances = []
  13. for (let profileData of profilesForUserId) {
  14. const profile = new Profile(profileData)
  15. if (profile.isValid()) {
  16. validProfileInstances.push(profile)
  17. }
  18. }
  19. return validProfileInstances
  20. }
  21. const createProfileForUserId = async (userId, responses) => {
  22. const profile = await db.post(`/user/${userId}/profile`, responses)
  23. return profile
  24. }
  25. const fetchProfileByProfileId = async profileId => {
  26. const profile = await db.get(`/profile/${profileId}`)
  27. return profile
  28. }
  29. export { fetchProfilesByUserId, fetchProfileByProfileId, createProfileForUserId }