-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: Add missing endpoints and normalize customer and currency endpoints for storefront #7160
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 14 additions & 4 deletions
18
packages/medusa/src/api-v2/store/currencies/[code]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import { remoteQueryObjectFromString } from "@medusajs/utils" | ||
import { | ||
ContainerRegistrationKeys, | ||
MedusaError, | ||
remoteQueryObjectFromString, | ||
} from "@medusajs/utils" | ||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing" | ||
import { defaultStoreCurrencyFields } from "../query-config" | ||
|
||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => { | ||
const remoteQuery = req.scope.resolve("remoteQuery") | ||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) | ||
|
||
const variables = { code: req.params.code } | ||
|
||
const queryObject = remoteQueryObjectFromString({ | ||
entryPoint: "currency", | ||
variables, | ||
fields: defaultStoreCurrencyFields, | ||
fields: req.remoteQueryConfig.fields, | ||
}) | ||
|
||
const [currency] = await remoteQuery(queryObject) | ||
if (!currency) { | ||
throw new MedusaError( | ||
MedusaError.Types.NOT_FOUND, | ||
`Currency with code: ${req.params.code} was not found` | ||
) | ||
} | ||
|
||
res.status(200).json({ currency }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
packages/medusa/src/api-v2/store/currencies/query-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
export const defaultStoreCurrencyRelations = [] | ||
export const allowedStoreCurrencyRelations = [] | ||
export const defaultStoreCurrencyFields = [ | ||
"code", | ||
"name", | ||
"symbol", | ||
"symbol_native", | ||
"decimal_digits", | ||
"rounding", | ||
] | ||
|
||
export const retrieveTransformQueryConfig = { | ||
defaultFields: defaultStoreCurrencyFields, | ||
defaultRelations: defaultStoreCurrencyRelations, | ||
allowedRelations: allowedStoreCurrencyRelations, | ||
defaults: defaultStoreCurrencyFields, | ||
isList: false, | ||
} | ||
|
||
export const listTransformQueryConfig = { | ||
defaultLimit: 20, | ||
...retrieveTransformQueryConfig, | ||
defaultLimit: 50, | ||
isList: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 17 additions & 28 deletions
45
packages/medusa/src/api-v2/store/currencies/validators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
import { Type } from "class-transformer" | ||
import { IsOptional, IsString, ValidateNested } from "class-validator" | ||
import { FindParams, extendedFindParamsMixin } from "../../../types/common" | ||
import { createFindParams, createSelectParams } from "../../utils/validators" | ||
import { z } from "zod" | ||
|
||
export class StoreGetCurrenciesCurrencyParams extends FindParams {} | ||
/** | ||
* Parameters used to filter and configure the pagination of the retrieved currencies. | ||
*/ | ||
export class StoreGetCurrenciesParams extends extendedFindParamsMixin({ | ||
limit: 50, | ||
offset: 0, | ||
}) { | ||
/** | ||
* Search parameter for currencies. | ||
*/ | ||
@IsString({ each: true }) | ||
@IsOptional() | ||
code?: string | string[] | ||
|
||
// Additional filters from BaseFilterable | ||
@IsOptional() | ||
@ValidateNested({ each: true }) | ||
@Type(() => StoreGetCurrenciesParams) | ||
$and?: StoreGetCurrenciesParams[] | ||
export const StoreGetCurrencyParams = createSelectParams() | ||
|
||
@IsOptional() | ||
@ValidateNested({ each: true }) | ||
@Type(() => StoreGetCurrenciesParams) | ||
$or?: StoreGetCurrenciesParams[] | ||
} | ||
export type StoreGetCurrenciesParamsType = z.infer< | ||
typeof StoreGetCurrenciesParams | ||
> | ||
export const StoreGetCurrenciesParams = createFindParams({ | ||
offset: 0, | ||
limit: 50, | ||
}).merge( | ||
z.object({ | ||
q: z.string().optional(), | ||
code: z.union([z.string(), z.array(z.string())]).optional(), | ||
$and: z.lazy(() => StoreGetCurrenciesParams.array()).optional(), | ||
$or: z.lazy(() => StoreGetCurrenciesParams.array()).optional(), | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MedusaContainer } from "@medusajs/types" | ||
import { | ||
ContainerRegistrationKeys, | ||
remoteQueryObjectFromString, | ||
} from "@medusajs/utils" | ||
|
||
export const refetchCustomer = async ( | ||
customerId: string, | ||
scope: MedusaContainer, | ||
fields: string[] | ||
) => { | ||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) | ||
const queryObject = remoteQueryObjectFromString({ | ||
entryPoint: "customer", | ||
variables: { | ||
filters: { id: customerId }, | ||
}, | ||
fields: fields, | ||
}) | ||
|
||
const customers = await remoteQuery(queryObject) | ||
return customers[0] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: is this type getting inferred correctly for you? I'm getting any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@riqwan it seems it doesn't, nice catch. It is a general issue though it seems, not specific to the currencies.