Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
✨ add interco with Conference Hall
Browse files Browse the repository at this point in the history
  • Loading branch information
fgruchala committed Mar 31, 2019
1 parent daaf454 commit d6b23e1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
23 changes: 21 additions & 2 deletions functions/src/editions/business/services/editions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,28 @@ class EditionsService {
});
}

public findOneOnConferenceHall(editionId, apiKey, state = 'accepted'): Promise<any> {
public findOneFromConferenceHall(editionId, apiKey, state = 'accepted'): Promise<any> {
return fetch(`https://conference-hall.io/api/v1/event/${editionId}?key=${apiKey}&state=${state}`)
.then(res => res.json());
.then(res => res.json())
.then(res => {
res.speakers.forEach(speaker => {
speaker.uidFromConferenceHall = speaker.uid;
delete speaker.uid;
});

res.talks.forEach(talk => {
talk.uidFromConferenceHall = talk.id;
delete talk.id;

talk.categories = res.categories.find(category => category.id === talk.categories);
talk.formats = res.formats.find(format => format.id === talk.formats);
});

return {
speakers: res.speakers,
talks: res.talks
};
});
}

}
Expand Down
20 changes: 20 additions & 0 deletions functions/src/editions/functions/find-one-from-conference-hall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as functions from 'firebase-functions';
import editionsService from '../../editions/business/services/editions.service';

export default (data, context) => {
const editionId = data.editionId;
const state = data.state;
console.log('editionId', editionId);
console.log('state', state);

if (!context.auth) {
throw new functions.https.HttpsError('unauthenticated', 'You must be authenticated to access this resource.');
}

if (editionId === undefined) {
throw new functions.https.HttpsError('invalid-argument', 'Required editionId field in the request.');
}

return editionsService.findOne(editionId)
.then(edition => editionsService.findOneFromConferenceHall(edition.conferenceHall.eventId, edition.conferenceHall.apiKey, state));
};
4 changes: 4 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';

import findOneFromConferenceHall from './editions/functions/find-one-from-conference-hall';

import findAllActivePartners from './partners/functions/find-all-active-partners';
import makeBillingForPartner from './partners/functions/make-billing-for-partner';

Expand All @@ -15,3 +17,5 @@ exports.makeBillingForPartner = functions.firestore.document('partners/{partnerI

exports.findAllActiveSpeakers = functions.https.onRequest(findAllActiveSpeakers);
exports.findAllSpeakersFromConferenceHall = functions.https.onCall(findAllSpeakersFromConferenceHall);

exports.findOneFromConferenceHall = functions.https.onCall(findOneFromConferenceHall);

0 comments on commit d6b23e1

Please sign in to comment.