Skip to content

Commit

Permalink
[MWPW-161959] Speaker type retention issue (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai authored Nov 11, 2024
1 parent fb0e6d3 commit e9a6baf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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] };
Expand Down
7 changes: 5 additions & 2 deletions ecc/components/profile/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 31 additions & 4 deletions ecc/scripts/esp-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ 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 {
speakerId,
firstName,
lastName,
title,
company,
type,
bio,
socialLinks: socialMedia,
creationTime,
Expand All @@ -182,15 +182,15 @@ 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 {
speakerId,
firstName,
lastName,
title,
company,
type,
bio,
photo,
socialMedia: socialLinks || [],
Expand Down Expand Up @@ -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()];
Expand Down

0 comments on commit e9a6baf

Please sign in to comment.