浏览代码

chore: Update seed script

olivermrbl 1 年之前
父节点
当前提交
728927aebb
共有 2 个文件被更改,包括 376 次插入350 次删除
  1. 48 40
      src/scripts/seed.ts
  2. 328 310
      yarn.lock

+ 48 - 40
src/scripts/seed.ts

@@ -18,7 +18,7 @@ import {
   ExecArgs,
   ExecArgs,
   IFulfillmentModuleService,
   IFulfillmentModuleService,
   ISalesChannelModuleService,
   ISalesChannelModuleService,
-  IStoreModuleService
+  IStoreModuleService,
 } from "@medusajs/types";
 } from "@medusajs/types";
 import {
 import {
   ContainerRegistrationKeys,
   ContainerRegistrationKeys,
@@ -43,8 +43,8 @@ export default async function seedDemoData({ container }: ExecArgs) {
   const countries = ["gb", "de", "dk", "se", "fr", "es", "it"];
   const countries = ["gb", "de", "dk", "se", "fr", "es", "it"];
 
 
   logger.info("Seeding store data...");
   logger.info("Seeding store data...");
-  const [store] = await storeModuleService.list();
-  let defaultSalesChannel = await salesChannelModuleService.list({
+  const [store] = await storeModuleService.listStores();
+  let defaultSalesChannel = await salesChannelModuleService.listSalesChannels({
     name: "Default Sales Channel",
     name: "Default Sales Channel",
   });
   });
 
 
@@ -74,20 +74,18 @@ export default async function seedDemoData({ container }: ExecArgs) {
     },
     },
   });
   });
   logger.info("Seeding region data...");
   logger.info("Seeding region data...");
-  const { result: regionResult } = await createRegionsWorkflow(container).run(
-    {
-      input: {
-        regions: [
-          {
-            name: "Europe",
-            currency_code: "eur",
-            countries,
-            payment_providers: ["pp_system_default"],
-          },
-        ],
-      },
-    }
-  );
+  const { result: regionResult } = await createRegionsWorkflow(container).run({
+    input: {
+      regions: [
+        {
+          name: "Europe",
+          currency_code: "eur",
+          countries,
+          payment_providers: ["pp_system_default"],
+        },
+      ],
+    },
+  });
   const region = regionResult[0];
   const region = regionResult[0];
   logger.info("Finished seeding regions.");
   logger.info("Finished seeding regions.");
 
 
@@ -113,7 +111,7 @@ export default async function seedDemoData({ container }: ExecArgs) {
     });
     });
   const shippingProfile = shippingProfileResult[0];
   const shippingProfile = shippingProfileResult[0];
 
 
-  const fulfillmentSet = await fulfillmentModuleService.create({
+  const fulfillmentSet = await fulfillmentModuleService.createFulfillmentSets({
     name: "European Warehouse delivery",
     name: "European Warehouse delivery",
     type: "delivery",
     type: "delivery",
     service_zones: [
     service_zones: [
@@ -296,32 +294,40 @@ export default async function seedDemoData({ container }: ExecArgs) {
   logger.info("Finished seeding publishable API key data.");
   logger.info("Finished seeding publishable API key data.");
 
 
   logger.info("Seeding product data...");
   logger.info("Seeding product data...");
-  const categories = {
-    Shirts: "",
-    Sweatshirts: "",
-    Pants: "",
-    Merch: "",
-  }
-  for (const category in categories) {
-    const { result: categoryResult } = await createProductCategoriesWorkflow(
-      container
-    ).run({
-      input: {
-        product_categories: [{
-          name: category,
+
+  const { result: categoryResult } = await createProductCategoriesWorkflow(
+    container
+  ).run({
+    input: {
+      product_categories: [
+        {
+          name: "Shirts",
           is_active: true,
           is_active: true,
-        }],
-      },
-    });
+        },
+        {
+          name: "Sweatshirts",
+          is_active: true,
+        },
+        {
+          name: "Pants",
+          is_active: true,
+        },
+        {
+          name: "Merch",
+          is_active: true,
+        },
+      ],
+    },
+  });
 
 
-    categories[category] = categoryResult[0].id;
-  }
   await createProductsWorkflow(container).run({
   await createProductsWorkflow(container).run({
     input: {
     input: {
       products: [
       products: [
         {
         {
           title: "Medusa T-Shirt",
           title: "Medusa T-Shirt",
-          category_ids: [categories["Shirts"]],
+          category_ids: [
+            categoryResult.find((cat) => cat.name === "Shirts").id,
+          ],
           description:
           description:
             "Reimagine the feeling of a classic T-shirt. With our cotton T-shirts, everyday essentials no longer have to be ordinary.",
             "Reimagine the feeling of a classic T-shirt. With our cotton T-shirts, everyday essentials no longer have to be ordinary.",
           handle: "t-shirt",
           handle: "t-shirt",
@@ -519,7 +525,9 @@ export default async function seedDemoData({ container }: ExecArgs) {
       products: [
       products: [
         {
         {
           title: "Medusa Sweatshirt",
           title: "Medusa Sweatshirt",
-          category_ids: [categories["Sweatshirts"]],
+          category_ids: [
+            categoryResult.find((cat) => cat.name === "Sweatshirts").id,
+          ],
           description:
           description:
             "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
             "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
           handle: "sweatshirt",
           handle: "sweatshirt",
@@ -627,7 +635,7 @@ export default async function seedDemoData({ container }: ExecArgs) {
       products: [
       products: [
         {
         {
           title: "Medusa Sweatpants",
           title: "Medusa Sweatpants",
-          category_ids: [categories["Pants"]],
+          category_ids: [categoryResult.find((cat) => cat.name === "Pants").id],
           description:
           description:
             "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
             "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
           handle: "sweatpants",
           handle: "sweatpants",
@@ -735,7 +743,7 @@ export default async function seedDemoData({ container }: ExecArgs) {
       products: [
       products: [
         {
         {
           title: "Medusa Shorts",
           title: "Medusa Shorts",
-          category_ids: [categories["Merch"]],
+          category_ids: [categoryResult.find((cat) => cat.name === "Merch").id],
           description:
           description:
             "Reimagine the feeling of classic shorts. With our cotton shorts, everyday essentials no longer have to be ordinary.",
             "Reimagine the feeling of classic shorts. With our cotton shorts, everyday essentials no longer have to be ordinary.",
           handle: "shorts",
           handle: "shorts",

文件差异内容过多而无法显示
+ 328 - 310
yarn.lock


部分文件因为文件数量过多而无法显示