Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty contact created from netsuite #34

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/adapters/netsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
const personInfo = await axios.post(
`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql`,
{
q: `SELECT id,firstname,middlename,lastname FROM contact WHERE phone = ${numberToQuery} OR homePhone = ${numberToQuery} OR mobilePhone = ${numberToQuery} OR officePhone = ${numberToQuery}`
q: `SELECT * FROM contact WHERE phone = ${numberToQuery} OR homePhone = ${numberToQuery} OR mobilePhone = ${numberToQuery} OR officePhone = ${numberToQuery}`
},
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json', 'Prefer': 'transient' }
Expand All @@ -123,9 +123,10 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
let firstName = result.firstname ?? '';
let middleName = result.middlename ?? '';
let lastName = result.lastname ?? '';
const contactName = (firstName + middleName + lastName).length > 0 ? `${firstName} ${middleName} ${lastName}` : result.entitytitle;
matchedContactInfo.push({
id: result.id,
name: `${firstName} ${middleName} ${lastName}`,
name: contactName,
phone: numberToQuery,
additionalInfo: null,
type: 'contact'
Expand All @@ -136,7 +137,7 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
const customerInfo = await axios.post(
`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql`,
{
q: `SELECT id,firstname,middlename,lastname FROM customer WHERE phone = ${numberToQuery} OR homePhone = ${numberToQuery} OR mobilePhone = ${numberToQuery} OR altPhone = ${numberToQuery}`
q: `SELECT * FROM customer WHERE phone = ${numberToQuery} OR homePhone = ${numberToQuery} OR mobilePhone = ${numberToQuery} OR altPhone = ${numberToQuery}`
},
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json', 'Prefer': 'transient' }
Expand All @@ -147,9 +148,10 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
let firstName = result.firstname ?? '';
let middleName = result.middlename ?? '';
let lastName = result.lastname ?? '';
const customerName = (firstName + middleName + lastName).length > 0 ? `${firstName} ${middleName} ${lastName}` : result.entitytitle;
matchedContactInfo.push({
id: result.id,
name: `${firstName} ${middleName} ${lastName}`,
name: customerName,
phone: numberToQuery,
additionalInfo: null,
type: 'custjob'
Expand Down Expand Up @@ -489,7 +491,7 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
returnMessage: {
message: `Error in creating Contact.`,
messageType: 'danger',
ttl: 3000
ttl: 5000
}
}
}
Expand Down Expand Up @@ -522,7 +524,7 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
returnMessage: {
message: `Error in creating Customer.`,
messageType: 'danger',
ttl: 3000
ttl: 5000
}
}
}
Expand All @@ -536,7 +538,7 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
returnMessage: {
message: `New contact created.`,
messageType: 'success',
ttl: 3000
ttl: 5000
}
}
}
Expand Down
Loading