Skip to content

Commit

Permalink
Add retrieval and update of product collections in update-product or…
Browse files Browse the repository at this point in the history
…chestration
  • Loading branch information
jamalsoueidan committed Jun 29, 2024
1 parent 3585bf5 commit e54a46e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { faker } from "@faker-js/faker";
import { CustomerProductServiceGet } from "~/functions/customer/services/product/get";
import { OpenAIServiceProductCategorize } from "~/functions/openai/services/product-categorize";
import { TimeUnit } from "~/functions/schedule";
import { createUser } from "~/library/jest/helpers";
Expand Down Expand Up @@ -231,6 +232,13 @@ describe("CustomerProductUpdateOrchestration", () => {
productId: product.productId,
});

const updatedProduct = await CustomerProductServiceGet({
customerId,
productId: product.productId,
});

expect(updatedProduct.collectionIds).toHaveLength(2);

const tags = [
`user`,
`user-${user.username}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CustomerServiceGet } from "~/functions/customer/services/customer/get";
import { CustomerProductServiceGet } from "~/functions/customer/services/product/get";
import { LocationModel } from "~/functions/location";
import { OpenAIServiceProductCategorize } from "~/functions/openai/services/product-categorize";
import { ScheduleModel } from "~/functions/schedule";
Expand Down Expand Up @@ -98,6 +99,29 @@ export const updateProduct = async ({
tags.push(r.condition);
});
});

const { scheduleId, scheduleMetafieldId, scheduleName, ...oldProduct } =
await CustomerProductServiceGet({
customerId,
productId,
});

await ScheduleModel.updateOne(
{
customerId,
"products.productId": productId,
},
{
$set: {
"products.$": {
...oldProduct,
collectionIds:
categories?.map((c) => GidFormat.parse(c.id)) ||
oldProduct.collectionIds,
},
},
}
);
}

const variables = {
Expand Down

0 comments on commit e54a46e

Please sign in to comment.