This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from GDG-Lille/develop
Develop
- Loading branch information
Showing
11 changed files
with
936 additions
and
1,780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,5 @@ node_modules/ | |
|
||
# dotenv environment variables file | ||
.env | ||
|
||
.idea |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ export default (snap, context) => { | |
}; | ||
|
||
// TODO call Manu soft | ||
}; | ||
}; |
19 changes: 19 additions & 0 deletions
19
functions/src/speakers/business/services/speakers.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
functions/src/speakers/functions/find-all-active-speakers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})); | ||
}); | ||
}; |
21 changes: 21 additions & 0 deletions
21
functions/src/speakers/functions/find-all-speakers-from-conference-hall.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
}); | ||
}; |