Permalink
Browse files

Step 15.14: Add a new response counting pipe

  • Loading branch information...
1 parent 2280cb4 commit 28daf75d898bfd7b7bbd8069fcf91c00293374cb @dotansimha dotansimha committed with DAB0mB Sep 27, 2016
Showing with 22 additions and 0 deletions.
  1. +22 −0 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.