Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafidMuhymin committed Jan 15, 2024
2 parents efdb75b + f2b4fdd commit dbfe5a6
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions src/workers/dilmahtea-me-exact-account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ async function handlePOST(request: Request, env: ENV) {
const { userId, Email, Phone, FirstName, LastName, Language, Address } =
await request.json<Body>();

if (!userId) {
handlePOST.retry = false;
handlePOST.catchError = true;
}

const Name = `${FirstName} ${LastName}`,
CustomerData = {
userId,
Expand All @@ -44,40 +49,28 @@ async function handlePOST(request: Request, env: ENV) {

const CustomerFilter = getCustomerFilter(Email || Phone, !!Email);

try {
var Customer = await fetchExactAPI(
"GET",
`/CRM/Accounts?$filter=${getCustomerFilter(
Email || Phone,
!!Email,
)}&$select=ID,Name,Language,Email,Phone,Country,LeadSource,Classification1`,
).then((Customer) => {
console.log({
ExistingCustomer: Customer,
});

return Customer.feed.entry?.content["m:properties"];
let Customer = await fetchExactAPI(
"GET",
`/CRM/Accounts?$filter=${getCustomerFilter(
Email || Phone,
!!Email,
)}&$select=ID,Name,Language,Email,Phone,Country,LeadSource,Classification1`,
).then((Customer) => {
console.log({
ExistingCustomer: Customer,
});

if (Customer) {
console.log("Exact: Customer exists");

await updateCustomer(
auth,
CustomerData,
Customer,
CustomerFilter,
userId,
);
} else {
Customer = await createCustomer(CustomerData);

console.log("Exact: Customer created successfully");
}
} catch (error) {
if (userId) throw error;

return reply({ success: false, error: error.message }, 500);
return Customer.feed.entry?.content["m:properties"];
});

if (Customer) {
console.log("Exact: Customer exists");

await updateCustomer(auth, CustomerData, Customer, CustomerFilter, userId);
} else {
Customer = await createCustomer(CustomerData);

console.log("Exact: Customer created successfully");
}

if (userId) {
Expand Down

0 comments on commit dbfe5a6

Please sign in to comment.