11import _ from 'lodash'
22import { 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 */
99export 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 */
4334export 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 */
5848export 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