feat: added dynamic body request to create lead/contact
parent
61783eecf6
commit
f2814269ac
|
@ -36,11 +36,11 @@ const getSalesforceUser = require('../utils/getSalesforceUser')
|
||||||
|
|
||||||
const contactCreate = async (req, res) => {
|
const contactCreate = async (req, res) => {
|
||||||
|
|
||||||
const { companyId, crmFirstName, crmLastName, crmPhone, crmEmail } = req.body
|
const { companyId, crmFirstName, crmLastName, crmPhone, crmEmail, dynamicBodyRequest } = req.body
|
||||||
|
|
||||||
mustContainProperties(req, ['companyId', 'crmPhone',])
|
mustContainProperties(req, ['companyId', 'crmPhone',])
|
||||||
|
|
||||||
await createCRMContact(companyId, crmFirstName, crmPhone, crmEmail, crmLastName)
|
await createCRMContact(companyId, crmFirstName, crmPhone, crmEmail, crmLastName, dynamicBodyRequest)
|
||||||
|
|
||||||
res.status(StatusCodes.OK).send()
|
res.status(StatusCodes.OK).send()
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const lookupContactByPhone = require('./lookupCRMContactByPhone')
|
||||||
const createContact = require('./createContact')
|
const createContact = require('./createContact')
|
||||||
const loadCRM = require('./loadCRM')
|
const loadCRM = require('./loadCRM')
|
||||||
|
|
||||||
async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = '', crmLastName = '',) {
|
async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = '', crmLastName = '', dynamicBodyRequest = {}) {
|
||||||
|
|
||||||
const crmFiles = await loadCRM(companyId)
|
const crmFiles = await loadCRM(companyId)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = ''
|
||||||
|
|
||||||
if (contact.exist) continue
|
if (contact.exist) continue
|
||||||
|
|
||||||
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail,)
|
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail, {}, dynamicBodyRequest)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ const CRM = require('../models/CRM')
|
||||||
const requestConfigHeader = require('./requestConfigHeader')
|
const requestConfigHeader = require('./requestConfigHeader')
|
||||||
const sendMessageSocket = require('./sendMessageSocket')
|
const sendMessageSocket = require('./sendMessageSocket')
|
||||||
|
|
||||||
async function createContact(companyId, rest, authentication, crmPhone, crmFirstName = 'Username', crmLastName = 'Last name', crmEmail = '', test = {}) {
|
async function createContact(companyId, rest, authentication, crmPhone, crmFirstName = 'Username', crmLastName = 'Last name', crmEmail = '', test = {}, dynamicBodyRequest = {}) {
|
||||||
let { request, body, response } = findProperty(rest, 'createContactRecord')
|
let { request, body, response } = findProperty(rest, 'createContactRecord')
|
||||||
|
|
||||||
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
||||||
|
@ -42,7 +42,7 @@ async function createContact(companyId, rest, authentication, crmPhone, crmFirst
|
||||||
const { type, userName, passWord, token, crmClientId } = authentication
|
const { type, userName, passWord, token, crmClientId } = authentication
|
||||||
|
|
||||||
//url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, data = '', ticketId = '', companyId
|
//url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, data = '', ticketId = '', companyId
|
||||||
const config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body, '', companyId)
|
let config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body, '', companyId)
|
||||||
|
|
||||||
if (test?.testing) {
|
if (test?.testing) {
|
||||||
msg = `Tentanto criar contato de numero ${crmPhone} no crm`
|
msg = `Tentanto criar contato de numero ${crmPhone} no crm`
|
||||||
|
@ -53,6 +53,13 @@ async function createContact(companyId, rest, authentication, crmPhone, crmFirst
|
||||||
console.log('CREATE CONTACT PAYLOAD: ', JSON.stringify(config, null, 6))
|
console.log('CREATE CONTACT PAYLOAD: ', JSON.stringify(config, null, 6))
|
||||||
console.log('#####################')
|
console.log('#####################')
|
||||||
|
|
||||||
|
if (dynamicBodyRequest && Object.keys(dynamicBodyRequest) !== 0) {
|
||||||
|
config.data = { ...config.data, ...dynamicBodyRequest }
|
||||||
|
console.log('#####################')
|
||||||
|
console.log('CREATE CONTACT PAYLOAD UPDATED BY DYNAMIC BODY REQUEST: ', JSON.stringify(config, null, 6))
|
||||||
|
console.log('#####################')
|
||||||
|
}
|
||||||
|
|
||||||
let data
|
let data
|
||||||
try {
|
try {
|
||||||
let { data: _data } = await axios(config)
|
let { data: _data } = await axios(config)
|
||||||
|
|
Loading…
Reference in New Issue