Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function audienceIdUsed(audienceId) {
- // Bucket to hold audience ids
- var audienceIds = [];
- // Get all the organizations
- var organizations = await OrganizationModel.getOrganizations();
- // For each organization...
- for (var organization of organizations) {
- // For each contact type ("call", "text", or "chat")...
- for (var contactType of contactTypes) {
- // Grab the array of contacts
- var contacts = organization.contacts[contactType];
- if (contacts) {
- // For each contact object...
- for (var contact of contacts) {
- // Grab the audiences array
- var audiences = contact.audiences;
- if (audiences) {
- // Convert audience elements to strings and add to bucket
- audienceIds = audienceIds.concat(
- audiences.map(audienceId => audienceId.toString())
- );
- }
- }
- }
- }
- }
- // Remove duplicates from bucket
- audienceIds = Array.from(new Set(audienceIds));
- if (audienceIds.includes(audienceId)) {
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment