Skip to content

Commit

Permalink
Refactor imports and improve error handling in webhookProductProcess …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
jamalsoueidan committed Mar 12, 2024
1 parent 0c5c646 commit db63681
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/functions/webhook-product.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
InvocationContext,
output,
} from "@azure/functions";
import {
productUpdateSchema,
webhookProductProcess,
} from "./webhook/product/product";
import { webhookProductProcess } from "./webhook/product/product";
import { productUpdateSchema } from "./webhook/product/types";

export const productQueueName = "webhook-product";
export const productQueueOutput = output.storageQueue({
Expand Down
11 changes: 9 additions & 2 deletions src/functions/webhook/product/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InvocationContext } from "@azure/functions";
import { telemetryClient } from "~/library/application-insight";
import { connect } from "~/library/mongoose";
import { shopifyAdmin } from "~/library/shopify";
import { ProductVariantCreateMutation } from "~/types/admin.generated";
import { ProductUpdateSchema } from "./types";
import { ProductWebHookGetUnusedVariantIds } from "./unused";

Expand All @@ -17,7 +18,7 @@ export async function webhookProductProcess(
product,
});

const response = await shopifyAdmin.query({
const { body } = await shopifyAdmin.query<ProductVariantCreateMutation>({
data: {
query: MUTATION_DESTROY_VARIANTS,
variables: {
Expand All @@ -29,7 +30,13 @@ export async function webhookProductProcess(
},
});

console.log(response);
if (!body.productVariantCreate?.product) {
context.error(
"webhook product error",
body.productVariantCreate?.userErrors
);
}

context.log("webhook product success");
} catch (exception: unknown) {
console.log(exception);
Expand Down

0 comments on commit db63681

Please sign in to comment.