| 123456789101112131415161718192021222324252627282930313233 |
- import { db } from '../utils/db'
- import { Profile } from '../entities/profile'
-
- /**
- * Get Profiles associated with a single user from the database and
- * create a class from the data and
- * validate the incoming against the schema
- * @param {number} userId
- * @returns {array} instantiated Profile objects (see: /entites/profile)
- */
- const fetchProfilesByUserId = async userId => {
- const profilesForUserId = await db.get(`/user/${userId}/profiles`)
- const validProfileInstances = []
- for (let profileData of profilesForUserId) {
- const profile = new Profile(profileData)
- if (profile.isValid()) {
- validProfileInstances.push(profile)
- }
- }
- return validProfileInstances
- }
-
- const createProfileForUserId = async (userId, responses) => {
- const profile = await db.post(`/user/${userId}/profile`, responses)
- return profile
- }
-
- const fetchProfileByProfileId = async profileId => {
- const profile = await db.get(`/profile/${profileId}`)
- return profile
- }
-
- export { fetchProfilesByUserId, fetchProfileByProfileId, createProfileForUserId }
|