From e9a6baf2f3aef27c40b5f2e817595f0a2f49798b Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 11 Nov 2024 15:39:51 -0600 Subject: [PATCH] [MWPW-161959] Speaker type retention issue (#284) --- .../profile-component-controller.js | 6 ++-- ecc/components/profile/profile.js | 7 ++-- ecc/scripts/esp-controller.js | 35 ++++++++++++++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ecc/blocks/form-handler/controllers/profile-component-controller.js b/ecc/blocks/form-handler/controllers/profile-component-controller.js index fd63b307..2cf96fb2 100644 --- a/ecc/blocks/form-handler/controllers/profile-component-controller.js +++ b/ecc/blocks/form-handler/controllers/profile-component-controller.js @@ -1,10 +1,10 @@ /* eslint-disable no-unused-vars */ import { addSpeakerToEvent, - getSpeaker, getSpeakers, updateSpeakerInEvent, removeSpeakerFromEvent, + getEventSpeaker, } from '../../../scripts/esp-controller.js'; import { getFilteredCachedResponse } from '../data-handler.js'; @@ -120,10 +120,10 @@ export async function onRespUpdate(_component, _props) { async function prefillProfiles(props) { const d = await props.eventDataResp; if (d?.eventId && d.seriesId) { - const { seriesId } = d; + const { eventId, seriesId } = d; try { // eslint-disable-next-line max-len - const speakers = await Promise.all(d.speakers.map(async (sp) => getSpeaker(seriesId, sp.speakerId))); + const speakers = await Promise.all(d.speakers.map(async (sp) => getEventSpeaker(seriesId, eventId, sp.speakerId))); for (let idx = 0; idx < d.speakers.length; idx += 1) { // eslint-disable-next-line max-len d.speakers[idx] = { ...d.speakers[idx], type: d.speakers[idx].speakerType, ...speakers[idx] }; diff --git a/ecc/components/profile/profile.js b/ecc/components/profile/profile.js index 75d5168f..972e5eee 100644 --- a/ecc/components/profile/profile.js +++ b/ecc/components/profile/profile.js @@ -114,11 +114,14 @@ export class Profile extends LitElement { profile.isPlaceholder = false; profile.socialMedia = profile.socialMedia.filter((sm) => sm.link !== ''); + + const sProfile = { ...profile }; + delete sProfile.type; let respJson; if (this.profile.speakerId) { - respJson = await updateSpeaker(profile, this.seriesId); + respJson = await updateSpeaker(sProfile, this.seriesId); } else { - respJson = await createSpeaker(profile, this.seriesId); + respJson = await createSpeaker(sProfile, this.seriesId); } if (respJson.error) { diff --git a/ecc/scripts/esp-controller.js b/ecc/scripts/esp-controller.js index f7b650f8..3c604c74 100644 --- a/ecc/scripts/esp-controller.js +++ b/ecc/scripts/esp-controller.js @@ -163,7 +163,7 @@ export async function uploadImage(file, configs, tracker, imageId = null) { function convertToNSpeaker(profile) { const { // eslint-disable-next-line max-len - speakerId, firstName, lastName, title, company, bio, socialMedia, creationTime, modificationTime, + speakerId, firstName, lastName, title, type, bio, socialMedia, creationTime, modificationTime, } = profile; return { @@ -171,7 +171,7 @@ function convertToNSpeaker(profile) { firstName, lastName, title, - company, + type, bio, socialLinks: socialMedia, creationTime, @@ -182,7 +182,7 @@ function convertToNSpeaker(profile) { function convertToSpeaker(speaker) { const { // eslint-disable-next-line max-len - speakerId, firstName, lastName, title, company, bio, socialLinks, creationTime, modificationTime, photo, + speakerId, firstName, lastName, title, type, bio, socialLinks, creationTime, modificationTime, photo, } = speaker; return { @@ -190,7 +190,7 @@ function convertToSpeaker(speaker) { firstName, lastName, title, - company, + type, bio, photo, socialMedia: socialLinks || [], @@ -553,6 +553,33 @@ export async function getSpeaker(seriesId, speakerId) { } } +export async function getEventSpeaker(seriesId, eventId, speakerId) { + const { host } = API_CONFIG.esp[getEventServiceEnv()]; + const options = await constructRequestOptions('GET'); + + const seriesSpeaker = await getSpeaker(seriesId, speakerId); + + if (seriesSpeaker.error) { + window.lana?.log('Failed to get event speaker details. Status:', seriesSpeaker.status, 'Error:', seriesSpeaker); + return { status: seriesSpeaker.status, error: seriesSpeaker.error.message }; + } + + try { + const response = await fetch(`${host}/v1/events/${eventId}/speakers/${speakerId}`, options); + const data = await response.json(); + + if (!response.ok) { + window.lana?.log('Failed to get event speaker details. Status:', response.status, 'Error:', data); + return { status: response.status, error: data }; + } + + return convertToSpeaker({ ...seriesSpeaker, type: data.speakerType }); + } catch (error) { + window.lana?.log('Failed to get event speaker details. Error:', error); + return { status: 'Network Error', error: error.message }; + } +} + export async function updateSpeaker(profile, seriesId) { const nSpeaker = convertToNSpeaker(profile); const { host } = API_CONFIG.esp[getEventServiceEnv()];