NovaKevin

LifeLiner - audienceIdUsed

May 16th, 2018
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function audienceIdUsed(audienceId) {
  2.     // Bucket to hold audience ids
  3.     var audienceIds = [];
  4.     // Get all the organizations
  5.     var organizations = await OrganizationModel.getOrganizations();
  6.     // For each organization...
  7.     for (var organization of organizations) {
  8.         // For each contact type ("call", "text", or "chat")...
  9.         for (var contactType of contactTypes) {
  10.             // Grab the array of contacts
  11.             var contacts = organization.contacts[contactType];
  12.             if (contacts) {
  13.                 // For each contact object...
  14.                 for (var contact of contacts) {
  15.                     // Grab the audiences array
  16.                     var audiences = contact.audiences;
  17.                     if (audiences) {
  18.                         // Convert audience elements to strings and add to bucket
  19.                         audienceIds = audienceIds.concat(
  20.                             audiences.map(audienceId => audienceId.toString())
  21.                         );
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.     }
  27.     // Remove duplicates from bucket
  28.     audienceIds = Array.from(new Set(audienceIds));
  29.  
  30.     if (audienceIds.includes(audienceId)) {
  31.         return true;
  32.     } else {
  33.         return false;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment