feat: Add find by client_id and companyId
parent
64869abc23
commit
1bdc545b4f
|
@ -75,9 +75,10 @@ const deleteCompany = async (req, res) => {
|
||||||
|
|
||||||
const callJournaling = async (req, res) => {
|
const callJournaling = async (req, res) => {
|
||||||
|
|
||||||
|
try {
|
||||||
let { companyId, operation, crmPhone, crmAgent, crmCallDuration, crmFirstName, operationStatus } = req.body
|
let { companyId, operation, crmPhone, crmAgent, crmCallDuration, crmFirstName, operationStatus } = req.body
|
||||||
|
|
||||||
console.log('REQ.BODY CRM TESTe: ', JSON.stringify(req.body, null, 6))
|
// console.log('REQ.BODY CRM TESTe: ', JSON.stringify(req.body, null, 6))
|
||||||
|
|
||||||
|
|
||||||
// test remove
|
// test remove
|
||||||
|
@ -118,11 +119,16 @@ const callJournaling = async (req, res) => {
|
||||||
await ticketCRM(companyId, crmPhone, crmAgent, crmFirstName)
|
await ticketCRM(companyId, crmPhone, crmAgent, crmFirstName)
|
||||||
|
|
||||||
const resp = await redirectContactLinkCRM(companyId, crmPhone, crmAgent, crmFirstName)
|
const resp = await redirectContactLinkCRM(companyId, crmPhone, crmAgent, crmFirstName)
|
||||||
|
|
||||||
return res.status(StatusCodes.OK).json({ contact: resp })
|
return res.status(StatusCodes.OK).json({ contact: resp })
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(StatusCodes.OK).send()
|
res.status(StatusCodes.OK).send()
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`[ERROR - ${new Date()}] Erro no Call Journaling`, error?.response?.data)
|
||||||
|
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,7 +164,7 @@ const install = async (req, res) => {
|
||||||
console.log('--------> authUrl: ', authUrl)
|
console.log('--------> authUrl: ', authUrl)
|
||||||
|
|
||||||
// Store the authUrl in the session
|
// Store the authUrl in the session
|
||||||
req.session.authUrl = authUrl
|
req.session.authUrl = authUrl + `&companyId=${companyId}`
|
||||||
|
|
||||||
res.redirect(authUrl)
|
res.redirect(authUrl)
|
||||||
}
|
}
|
||||||
|
@ -174,9 +180,13 @@ const oauthCallBack = async (req, res) => {
|
||||||
|
|
||||||
const parsedUrl = new URL(storedAuthUrl)
|
const parsedUrl = new URL(storedAuthUrl)
|
||||||
const clientId = parsedUrl.searchParams.get('client_id')
|
const clientId = parsedUrl.searchParams.get('client_id')
|
||||||
|
const companyId = parsedUrl.searchParams.get('companyId')
|
||||||
|
|
||||||
|
console.log('xxxxxxxxxx clientId: ', clientId)
|
||||||
|
console.log('xxxxxxxxxx companyId: ', companyId)
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
let crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId })
|
let crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, 'companyId': companyId })
|
||||||
crmOauth = crmOauth.toObject()
|
crmOauth = crmOauth.toObject()
|
||||||
|
|
||||||
let authCodeProof = {
|
let authCodeProof = {
|
||||||
|
@ -213,7 +223,7 @@ const oauthCallBack = async (req, res) => {
|
||||||
// Exchange the authorization code for an access token and refresh token
|
// Exchange the authorization code for an access token and refresh token
|
||||||
await exchangeForTokens(crmOauth, authCodeProof)
|
await exchangeForTokens(crmOauth, authCodeProof)
|
||||||
|
|
||||||
const url = `${process.env.URL_OAUTH_FRONTEND_SUCCESS_REDIRECT}?clientId=${encodeURIComponent(clientId)}`
|
const url = `${process.env.URL_OAUTH_FRONTEND_SUCCESS_REDIRECT}?clientId=${encodeURIComponent(clientId)}&codWeb=${companyId}`
|
||||||
|
|
||||||
return res.redirect(url)
|
return res.redirect(url)
|
||||||
// return res.redirect(process.env.URL_OAUTH_FRONTEND_SUCCESS_REDIRECT)
|
// return res.redirect(process.env.URL_OAUTH_FRONTEND_SUCCESS_REDIRECT)
|
||||||
|
@ -226,7 +236,7 @@ const testTemplate = async (req, res) => {
|
||||||
|
|
||||||
const { clientId, companyId } = req.body
|
const { clientId, companyId } = req.body
|
||||||
|
|
||||||
let crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, testing: true })
|
let crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, 'companyId': companyId, testing: true })
|
||||||
|
|
||||||
if (!crmOauth)
|
if (!crmOauth)
|
||||||
return res.status(StatusCodes.OK).send()
|
return res.status(StatusCodes.OK).send()
|
||||||
|
@ -236,7 +246,7 @@ const testTemplate = async (req, res) => {
|
||||||
const { crmPhoneTest } = crmOauth.crm.authentication
|
const { crmPhoneTest } = crmOauth.crm.authentication
|
||||||
await templateValidator(crmPhoneTest, crmOauth.crm, companyId)
|
await templateValidator(crmPhoneTest, crmOauth.crm, companyId)
|
||||||
|
|
||||||
crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId })
|
crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, 'companyId': companyId })
|
||||||
crmOauth.testing = false
|
crmOauth.testing = false
|
||||||
await crmOauth.save()
|
await crmOauth.save()
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,29 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
||||||
sendMessageSocket({ companyId, status: 'processing', data: { request: config, msg } })
|
sendMessageSocket({ companyId, status: 'processing', data: { request: config, msg } })
|
||||||
}
|
}
|
||||||
|
|
||||||
let { data } = await axios(config)
|
let data
|
||||||
|
|
||||||
|
try {
|
||||||
|
let { data: _data } = await axios(config)
|
||||||
|
data = _data
|
||||||
|
} catch (error) {
|
||||||
|
if (error.response) {
|
||||||
|
console.error('==================> Erro na resposta da API:', {
|
||||||
|
status: error.response.status,
|
||||||
|
data: error.response.data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (error.request) {
|
||||||
|
console.error('==================> Nenhuma resposta recebida da API:', error.request)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error('==================> Erro ao configurar a request:', error.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log('DATA: ', JSON.stringify(data, null, 6))
|
console.log('DATA: ', JSON.stringify(data, null, 6))
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,35 @@ const exchangeForTokens = async (crmOauth, exchangeProof) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('CONFIG: ', config)
|
console.log('======> CONFIG: ', config)
|
||||||
|
|
||||||
const { data } = await axios(config)
|
// const { data } = await axios(config)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//test
|
||||||
|
let data
|
||||||
|
try {
|
||||||
|
let { data: _data } = await axios(config)
|
||||||
|
data = _data
|
||||||
|
} catch (error) {
|
||||||
|
if (error.response) {
|
||||||
|
console.error('==================> oauth2 Erro na resposta da API:', {
|
||||||
|
status: error.response.status,
|
||||||
|
data: error.response.data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (error.request) {
|
||||||
|
console.error('==================> oauth2 Nenhuma resposta recebida da API:', error.request)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error('==================> oauth2 Erro ao configurar a request:', error.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
const { refresh_token, access_token, token_type, expires_in, issued_at } = data
|
const { refresh_token, access_token, token_type, expires_in, issued_at } = data
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ async function _lookupContact(rest, authentication, crmPhone, companyId, crmFirs
|
||||||
|
|
||||||
let contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
|
let contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
|
||||||
|
|
||||||
|
|
||||||
if (contact?.exist) {
|
if (contact?.exist) {
|
||||||
return { created: false, contactId: contact.contactId }
|
return { created: false, contactId: contact.contactId }
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,15 +41,19 @@ async function sfcase(companyId, crmPhone) {
|
||||||
|
|
||||||
let config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body)
|
let config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body)
|
||||||
|
|
||||||
|
console.log("====> config", config)
|
||||||
console.log("====> accountId: ", accountId, " | contactId: ", contactId)
|
console.log("====> accountId: ", accountId, " | contactId: ", contactId)
|
||||||
|
|
||||||
|
const complementarInformations = {
|
||||||
if (accountId && contactId)
|
|
||||||
config.data = {
|
|
||||||
...config.data, ...{
|
|
||||||
ContactId: contactId,
|
|
||||||
AccountId: accountId
|
AccountId: accountId
|
||||||
}
|
}
|
||||||
|
if (!config?.data?.ContactId && !config?.data?.ContactId === "") {
|
||||||
|
complementarInformations.ContactId = contactId
|
||||||
|
}
|
||||||
|
if (accountId && contactId)
|
||||||
|
config.data = {
|
||||||
|
...config.data,
|
||||||
|
...complementarInformations
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("====> create case request config: ", config)
|
console.log("====> create case request config: ", config)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"files": {
|
"files": {
|
||||||
"main.css": "/static/css/main.ae60ab08.css",
|
"main.css": "/static/css/main.ae60ab08.css",
|
||||||
"main.js": "/static/js/main.2166c932.js",
|
"main.js": "/static/js/main.b7e32f90.js",
|
||||||
"index.html": "/index.html",
|
"index.html": "/index.html",
|
||||||
"main.ae60ab08.css.map": "/static/css/main.ae60ab08.css.map",
|
"main.ae60ab08.css.map": "/static/css/main.ae60ab08.css.map",
|
||||||
"main.2166c932.js.map": "/static/js/main.2166c932.js.map"
|
"main.b7e32f90.js.map": "/static/js/main.b7e32f90.js.map"
|
||||||
},
|
},
|
||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"static/css/main.ae60ab08.css",
|
"static/css/main.ae60ab08.css",
|
||||||
"static/js/main.2166c932.js"
|
"static/js/main.b7e32f90.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.2166c932.js"></script><link href="/static/css/main.ae60ab08.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.b7e32f90.js"></script><link href="/static/css/main.ae60ab08.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -85,14 +85,16 @@ const UploadFile = () => {
|
||||||
setCodweb(codWebFromUrl)
|
setCodweb(codWebFromUrl)
|
||||||
|
|
||||||
console.log('clientId: ', clientId)
|
console.log('clientId: ', clientId)
|
||||||
|
console.log('codWebFromURl: ', codWebFromUrl)
|
||||||
|
console.log('codWeb: ', codWeb)
|
||||||
|
|
||||||
if (clientId && codWeb) {
|
if (clientId && codWebFromUrl) {
|
||||||
|
|
||||||
const postData = async () => {
|
const postData = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/test`, {
|
await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/test`, {
|
||||||
clientId,
|
clientId,
|
||||||
companyId: codWeb,
|
companyId: codWebFromUrl,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setStatus('error')
|
setStatus('error')
|
||||||
|
|
Loading…
Reference in New Issue