Skip to content

Commit 1a8cb24

Browse files
committed
TSJR-14 - update calls to standardized skills api to send correct payload
1 parent 1410318 commit 1a8cb24

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/libs/shared/lib/components/member-skill-editor/use-member-skill-editor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react'
2-
import { differenceWith } from 'lodash'
2+
import { differenceWith, pick } from 'lodash'
33

44
import { profileContext, ProfileContextData, UserSkill } from '~/libs/core'
55

@@ -45,13 +45,15 @@ export const useMemberSkillEditor = ({
4545
return
4646
}
4747

48+
const skillIds = skills.map(skill => pick(skill, 'id'))
49+
4850
if (!isInitialized) {
49-
await createMemberSkills(profile.userId, skills)
51+
await createMemberSkills(profile.userId, skillIds)
5052
setIsInitialized(true)
5153
return
5254
}
5355

54-
await updateMemberSkills(profile.userId, skills)
56+
await updateMemberSkills(profile.userId, skillIds)
5557
}, [isInitialized, profile?.userId, skills])
5658

5759
// Handle user changes

src/libs/shared/lib/services/standard-skills/standard-skills.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { UserSkill, xhrGetAsync, xhrPostAsync, xhrPutAsync } from '~/libs/core'
33

44
const baseUrl = `${EnvironmentConfig.API.V5}/standardized-skills`
55

6+
export interface UpdateUserSkillDTO {
7+
id: string
8+
levelId?: string
9+
}
10+
611
export async function autoCompleteSkills(queryTerm: string): Promise<UserSkill[]> {
712
if (!queryTerm) {
813
return Promise.resolve([])
@@ -23,13 +28,16 @@ export async function fetchMemberSkills(
2328
return xhrGetAsync(url)
2429
}
2530

26-
export async function createMemberSkills(userId: number, skills: UserSkill[]): Promise<void> {
31+
export async function createMemberSkills(userId: number, skills: UpdateUserSkillDTO[]): Promise<void> {
2732
return xhrPostAsync(`${baseUrl}/user-skills/${userId}`, {
2833
skills,
2934
})
3035
}
3136

32-
export async function updateMemberSkills(userId: string | number, skills: UserSkill[]): Promise<void> {
37+
export async function updateMemberSkills(
38+
userId: string | number,
39+
skills: UpdateUserSkillDTO[],
40+
): Promise<void> {
3341
return xhrPutAsync(`${baseUrl}/user-skills/${userId}`, {
3442
skills,
3543
})

0 commit comments

Comments
 (0)