Skip to content

Commit e97c0db

Browse files
committed
V6 updates and fixes
1 parent 651f0f6 commit e97c0db

File tree

13 files changed

+218
-122
lines changed

13 files changed

+218
-122
lines changed

src/apps/admin/src/lib/components/ReviewSummaryList/MobileListView/MobileListView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ const MobileListView: FC<MobileListViewProps<ReviewSummary>> = props => {
6464
))
6565

6666
return (
67-
<div className={styles.mobileListViewItemContainer} key={d.legacyChallengeId}>
67+
<div
68+
className={styles.mobileListViewItemContainer}
69+
key={d.legacyChallengeId || d.challengeId}
70+
>
6871
<div className={styles.rows}>
6972
<div className={styles.row1}>
7073
{/* Title */ propertyElements[0]}

src/apps/admin/src/lib/models/MemberInfo.model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
export interface MemberInfo {
55
handle: string
66
userId: number
7+
firstName?: string | null
8+
lastName?: string | null
9+
photoURL?: string | null
10+
maxRating?: unknown
711
}

src/apps/admin/src/lib/models/review-management/ReviewSummary.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export interface ReviewSummary {
2+
/** Challenge uuid */
3+
challengeId: string
24
/** Challenge Name */
35
challengeName: string
46
/** Challenge Status */

src/apps/admin/src/lib/services/billing-accounts.service.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { EnvironmentConfig } from '~/config'
77
import {
88
xhrDeleteAsync,
99
xhrGetAsync,
10+
xhrGetPaginatedAsync,
1011
xhrPatchAsync,
1112
xhrPostAsync,
1213
} from '~/libs/core'
1314

1415
import {
1516
adjustBillingAccountResponse,
16-
ApiV3Response,
1717
BillingAccount,
1818
BillingAccountResource,
1919
FormEditBillingAccount,
@@ -39,15 +39,17 @@ export const searchBillingAccounts = async (
3939
content: BillingAccount[]
4040
totalPages: number
4141
}> => {
42-
const data = await xhrGetAsync<ApiV3Response<BillingAccount[]>>(
42+
const { data, totalPages }: {
43+
data: BillingAccount[]
44+
totalPages: number
45+
} = await xhrGetPaginatedAsync<BillingAccount[]>(
4346
`${
44-
EnvironmentConfig.API.V3
47+
EnvironmentConfig.API.V6
4548
}/billing-accounts?${createFilterPageSortQuery(criteria, pageAndSort)}`,
4649
)
47-
const totalCount = data.result.metadata.totalCount
4850
return {
49-
content: data.result.content.map(adjustBillingAccountResponse),
50-
totalPages: Math.ceil(totalCount / pageAndSort.limit),
51+
content: data.map(adjustBillingAccountResponse),
52+
totalPages,
5153
}
5254
}
5355

@@ -58,12 +60,9 @@ export const searchBillingAccounts = async (
5860
*/
5961
export const findAllBillingAccountResources = async (
6062
accountId: string,
61-
): Promise<BillingAccountResource[]> => {
62-
const data = await xhrGetAsync<ApiV3Response<BillingAccount[]>>(
63-
`${EnvironmentConfig.API.V3}/billing-accounts/${accountId}/users`,
64-
)
65-
return data.result.content
66-
}
63+
): Promise<BillingAccountResource[]> => xhrGetAsync<BillingAccountResource[]>(
64+
`${EnvironmentConfig.API.V6}/billing-accounts/${accountId}/users`,
65+
)
6766

6867
/**
6968
* Find billing account by id
@@ -74,10 +73,10 @@ export const findAllBillingAccountResources = async (
7473
export const findBillingAccountById = async (
7574
id: string,
7675
): Promise<BillingAccount> => {
77-
const data = await xhrGetAsync<ApiV3Response<BillingAccount>>(
78-
`${EnvironmentConfig.API.V3}/billing-accounts/${id}`,
76+
const data = await xhrGetAsync<BillingAccount>(
77+
`${EnvironmentConfig.API.V6}/billing-accounts/${id}`,
7978
)
80-
return adjustBillingAccountResponse(data.result.content)
79+
return adjustBillingAccountResponse(data)
8180
}
8281

8382
/**
@@ -91,7 +90,7 @@ export const deleteBillingAccountResource = async (
9190
resourceId: string,
9291
): Promise<void> => {
9392
await xhrDeleteAsync<void>(
94-
`${EnvironmentConfig.API.V3}/billing-accounts/${accountId}/users/${resourceId}`,
93+
`${EnvironmentConfig.API.V6}/billing-accounts/${accountId}/users/${resourceId}`,
9594
)
9695
}
9796

@@ -153,12 +152,12 @@ export const createBillingAccount = async (
153152
{
154153
param: RequestCommonDataType
155154
},
156-
ApiV3Response<BillingAccount[]>
155+
BillingAccount[]
157156
>(
158-
`${EnvironmentConfig.API.V3}/billing-accounts`,
157+
`${EnvironmentConfig.API.V6}/billing-accounts`,
159158
createBillingAccountRequestData(data),
160159
)
161-
return resultData.result.content
160+
return resultData
162161
}
163162

164163
/**
@@ -178,15 +177,15 @@ export const editBillingAccount = async (
178177
{
179178
param: RequestCommonDataType
180179
},
181-
ApiV3Response<{
180+
{
182181
original: BillingAccount
183182
updated: BillingAccount
184-
}>
183+
}
185184
>(
186-
`${EnvironmentConfig.API.V3}/billing-accounts/${accountId}`,
185+
`${EnvironmentConfig.API.V6}/billing-accounts/${accountId}`,
187186
createBillingAccountRequestData(data),
188187
)
189-
return resultData.result.content
188+
return resultData
190189
}
191190

192191
/**
@@ -203,11 +202,11 @@ export const createBillingAccountResource = async (
203202
{
204203
param: RequestCommonDataType
205204
},
206-
ApiV3Response<BillingAccountResource>
207-
>(`${EnvironmentConfig.API.V3}/billing-accounts/${accountId}/users`, {
205+
BillingAccountResource
206+
>(`${EnvironmentConfig.API.V6}/billing-accounts/${accountId}/users`, {
208207
param: {
209208
userId: data.userId,
210209
},
211210
})
212-
return resultData.result.content
211+
return resultData
213212
}

src/apps/admin/src/lib/services/challenge-management.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const addChallengeResource = async (data: {
129129
challengeId: string
130130
memberHandle: string
131131
roleId: string
132-
}): Promise<unknown> => xhrPostAsync(`${EnvironmentConfig.API.V5}/resources`, data)
132+
}): Promise<unknown> => xhrPostAsync(`${resourceBaseUrl}/resources`, data)
133133

134134
/**
135135
* Gets the challenge details by id.

src/apps/admin/src/lib/services/client.service.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import _ from 'lodash'
22

33
import { EnvironmentConfig } from '~/config'
4-
import { xhrGetAsync, xhrPatchAsync, xhrPostAsync } from '~/libs/core'
4+
import {
5+
xhrGetAsync,
6+
xhrGetPaginatedAsync,
7+
xhrPatchAsync,
8+
xhrPostAsync,
9+
} from '~/libs/core'
510

611
import {
712
adjustClientInfoResponse,
8-
ApiV3Response,
913
ClientInfo,
1014
FormEditClient,
1115
RequestCommonDataType,
@@ -29,16 +33,18 @@ export const searchClients = async (
2933
content: ClientInfo[]
3034
totalPages: number
3135
}> => {
32-
const data = await xhrGetAsync<ApiV3Response<ClientInfo[]>>(
33-
`${EnvironmentConfig.API.V3}/clients?${createFilterPageSortQuery(
36+
const { data, totalPages }: {
37+
data: ClientInfo[]
38+
totalPages: number
39+
} = await xhrGetPaginatedAsync<ClientInfo[]>(
40+
`${EnvironmentConfig.API.V6}/clients?${createFilterPageSortQuery(
3441
criteria,
3542
pageAndSort,
3643
)}`,
3744
)
38-
const totalCount = data.result.metadata.totalCount
3945
return {
40-
content: data.result.content.map(adjustClientInfoResponse),
41-
totalPages: Math.ceil(totalCount / pageAndSort.limit),
46+
content: data.map(adjustClientInfoResponse),
47+
totalPages,
4248
}
4349
}
4450

@@ -50,10 +56,10 @@ export const searchClients = async (
5056
export const findClientById = async (
5157
clientId: number | string,
5258
): Promise<ClientInfo> => {
53-
const data = await xhrGetAsync<ApiV3Response<ClientInfo>>(
54-
`${EnvironmentConfig.API.V3}/clients/${clientId}`,
59+
const data = await xhrGetAsync<ClientInfo>(
60+
`${EnvironmentConfig.API.V6}/clients/${clientId}`,
5561
)
56-
return adjustClientInfoResponse(data.result.content)
62+
return adjustClientInfoResponse(data)
5763
}
5864

5965
/**
@@ -95,9 +101,9 @@ export const createClient = async (
95101
{
96102
param: RequestCommonDataType
97103
},
98-
ApiV3Response<ClientInfo>
99-
>(`${EnvironmentConfig.API.V3}/clients`, createClientRequestData(data))
100-
return resultData.result.content
104+
ClientInfo
105+
>(`${EnvironmentConfig.API.V6}/clients`, createClientRequestData(data))
106+
return resultData
101107
}
102108

103109
/**
@@ -114,10 +120,10 @@ export const editClient = async (
114120
{
115121
param: RequestCommonDataType
116122
},
117-
ApiV3Response<ClientInfo>
123+
ClientInfo
118124
>(
119-
`${EnvironmentConfig.API.V3}/clients/${clientId}`,
125+
`${EnvironmentConfig.API.V6}/clients/${clientId}`,
120126
createClientRequestData(data),
121127
)
122-
return resultData.result.content
128+
return resultData
123129
}

src/apps/admin/src/lib/services/review-management.service.ts

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,75 @@ import { createReviewQueryString } from '../utils'
1515
/**
1616
* Searches the review opportunities using v3 api.
1717
*/
18+
type BackendReviewOpportunitySummary = {
19+
challengeId: string
20+
challengeLegacyId?: string | number
21+
legacyChallengeId?: string | number
22+
challengeName: string
23+
challengeStatus: string
24+
submissionEndDate?: string | null
25+
numberOfSubmissions?: number
26+
numberOfReviewerSpots?: number
27+
numberOfPendingApplications?: number
28+
numberOfApprovedApplications?: number
29+
}
30+
31+
type ReviewOpportunitiesSummaryResponse = {
32+
result: {
33+
success: boolean
34+
status: number
35+
content: BackendReviewOpportunitySummary[]
36+
metadata?: {
37+
total?: number
38+
totalPages?: number
39+
page?: number
40+
perPage?: number
41+
}
42+
}
43+
}
44+
45+
/**
46+
* Searches the review opportunities using v6 api.
47+
*/
1848
export const getReviewOpportunities = async (
1949
filterCriteria: ReviewFilterCriteria,
20-
): Promise<Array<ReviewSummary>> => {
21-
type v3Response<Review> = { result: { content: Review[], metadata: { totalCount: number } } }
22-
const data = await xhrGetAsync<v3Response<ReviewSummary>>(
23-
// eslint-disable-next-line max-len
24-
`${EnvironmentConfig.API.V3}/reviewOpportunities/reviewApplicationsSummary?${createReviewQueryString(filterCriteria)}`,
25-
)
26-
return data.result.content
50+
): Promise<{
51+
content: ReviewSummary[]
52+
metadata?: {
53+
total?: number
54+
totalPages?: number
55+
page?: number
56+
perPage?: number
57+
}
58+
}> => {
59+
const response = await xhrGetAsync<ReviewOpportunitiesSummaryResponse>(
60+
`${EnvironmentConfig.API.V6}/review-opportunities/summary?${createReviewQueryString(filterCriteria)}`,
61+
)
62+
63+
const mapToReviewSummary = (
64+
item: BackendReviewOpportunitySummary,
65+
): ReviewSummary => {
66+
const legacyId = item.challengeLegacyId
67+
?? item.legacyChallengeId
68+
?? item.challengeId
69+
70+
return {
71+
challengeId: item.challengeId,
72+
challengeName: item.challengeName,
73+
challengeStatus: item.challengeStatus,
74+
legacyChallengeId: String(legacyId ?? ''),
75+
numberOfApprovedApplications: item.numberOfApprovedApplications ?? 0,
76+
numberOfPendingApplications: item.numberOfPendingApplications ?? 0,
77+
numberOfReviewerSpots: item.numberOfReviewerSpots ?? 0,
78+
numberOfSubmissions: item.numberOfSubmissions ?? 0,
79+
submissionEndDate: item.submissionEndDate ?? '',
80+
}
81+
}
82+
83+
return {
84+
content: response.result.content.map(mapToReviewSummary),
85+
metadata: response.result.metadata,
86+
}
2787
}
2888

2989
/**

src/apps/admin/src/lib/services/user.service.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,29 @@ export const getMemberSuggestionsByHandle = async (
3131
return []
3232
}
3333

34-
type v3Response<T> = { result: { content: T } }
35-
const data = await xhrGetAsync<
36-
v3Response<Array<MemberInfo>>
37-
>(`${EnvironmentConfig.API.V3}/members/_suggest/${handle}`)
38-
return data.result.content
34+
const sanitizedHandle = encodeURIComponent(handle.trim())
35+
36+
type MemberAutocompleteResponse = {
37+
userId: number
38+
handle: string
39+
firstName?: string | null
40+
lastName?: string | null
41+
photoURL?: string | null
42+
maxRating?: unknown
43+
}
44+
45+
const response = await xhrGetAsync<MemberAutocompleteResponse[]>(
46+
`${EnvironmentConfig.API.V6}/members/autocomplete/${sanitizedHandle}`,
47+
)
48+
49+
return response.map(member => ({
50+
firstName: member.firstName ?? undefined,
51+
handle: member.handle,
52+
lastName: member.lastName ?? undefined,
53+
maxRating: member.maxRating,
54+
photoURL: member.photoURL ?? undefined,
55+
userId: member.userId,
56+
}))
3957
}
4058

4159
/**
@@ -101,10 +119,15 @@ export const getProfile = async (handle: string): Promise<MemberInfo> => {
101119
return Promise.reject(new Error('Handle must be specified.'))
102120
}
103121

104-
const result = await xhrGetAsync<ApiV3Response<MemberInfo>>(
105-
`${EnvironmentConfig.API.V3}/members/${handle}`,
122+
const response = await xhrGetAsync<MemberInfo | ApiV3Response<MemberInfo>>(
123+
`${EnvironmentConfig.API.V6}/members/${handle}`,
106124
)
107-
return result.result.content
125+
126+
if ('result' in response) {
127+
return response.result.content
128+
}
129+
130+
return response
108131
}
109132

110133
/**

0 commit comments

Comments
 (0)