26 lines
704 B
JavaScript
26 lines
704 B
JavaScript
const lookupContactByPhone = require('./lookupCRMContactByPhone')
|
|
const createContact = require('./createContact')
|
|
const loadCRM = require('./loadCRM')
|
|
|
|
async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = '', crmLastName = '',) {
|
|
|
|
const crmFiles = await loadCRM(companyId)
|
|
|
|
for (const crmConfig of crmFiles) {
|
|
|
|
const { crmRest: rest, authentication } = crmConfig.crm
|
|
|
|
const contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
|
|
|
|
if (contact.exist) continue
|
|
|
|
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail,)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = createCRMContact
|
|
|
|
|