From d84ff0230c01c258fcca2b68c614baed6dd5ed83 Mon Sep 17 00:00:00 2001 From: Labham Jain Date: Mon, 30 Oct 2023 21:05:40 +0530 Subject: [PATCH] fix: location ancestors in sheet --- dump.rdb | Bin 166719 -> 171059 bytes medusa-config.js | 2 +- src/services/category.ts | 32 ++++++++++++++++++++++---------- src/services/customer.ts | 1 - 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/dump.rdb b/dump.rdb index 5c4a8696f25368c5e593592ea469971819a5ebd4..99ef1e99be8e45973b6c5af4285677fcc175fb82 100644 GIT binary patch delta 3768 zcmZu!Yj7LY8Qon!W6SYFc8p`o2Is*LNU|@jRv9{I-`iDovkyhPD?5_ySV}??2zit? z6qE;nGPDyQ6v31sp;HQNXW9TQ;YTN=?XlGjD~~n3_;S-jSciJu7|mEHTl@ku?~1g z1Y1X7>ri@4a~w?`gKMZ4&%n>XaOrTV=KfL*e5zD~{Ca;qU!yPXSzNheC4!xD??Emh z<+eP0_JZG^kGf`3AZ$`f7@90evaOnC&hO5rhW(bj7g0y^&}&}(L)G@vUWD_T3(y6x z-t;>QUSuQqPUZc!0-|ya)xOi65++y)+!Ty-MoMtDELbeY_}v8n6)AWv>SzJd02J8a zwUk4w9RXGpEU#dldttF3D|AR~JWgpYqf@kDm~lsNxa)s*v1>S>1^zq0dOg5u2a6Eu z(<`*v3NU=R4T9hY4>qoO51RVGzvI5zaIx!RD+Db?l5mCEk6c%CPcKq=a~0BW3#g<@ zT*8tZ#Z~Q$u9*&(#n^#+ZyVjYq*(X(uHCnf@7uh0_2$vN#Vxn*{??j(yT-3=LdJWV z&WxqLed7Mc`|ljxws+fYTN=Io%~0bR4u)Y5dZu!egO@and><-%^rho>;$m z4EnQIKk0XZ)keQ|toDJSyY9Yev9_pE)dKG@@;t`s*Ii^|%xl(99%AW6Tw2%!gtCwkXW#Y0f| z45*Z#p#zUiK!^O!QV3QG2$Yc8LW3VGMRPbMQy8ixtSpD;z-dyb?su0`<>6}VTu@Xo z#Z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*8x?4qtn9iK87N;j4w|B6V-QRm;mI3A-*y9an_PG@9m+c#&cbkzOa<8E{DDFT z&m}05WNk$vc~RzNQJ8k^#Rab!y!8T?>I0z!-Y@bn#CvsBzbo%GKR#pI@Hb9)b$3){}d;17$K+f6;cSkyyk=0-O*&6I_V{$n=O>-HMkU&t* zy=f5h2o)C+8oUD#YB#~lQ_>K1ip0}AkySbL+Sez#`axw^7?t~`DNTjje3gEG65MwD0uR(bAv5% z9JICm*}?FZ6aQt;soX)N241`Ek+p{(gh7|D*i+oIXPvQOR-$F|Yy_w$L}W7wFO z(`B>h5aO1to7ZbwD$HTzYpqxYMc0wUI)Yr&Ow++7GI?tF5V9Svx%etmIeQohE}1B? s4hNS^oS=eB=CL!dbn2CRksJ))eroA`$Xm6GF8}TICq8{}@a!-C2R-UAKL7v# delta 235 zcmdnIgKPgZt_g-hM*Hkje{qx+r>5xUrsf`+@l$M~^BHERYURm7j5$08R>lTaMn-zv zrp5-78JW#CA7EU{$e7fe#@wF9%(y*`nQ2cIkF%x^wzF<= z3Gl=*GX4+XX=Gqv>~8qCBYgYAiA+FEGbb};F)~Lklb+5tl?h~pk)f4|r5?ADxe>^U z$p;wSxBs5X6vfEuz|7*{Fx_A}lhXE@=}hZbxc|s-{%`1JWME*>2Mendmn7!o0G*zk fk(!*%YiMR^VP { + product.variants?.[0]?.prices.forEach((price) => { prices[price.currency_code] = price.amount; }); diff --git a/src/services/category.ts b/src/services/category.ts index 484a727..6b3d62e 100644 --- a/src/services/category.ts +++ b/src/services/category.ts @@ -1,5 +1,5 @@ import { ProductCategory, ProductCategoryService } from "@medusajs/medusa"; -import { buildLocationTree, getLastLocationPath, getLocationPath, getLocationPathWithLastID } from "../utils/convertIntoNestedLocations"; + class CategoryService extends ProductCategoryService { constructor(container) { @@ -15,17 +15,30 @@ class CategoryService extends ProductCategoryService { } async retrieveAllLastLocationsName() { - const retrieveAllLocations = ` - SELECT name, id, parent_category_id FROM "product_category" WHERE handle LIKE 'loc:%' - ` + const categories = await this.listAndCount({}) + const res = await Promise.all(categories[0].map((c) => { + return this.productCategoryRepo_.findDescendantsTree(c) + })) + + const childCategories = res.filter(r => !r.category_children?.length && r.handle.startsWith('loc:')); + + const categoriesWithParent = await Promise.all(childCategories.map((c) => this.productCategoryRepo_.findAncestorsTree(c))) - const result = await this.activeManager_.query(retrieveAllLocations) as { name: string, id: string, parent_category_id: string }[] - // Convert the location tree to slash-separated strings + return categoriesWithParent.map((category) => { + const list = []; - const nestedLocations = buildLocationTree(result); - const locationStrings: string[] = getLocationPath(nestedLocations) - return locationStrings + const getParent = (pcat: ProductCategory) => { + if (pcat.parent_category) { + list.unshift(pcat.name) + getParent(pcat.parent_category) + } + } + + getParent(category); + + return list.join(' / '); + }) } @@ -43,7 +56,6 @@ class CategoryService extends ProductCategoryService { const getLocation = async (locationId: string) => { const location = await this.retrieve(locationId); - if (location.parent_category_id) { locations.unshift(location) await getLocation(location.parent_category_id) diff --git a/src/services/customer.ts b/src/services/customer.ts index 997f84d..d10b3e0 100644 --- a/src/services/customer.ts +++ b/src/services/customer.ts @@ -25,7 +25,6 @@ export default class CustomerService extends BaseCustomerService { const customerResult = await this.activeManager_.query(customerByEmailQuery, [email]) as Customer[] if (!customerResult.length) { - console.log(customerResult); throw new Error('Customer not found with this email!') }