Skip to content

Commit

Permalink
updated contact matching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RafidMuhymin committed Jan 6, 2024
1 parent 43d6026 commit fed10cc
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,16 @@ export default async function updateCustomer(customer, existingCustomer) {

const contact = await fetchExactAPI(
"GET",
`/CRM/Contacts?$filter=Email eq '${customer.Email}'&select=ID,FirstName,LastName`,
`/CRM/Contacts?$filter=Account eq guid'${ExistingCustomer["d:ID"]}' and Email eq '${customer.Email}'&select=ID,FirstName,LastName`,
).then(async ({ feed }) => {
const matchedContact = [feed.entry]
.flat()
.filter(Boolean)
.find(
({ content: { "m:properties": props } }) =>
[customer.FirstName, ExistingCustomer["d:FirstName"]].includes(
props["d:FirstName"],
) &&
[customer.LastName, ExistingCustomer["d:LastName"]].includes(
props["d:LastName"],
),
)?.content["m:properties"];
.find(({ content: { "m:properties": props } }) => {
return [customer.Name, ExistingCustomer["d:Name"]].includes(
props["d:FirstName"] + " " + props["d:LastName"],
);
})?.content["m:properties"];

if (matchedContact) {
promises.push(updateContact(customer, matchedContact));
Expand Down

0 comments on commit fed10cc

Please sign in to comment.