Created
January 29, 2022 04:07
-
-
Save calebcauthon/24a0db1dc37b144742f9eaf627657335 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { contacts } from 'wix-crm-backend'; | |
import wixPricingPlansBackend from 'wix-pricing-plans-backend'; | |
export function listPlans() { | |
return wixPricingPlansBackend.listPlans() | |
.then((plans) => { | |
// Array of all the specified pricing plan objects that match the criteria | |
console.log(plans); | |
}) | |
.catch((error) => { | |
console.error(error); | |
}); | |
} | |
export function findPlans() { | |
return contacts.queryLabels() | |
.ascending("_createdDate") | |
.limit(5) | |
.find() | |
.then((results) => { | |
return results.items; | |
}); | |
} | |
let options = { | |
suppressAuth: true | |
} | |
export async function getContacts() { | |
let contactsArr = [] | |
return contacts.queryContacts() | |
.eq('info.labelKeys', "custom.paid-subscriber").or(contacts.queryContacts().eq('info.labelKeys', "custom.prp-club-membership").or(contacts.queryContacts().eq("info.labelKeys", "custom.2020-new-memberships").or(contacts.queryContacts().eq("info.labelKeys", "custom.2020-renewal-memberships")))) | |
.limit(1000) | |
.find(options) | |
.then((results) => { | |
console.log(results.items[0]) | |
let items = results.items | |
contactsArr = items.map(item => item); | |
results.items.forEach((contact) => { | |
contact.info.labelKeys.forEach((label) => { | |
if(label === "custom.expired" || label === "custom.cancelled"){ | |
contactsArr = contactsArr.filter((item) => item._id !== contact._id) | |
} | |
}) | |
}) | |
return contactsArr; | |
}) | |
} | |
//.not(contacts.queryContacts().eq("info.labelKeys", "custom.cancelled").or(contacts.queryContacts().eq("info.labelKeys", "custom.expired"))) | |
//contacts.queryContacts().eq('info.labelKeys', "custom.prp-club-membership").or(contacts.queryContacts().eq("info.labelKeys", "custom.2020-new-memberships").or(contacts.queryContacts().eq("info.labelKeys", "custom.2020-renewal-memberships").or(contacts.queryContacts().eq("info.labelKeys", "custom.one-time-payment")))) | |
export function fillTable(contacts) { | |
let data = [] | |
contacts.forEach((contact) => { | |
let name = "Name: " + contact.info.name.first + " " + contact.info.name.last | |
let email = "Email: " + contact.primaryInfo.email | |
let phone = "Phone: " + contact.primaryInfo.phone | |
let id = contact._id | |
data.push( { | |
_id: id, | |
name: name, | |
email: email, | |
phone: phone | |
}) | |
}) | |
return data | |
} | |
export function buildDataset(contacts) { | |
let data = [] | |
contacts.forEach((contact) => { | |
let name = contact.info.name.first + " " + contact.info.name.last | |
let email = contact.primaryInfo.email | |
let phone = contact.primaryInfo.phone | |
let id = contact._id | |
data.push( { | |
_id: id, | |
name: name, | |
email: email, | |
phone: phone | |
}) | |
}) | |
return data | |
} | |
export function unlabelContact(contactInfo) { | |
console.log(contactInfo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment