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

Commit

Permalink
Merge pull request #2 from GDG-Lille/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
François GRUCHALA authored Feb 25, 2019
2 parents f486221 + fcd5c5e commit 8a72b87
Show file tree
Hide file tree
Showing 11 changed files with 936 additions and 1,780 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ node_modules/

# dotenv environment variables file
.env

.idea
2,572 changes: 813 additions & 1,759 deletions functions/package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"main": "lib/index.js",
"dependencies": {
"cors": "^2.8.5",
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.1.0"
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.2.0",
"node-fetch": "^2.3.0"
},
"devDependencies": {
"tslint": "~5.8.0",
"typescript": "~2.8.3"
"tslint": "~5.13.0",
"typescript": "~3.3.3333"
},
"private": true
}
16 changes: 11 additions & 5 deletions functions/src/editions/business/services/editions.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as admin from "firebase-admin";
import * as admin from 'firebase-admin';
import fetch from 'node-fetch';

class EditionsService {

Expand All @@ -8,12 +9,17 @@ class EditionsService {
.doc(editionId)
.get()
.then(edition => {
if(!edition.exists) {
throw new Error(`Edition ${editionId} not found.`)
if (!edition.exists) {
throw new Error(`Edition ${editionId} not found.`);
}

return edition.data()
})
return edition.data();
});
}

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

}
Expand Down
10 changes: 8 additions & 2 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';

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

import findAllActiveSpeakers from './speakers/functions/find-all-active-speakers';
import findAllSpeakersFromConferenceHall
from './speakers/functions/find-all-speakers-from-conference-hall';

admin.initializeApp();
admin.firestore().settings({ timestampsInSnapshots: true });

exports.findAllActivePartners = functions.https.onRequest(findAllActivePartners);
exports.makeBillingForPartner = functions.firestore.document('partners/{partnerId}').onCreate(makeBillingForPartner);

exports.findAllActiveSpeakers = functions.https.onRequest(findAllActiveSpeakers);
exports.findAllSpeakersFromConferenceHall = functions.https.onCall(findAllSpeakersFromConferenceHall);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PartnersService {
.then(query => {
const partners = {};
query.forEach(doc => partners[doc.id] = doc.data());
return partners
return partners;
});
}

Expand Down
15 changes: 7 additions & 8 deletions functions/src/partners/functions/find-all-active-partners.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import * as cors from 'cors';

import partnersService from '../business/services/partners.service';
import editionsService from '../../editions/business/services/editions.service';
import partnersService from '../business/services/partners.service';

function checkOrigin(request, callback) {
const editionId = request.query.editionId;
const origin = request.header('Origin');

editionsService.findOne(editionId)
.then(edition => `https://${edition.url}` === origin ? callback(null, { origin: true }) : callback(null, { origin : false }))
.then(edition => `https://${edition.url}` === origin ? callback(null, {origin: true}) : callback(null, {origin: false}))
.catch(err => {
console.error('checkOrigin', err);
callback(err, { origin: false })
callback(err, {origin: false});
});
}

Expand All @@ -20,8 +19,8 @@ export default (request, response) => {
const editionId = request.query.editionId;
console.log('editionId', editionId);

if(editionId === undefined) {
response.status(400).send({ message: 'Required editionId field in the request.'});
if (editionId === undefined) {
response.status(400).send({message: 'Required editionId field in the request.'});
}

return editionsService.findOne(editionId)
Expand All @@ -34,13 +33,13 @@ export default (request, response) => {
name: partners[key].name,
url: partners[key].url,
logoUrl: partners[key].logoUrl,
level: partners[key].level,
level: partners[key].level
};
});

return limitedPartners;
})
.then(partners => response.send(partners))
.catch(err => response.status(500).send({ message: err.message }));
.catch(err => response.status(500).send({message: err.message}));
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default (snap, context) => {
};

// TODO call Manu soft
};
};
19 changes: 19 additions & 0 deletions functions/src/speakers/business/services/speakers.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as admin from 'firebase-admin';

class SpeakersService {

public findAllActiveByEditionId(editionId: string): Promise<any> {
return admin.firestore()
.collection('speakers')
.where('edition', '==', editionId)
.get()
.then(query => {
const speakers = {};
query.forEach(doc => speakers[doc.id] = doc.data());
return speakers;
});
}

}

export default new SpeakersService();
48 changes: 48 additions & 0 deletions functions/src/speakers/functions/find-all-active-speakers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as cors from 'cors';
import editionsService from '../../editions/business/services/editions.service';

import speakersService from '../business/services/speakers.service';

function checkOrigin(request, callback) {
const editionId = request.query.editionId;
const origin = request.header('Origin');

editionsService.findOne(editionId)
.then(edition => `https://${edition.url}` === origin ? callback(null, {origin: true}) : callback(null, {origin: false}))
.catch(err => {
console.error('checkOrigin', err);
callback(err, {origin: false});
});
}

export default (request, response) => {
cors(checkOrigin)(request, response, () => {
const editionId = request.query.editionId;
console.log('editionId', editionId);

if (editionId === undefined) {
response.status(400).send({message: 'Required editionId field in the request.'});
}

return editionsService.findOne(editionId)
.then(() => speakersService.findAllActiveByEditionId(editionId))
.then(speakers => {
const limitedSpeakers = {};

Object.keys(speakers).forEach(key => {
limitedSpeakers[key] = {
displayName: speakers[key].displayName,
photoURL: speakers[key].photoURL,
company: speakers[key].company,
bio: speakers[key].bio,
github: speakers[key].github,
twitter: speakers[key].twitter
};
});

return limitedSpeakers;
})
.then(speakers => response.send(speakers))
.catch(err => response.status(500).send({message: err.message}));
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as functions from 'firebase-functions';
import editionsService from '../../editions/business/services/editions.service';

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

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.findOneOnConferenceHall(edition.conferenceHall.eventId, edition.conferenceHall.apiKey))
.then(edition => {
return {speakers: edition.speakers};
});
};

0 comments on commit 8a72b87

Please sign in to comment.