#Extend collection store api

3 messages · Page 1 of 1 (latest)

minor harbor
#

Hello Devs,
I'm fairly new to medusa and have been facing a problem for a few days.
I've done a lot of research and couldn't help myself.

I have extended the collection so that you can assign a image.
This works fine for the admin api.

But in the Store API I can't get the new field.
What am I doing wrong?

  const adminCollectionImports = (await import(
    "@medusajs/medusa/dist/api/routes/admin/collections/index"
  )) as any;

  const storeCollectionImports = (await import(
    "@medusajs/medusa/dist/api/routes/store/collections/index"
  )) as any;

  adminCollectionImports.defaultAdminCollectionsRelations = [
    ...adminCollectionImports.defaultAdminCollectionsRelations,
    "images",
  ];

  storeCollectionImports.defaultStoreCollectionRelations = [
    ...storeCollectionImports.defaultStoreCollectionRelations,
    "images",
  ];

  storeCollectionImports.allowedFields = [
    ...storeCollectionImports.allowedFields,
    "images",
  ];
}```
merry drift
#

why are you adding to defaultStoreCollectionRelations and allowedFields this is redundant as the allowedFields includes defaultStoreCollectionRelations

minor harbor
#

just some trial and error.
i tried a lot and nothing was working.

finally I fixed my issue by adding relations to the retrieve method.

const collection = await super.retrieve(collectionId, {
      ...config,
      relations: ["images"],
    });

But this feels dirty. I would be grateful for a nicer solution