feat: adjustment to create contact via omnihit for SAP crm
parent
ebe4f901f7
commit
9db7604b93
|
|
@ -19,11 +19,12 @@
|
|||
"body":{
|
||||
"LastName":"crmLastName",
|
||||
"FirstName":"crmFirstName",
|
||||
"Mobile":"crmPhone",
|
||||
"Mobile":"+crmPhone",
|
||||
"AccountID":"1000320"
|
||||
},
|
||||
"response":{
|
||||
"id":"d.results.ContactID"
|
||||
"id":"d.results.ContactID",
|
||||
"objectId":"d.results.ObjectID"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -191,8 +191,8 @@ const callJournaling = async (req, res) => {
|
|||
// return res.status(StatusCodes.OK).send()
|
||||
|
||||
// Refactor this in the future. Integração Gradezco colombia, o crm sap precisa criar o contato com o + no inicio seguido do codigo do pais
|
||||
if(companyId == "4953"){ // companyId de test para colombia
|
||||
crmPhone = '+57' + crmPhone
|
||||
if(companyId == "4953"){ // companyId da gradezco colombia
|
||||
crmPhone = '57' + crmPhone
|
||||
}
|
||||
else{
|
||||
crmPhone = '55' + crmPhone
|
||||
|
|
|
|||
|
|
@ -26,8 +26,17 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
|
|||
}
|
||||
|
||||
for (const prop in body) {
|
||||
|
||||
// Para o crm SAP que precisa do +57 no inicio do contato para ser criado corretamente
|
||||
if(body[prop].includes("+crmPhone")){
|
||||
body[prop] = `+${crmPhone}`
|
||||
continue
|
||||
}
|
||||
|
||||
if (mapping.hasOwnProperty(body[prop])) {
|
||||
|
||||
const variable = mapping[body[prop]]
|
||||
|
||||
if (variable) {
|
||||
body[prop] = variable
|
||||
} else {
|
||||
|
|
@ -91,6 +100,7 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
|
|||
data = flatten(data)
|
||||
|
||||
let auxContactId
|
||||
let auxContactId2
|
||||
|
||||
for (const prop in data) {
|
||||
|
||||
|
|
@ -98,10 +108,14 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
|
|||
|
||||
if (_prop == response?.id?.trim()) {
|
||||
auxContactId = data[prop]
|
||||
break
|
||||
}
|
||||
|
||||
if (_prop == response?.objectId?.trim()) {
|
||||
auxContactId2 = data[prop]
|
||||
}
|
||||
}
|
||||
|
||||
console.log('---------> createContact crmPhone: ', crmPhone, ' | auxContactId: ', auxContactId, ' | auxContactId2: ', auxContactId2)
|
||||
|
||||
if (auxContactId && !test?.testing && crmEmail=='') {
|
||||
|
||||
|
|
@ -110,7 +124,7 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
|
|||
await CRM_Contact.create({ companyId, crm, crmBaseURL: new URL(url).hostname, contactId: auxContactId, phone: crmPhone })
|
||||
}
|
||||
|
||||
return { exist: true, contactId: auxContactId, phone: crmPhone }
|
||||
return { exist: true, contactId: auxContactId, phone: crmPhone, contactId2: auxContactId2}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,15 @@ async function journalingRequest(request, body, crmCallDuration, contact, crmAge
|
|||
let { requestContentType, requestEncoding, requestType, responseType, url } = request
|
||||
|
||||
console.log('----------> crmCallDuration: ', crmCallDuration)
|
||||
console.log('----------> url 1: ', url)
|
||||
console.log('----------> journalingRequest url 1: ', url)
|
||||
|
||||
// Second contactId for some cases like SAP crm
|
||||
// Second contactId for some cases like SAP crm that use ObjectID to create note
|
||||
if(url.includes("contactObjectId") && contact?.contactId2){
|
||||
url = url.replace("contactObjectId", contact.contactId2)
|
||||
}
|
||||
|
||||
console.log('----------> journalingRequest url 2: ', url)
|
||||
|
||||
body = flatten(body)
|
||||
|
||||
let ignore = []
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ async function _lookupContact(rest, authentication, crmPhone, crmEmail, companyI
|
|||
// Se o contato for criado, retorna suas informações
|
||||
if (contact?.contactId) {
|
||||
console.log(`Novo contato criado com ID: ${contact.contactId}`);
|
||||
return { created: true, contactId: contact.contactId };
|
||||
return { created: true, contactId: contact.contactId, contactId2: contact?.contactId2};
|
||||
}
|
||||
|
||||
// Caso não tenha nem telefone nem e-mail, retorna um erro ou um valor nulo
|
||||
|
|
|
|||
Loading…
Reference in New Issue