Skip to content

Commit

Permalink
Step 15.14: Add a new response counting pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Dec 14, 2016
1 parent 2280cb4 commit 28daf75
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions client/imports/app/shared/rsvp.pipe.ts
@@ -0,0 +1,22 @@
import {Pipe, PipeTransform} from '@angular/core';
import {Party} from "../../../../both/models/party.model";
import {Parties} from "../../../../both/collections/parties.collection";

@Pipe({
name: 'rsvp'
})
export class RsvpPipe implements PipeTransform {
transform(party: Party, type: string): number {
if (!type) {
return 0;
}

let total = 0;
const found = Parties.findOne(party._id);

if (found)
total = found.rsvps ? found.rsvps.filter(rsvp => rsvp.response === type).length : 0;

return total;
}
}

0 comments on commit 28daf75

Please sign in to comment.