Skip to content

Commit 3c37101

Browse files
committed
Use member API v5 instead of v3
1 parent a7ffea4 commit 3c37101

File tree

4 files changed

+18
-39
lines changed

4 files changed

+18
-39
lines changed

config/constants/development.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`,
1111
COMMUNITY_APP_URL: `https://www.${DOMAIN}`,
1212
MEMBER_API_URL: `${DEV_API_HOSTNAME}/v5/members`,
13-
MEMBER_API_V3_URL: `${DEV_API_HOSTNAME}/v3/members`,
1413
CHALLENGE_API_URL: `${DEV_API_HOSTNAME}/v5/challenges`,
1514
CHALLENGE_TIMELINE_TEMPLATES_URL: `${DEV_API_HOSTNAME}/v5/timeline-templates`,
1615
CHALLENGE_TYPES_URL: `${DEV_API_HOSTNAME}/v5/challenge-types`,

config/constants/production.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`,
1111
COMMUNITY_APP_URL: `https://www.${DOMAIN}`,
1212
MEMBER_API_URL: `${PROD_API_HOSTNAME}/v5/members`,
13-
MEMBER_API_V3_URL: `${PROD_API_HOSTNAME}/v3/members`,
1413
CHALLENGE_API_URL: `${PROD_API_HOSTNAME}/v5/challenges`,
1514
CHALLENGE_TIMELINE_TEMPLATES_URL: `${PROD_API_HOSTNAME}/v5/timeline-templates`,
1615
CHALLENGE_TYPES_URL: `${PROD_API_HOSTNAME}/v5/challenge-types`,

src/components/SelectUserAutocomplete/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import React, { useState, useCallback } from 'react'
88
import PropTypes from 'prop-types'
99
import Select from '../Select'
10-
import { suggestProfilesV5, fetchProfileV5 } from '../../services/user'
10+
import { suggestProfiles, fetchProfile } from '../../services/user'
1111
import _ from 'lodash'
1212
import { AUTOCOMPLETE_MIN_LENGTH, AUTOCOMPLETE_DEBOUNCE_TIME_MS } from '../../config/constants'
1313

@@ -27,7 +27,7 @@ export default function SelectUserAutocomplete (props) {
2727
return
2828
}
2929

30-
Promise.all([suggestProfilesV5(inputValue), fetchProfileV5(inputValue)]).then(
30+
Promise.all([suggestProfiles(inputValue), fetchProfile(inputValue)]).then(
3131
([suggestions, user]) => {
3232
const suggestedOptions = suggestions.map((u) => ({
3333
label: u.handle,

src/services/user.js

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
import _ from 'lodash'
22
import { axiosInstance } from './axiosWithAuth'
3-
const { MEMBER_API_URL, MEMBER_API_V3_URL } = process.env
3+
const { MEMBER_API_URL } = process.env
44

55
/**
66
* Api request for fetching user profile
77
* @returns {Promise<*>}
88
*/
99
export async function fetchProfile (handle) {
10-
const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/${handle}`)
11-
return _.get(response, 'data.result.content')
12-
}
13-
14-
/**
15-
* Api request for fetching user profile v5
16-
* @returns {Promise<*>}
17-
*/
18-
export async function fetchProfileV5 (handle) {
19-
const response = await axiosInstance.get(`${MEMBER_API_URL}?handle=${handle}`)
20-
const data = _.get(response, 'data')
21-
return data.length ? data[0] : undefined
10+
const response = await axiosInstance.get(`${MEMBER_API_URL}/${handle}`)
11+
return _.get(response, 'data')
2212
}
2313

2414
/**
25-
* Api request for fetching user profile
15+
* Api request for searching profiles
2616
* @returns {Promise<*>}
2717
*/
28-
export async function searchProfiles (fields, query, limit) {
29-
const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/_search`, {
18+
export async function searchProfiles (fields, queryObject = {}, limit) {
19+
const response = await axiosInstance.get(`${MEMBER_API_URL}`, {
3020
params: {
3121
fields,
32-
query,
33-
limit
22+
...queryObject,
23+
perPage: limit,
24+
page: 1
3425
}
3526
})
3627
return _.get(response, 'data.result.content')
@@ -41,30 +32,20 @@ export async function searchProfiles (fields, query, limit) {
4132
* @returns {Promise<*>}
4233
*/
4334
export async function searchProfilesByUserIds (userIds, fields = 'userId,handle,firstName,lastName,email', limit) {
44-
const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/_search`, {
45-
params: {
46-
query: `${_.map(userIds, id => `userId:${id}`).join(encodeURIComponent(' OR '))}`,
47-
fields,
48-
limit
49-
}
50-
})
51-
return _.get(response, 'data.result.content')
35+
return searchProfiles(
36+
fields,
37+
{
38+
userIds
39+
},
40+
limit
41+
)
5242
}
5343

5444
/**
5545
* Api request for finding (suggesting) users by the part of the handle
5646
* @returns {Promise<*>}
5747
*/
5848
export async function suggestProfiles (partialHandle) {
59-
const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/_suggest/${encodeURIComponent(partialHandle)}`)
60-
return _.get(response, 'data.result.content')
61-
}
62-
63-
/**
64-
* Api request for finding (suggesting) users by the part of the handle
65-
* @returns {Promise<*>}
66-
*/
67-
export async function suggestProfilesV5 (partialHandle) {
6849
const response = await axiosInstance.get(`${MEMBER_API_URL}/autocomplete?term=${encodeURIComponent(partialHandle)}`)
6950
return _.get(response, 'data')
7051
}

0 commit comments

Comments
 (0)