Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(medusa): migrate store cart endpoints to zod #7130

Merged
merged 2 commits into from
Apr 23, 2024
Merged

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Apr 23, 2024

what:

  • migrates all store cart endpoints to zod

RESOLVES CORE-2014

Copy link

changeset-bot bot commented Apr 23, 2024

🦋 Changeset detected

Latest commit: 8664360

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/medusa Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview Apr 23, 2024 10:53am
medusa-dashboard 🛑 Canceled (Inspect) Apr 23, 2024 10:53am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
docs-ui ⬜️ Ignored (Inspect) Visit Preview Apr 23, 2024 10:53am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Apr 23, 2024 10:53am

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

remoteQueryObjectFromString,
} from "@medusajs/utils"

export const refetchCart = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: I have noticed these refetch-helpers do not accept filters. I think we should add that going forward, so that you can also pass params on a POST request.

cc @sradevski

Copy link
Contributor Author

@riqwan riqwan Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be a single generic entity:

export const refetchEntity = async (
  entryPoint: string,
  idOrFilter: string | object,
  scope: MedusaContainer,
  fields: string[]
) => {
  const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
  const filters = isString(idOrFilter) ? { id: idOrFilter } : idOrFilter
  const queryObject = remoteQueryObjectFromString({
    entryPoint,
    variables: { filters },
    fields,
  })

  const [entity] = await remoteQuery(queryObject)

  return entity
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riqwan I completely agree, I was thinking about it but I didn't want to do it while doing the cleanup, as it will be pretty easy to refactor it. I think we can still keep eg. refetchProduct as a method, which instead calls refetchEntity("product", ...args).

@riqwan riqwan merged commit 2446151 into develop Apr 23, 2024
24 checks passed
@riqwan riqwan deleted the feat/store-zod branch April 23, 2024 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants