From 1410318687e003fecc5836e3a1ece0811d895e30 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Tue, 17 Oct 2023 11:21:11 +0300 Subject: [PATCH 1/2] TSJR-14 - update api endpoints for skills --- .../standard-skills/standard-skills.service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts b/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts index f0acd5ea6..616b13cc2 100644 --- a/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts +++ b/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts @@ -1,7 +1,7 @@ import { EnvironmentConfig } from '~/config' import { UserSkill, xhrGetAsync, xhrPostAsync, xhrPutAsync } from '~/libs/core' -const baseUrl = `${EnvironmentConfig.API.V5}/emsi-skills/member-emsi-skills` +const baseUrl = `${EnvironmentConfig.API.V5}/standardized-skills` export async function autoCompleteSkills(queryTerm: string): Promise { if (!queryTerm) { @@ -9,7 +9,7 @@ export async function autoCompleteSkills(queryTerm: string): Promise { - const url = `${baseUrl}/${userId}?pageFlag=${!config.skipPagination}` + const url = `${baseUrl}/user-skills/${userId}?disablePagination=${config.skipPagination}` return xhrGetAsync(url) } export async function createMemberSkills(userId: number, skills: UserSkill[]): Promise { - return xhrPostAsync(baseUrl, { + return xhrPostAsync(`${baseUrl}/user-skills/${userId}`, { skills, - userId, }) } export async function updateMemberSkills(userId: string | number, skills: UserSkill[]): Promise { - return xhrPutAsync(`${baseUrl}/${userId}`, { + return xhrPutAsync(`${baseUrl}/user-skills/${userId}`, { skills, }) } From 1a8cb245bd55215a1aeb5eeeaa2521c61de3791b Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Tue, 17 Oct 2023 15:30:48 +0300 Subject: [PATCH 2/2] TSJR-14 - update calls to standardized skills api to send correct payload --- .../member-skill-editor/use-member-skill-editor.tsx | 8 +++++--- .../standard-skills/standard-skills.service.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/libs/shared/lib/components/member-skill-editor/use-member-skill-editor.tsx b/src/libs/shared/lib/components/member-skill-editor/use-member-skill-editor.tsx index 1f49c4e5f..87e2ceda2 100644 --- a/src/libs/shared/lib/components/member-skill-editor/use-member-skill-editor.tsx +++ b/src/libs/shared/lib/components/member-skill-editor/use-member-skill-editor.tsx @@ -1,5 +1,5 @@ import { ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react' -import { differenceWith } from 'lodash' +import { differenceWith, pick } from 'lodash' import { profileContext, ProfileContextData, UserSkill } from '~/libs/core' @@ -45,13 +45,15 @@ export const useMemberSkillEditor = ({ return } + const skillIds = skills.map(skill => pick(skill, 'id')) + if (!isInitialized) { - await createMemberSkills(profile.userId, skills) + await createMemberSkills(profile.userId, skillIds) setIsInitialized(true) return } - await updateMemberSkills(profile.userId, skills) + await updateMemberSkills(profile.userId, skillIds) }, [isInitialized, profile?.userId, skills]) // Handle user changes diff --git a/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts b/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts index 616b13cc2..1eb55874a 100644 --- a/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts +++ b/src/libs/shared/lib/services/standard-skills/standard-skills.service.ts @@ -3,6 +3,11 @@ import { UserSkill, xhrGetAsync, xhrPostAsync, xhrPutAsync } from '~/libs/core' const baseUrl = `${EnvironmentConfig.API.V5}/standardized-skills` +export interface UpdateUserSkillDTO { + id: string + levelId?: string +} + export async function autoCompleteSkills(queryTerm: string): Promise { if (!queryTerm) { return Promise.resolve([]) @@ -23,13 +28,16 @@ export async function fetchMemberSkills( return xhrGetAsync(url) } -export async function createMemberSkills(userId: number, skills: UserSkill[]): Promise { +export async function createMemberSkills(userId: number, skills: UpdateUserSkillDTO[]): Promise { return xhrPostAsync(`${baseUrl}/user-skills/${userId}`, { skills, }) } -export async function updateMemberSkills(userId: string | number, skills: UserSkill[]): Promise { +export async function updateMemberSkills( + userId: string | number, + skills: UpdateUserSkillDTO[], +): Promise { return xhrPutAsync(`${baseUrl}/user-skills/${userId}`, { skills, })