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

Commit

Permalink
✨ add room filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
François GRUCHALA committed Apr 22, 2019
1 parent aeae3b6 commit 39c0b16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 16 additions & 1 deletion functions/src/talks/business/services/talks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ import * as admin from 'firebase-admin';

class TalksService {

public findAllActiveByEditionId(editionId: string): Promise<any> {
public findAllActiveByEditionId(editionId: string, roomId?: string): Promise<any> {
return admin.firestore()
.collection('talks')
.where('edition', '==', editionId)
.orderBy('hour', 'asc')
.get()
.then(query => {
const talks = {};
query.forEach(doc => talks[doc.id] = doc.data());
return talks;
})
.then(talks => {
if (roomId) {
const filteredTalks = {};
Object.keys(talks).forEach(talkId => {
if(talks[talkId].room === roomId) {
filteredTalks[talkId] = talks[talkId];
}
});

return filteredTalks;
}

return talks;
});
}
Expand Down
5 changes: 3 additions & 2 deletions functions/src/talks/functions/find-all-active-talks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import editionsService from '../../editions/business/services/editions.service';
import speakersService from '../../speakers/business/services/speakers.service';

import talksService from '../business/services/talks.service';
import * as moment from 'moment';

function disableCors(request, callback) {
callback(null, true);
Expand All @@ -12,14 +11,16 @@ function disableCors(request, callback) {
export default (request, response) => {
cors(disableCors)(request, response, () => {
const editionId = request.query.editionId;
const roomId = request.query.roomId;
console.log('editionId', editionId);
console.log('roomId', roomId);

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

return editionsService.findOne(editionId)
.then(() => Promise.all([talksService.findAllActiveByEditionId(editionId), speakersService.findAllActiveByEditionId(editionId)]))
.then(() => Promise.all([talksService.findAllActiveByEditionId(editionId, roomId), speakersService.findAllActiveByEditionId(editionId)]))
.then(datas => {
const limitedTalks = {};

Expand Down

0 comments on commit 39c0b16

Please sign in to comment.