Skip to content

Commit

Permalink
feat(oas): declare x-expanded-relations - Store (medusajs#3482)
Browse files Browse the repository at this point in the history
* feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* chore(changeset): patch

* fix(tests): update store auth integration test

* fix: pr feedback

* fix(test): match response code
  • Loading branch information
patrick-medusajs authored Mar 16, 2023
1 parent da0787b commit 522e306
Show file tree
Hide file tree
Showing 31 changed files with 448 additions and 52 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-pillows-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/client-types": patch
"@medusajs/medusa": patch
---

feat(oas): declare x-expanded-relations - Store
18 changes: 0 additions & 18 deletions integration-tests/api/__tests__/store/__snapshots__/auth.js.snap

This file was deleted.

21 changes: 12 additions & 9 deletions integration-tests/api/__tests__/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ describe("/store/auth", () => {

expect(response.status).toEqual(200)
expect(response.data.customer.password_hash).toEqual(undefined)
expect(response.data.customer).toMatchSnapshot({
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "test",
last_name: "testesen",
phone: null,
email: "test@testesen.dk",
})
expect(response.data.customer).toEqual(
expect.objectContaining({
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "test",
last_name: "testesen",
phone: null,
email: "test@testesen.dk",
shipping_addresses: expect.arrayContaining([]),
})
)
})

describe("Store session management", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe("/store/payment-collections", () => {
})
)

expect(response.status).toEqual(207)
expect(response.status).toEqual(200)
})
})
})
3 changes: 2 additions & 1 deletion packages/medusa/src/api/routes/store/auth/create-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EntityManager } from "typeorm"
import AuthService from "../../../../services/auth"
import CustomerService from "../../../../services/customer"
import { validator } from "../../../../utils/validator"
import { defaultRelations } from "."

/**
* @oas [post] /store/auth
Expand Down Expand Up @@ -91,7 +92,7 @@ export default async (req, res) => {

const customerService: CustomerService = req.scope.resolve("customerService")
const customer = await customerService.retrieve(result.customer?.id || "", {
relations: ["orders", "orders.items"],
relations: defaultRelations,
})

res.json({ customer })
Expand Down
3 changes: 2 additions & 1 deletion packages/medusa/src/api/routes/store/auth/get-session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CustomerService from "../../../../services/customer"
import { defaultRelations } from "."

/**
* @oas [get] /store/auth
Expand Down Expand Up @@ -52,7 +53,7 @@ export default async (req, res) => {
const customerService: CustomerService = req.scope.resolve("customerService")

const customer = await customerService.retrieve(req.user.customer_id, {
relations: ["shipping_addresses", "orders", "orders.items"],
relations: defaultRelations,
})

res.json({ customer })
Expand Down
8 changes: 8 additions & 0 deletions packages/medusa/src/api/routes/store/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ export default (app) => {
return app
}

export const defaultRelations = ["orders", "orders.items", "shipping_addresses"]

/**
* @schema StoreAuthRes
* type: object
* x-expanded-relations:
* field: customer
* relations:
* - orders
* - orders.items
* - shipping_addresses
* required:
* - customer
* properties:
Expand Down
21 changes: 15 additions & 6 deletions packages/medusa/src/api/routes/store/carts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,24 @@ export const defaultStoreCartRelations = [
* - region.payment_providers
* - shipping_address
* - shipping_methods
* - shipping_methods.shipping_option
* implicit:
* - items.tax_lines
* - items.variant.product
* eager:
* - region.fulfillment_providers
* - region.payment_providers
* - region.tax_rates
* - shipping_methods.shipping_option
* - shipping_methods.tax_lines
* implicit:
* - items
* - items.variant
* - items.variant.product
* - items.tax_lines
* - items.adjustments
* - gift_cards
* - discounts
* - discounts.rule
* - shipping_methods
* - shipping_methods.tax_lines
* - shipping_address
* - region
* - region.tax_rates
* totals:
* - discount_total
* - gift_card_tax_total
Expand Down
3 changes: 2 additions & 1 deletion packages/medusa/src/api/routes/store/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export default (app) => {
return app
}

export const defaultStoreCollectionRelations = ["products"]
export const defaultStoreCollectionRelations = []
export const allowedFields = [
"id",
"title",
"handle",
"products",
"metadata",
"created_at",
"updated_at",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import { Type } from "class-transformer"
* - (query) offset=0 {integer} The number of collections to skip before starting to collect the collections set
* - (query) limit=10 {integer} The number of collections to return
* - in: query
* name: handle
* style: form
* explode: false
* description: Filter by the collection handle
* schema:
* type: array
* items:
* type: string
* - in: query
* name: created_at
* description: Date comparison for when resulting collections were created.
* schema:
Expand Down
99 changes: 99 additions & 0 deletions packages/medusa/src/api/routes/store/customers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export const allowedStoreCustomersFields = [
/**
* @schema StoreCustomersRes
* type: object
* x-expanded-relations:
* field: customer
* relations:
* - billing_address
* - shipping_addresses
* required:
* - customer
* properties:
Expand All @@ -124,9 +129,103 @@ export type StoreCustomersRes = {
customer: Omit<Customer, "password_hash">
}

/**
* @schema StoreCustomersResetPasswordRes
* type: object
* required:
* - customer
* properties:
* customer:
* $ref: "#/components/schemas/Customer"
*/
export type StoreCustomersResetPasswordRes = {
customer: Omit<Customer, "password_hash">
}

/**
* @schema StoreCustomersListOrdersRes
* type: object
* x-expanded-relations:
* field: orders
* relations:
* - customer
* - discounts
* - discounts.rule
* - fulfillments
* - fulfillments.tracking_links
* - items
* - items.variant
* - payments
* - region
* - shipping_address
* - shipping_methods
* eager:
* - region.fulfillment_providers
* - region.payment_providers
* - shipping_methods.shipping_option
* implicit:
* - claims
* - claims.additional_items
* - claims.additional_items.adjustments
* - claims.additional_items.refundable
* - claims.additional_items.tax_lines
* - customer
* - discounts
* - discounts.rule
* - gift_card_transactions
* - gift_card_transactions.gift_card
* - gift_cards
* - items
* - items.adjustments
* - items.refundable
* - items.tax_lines
* - items.variant
* - items.variant.product
* - refunds
* - region
* - shipping_address
* - shipping_methods
* - shipping_methods.tax_lines
* - swaps
* - swaps.additional_items
* - swaps.additional_items.adjustments
* - swaps.additional_items.refundable
* - swaps.additional_items.tax_lines
* totals:
* - discount_total
* - gift_card_tax_total
* - gift_card_total
* - paid_total
* - refundable_amount
* - refunded_total
* - shipping_total
* - subtotal
* - tax_total
* - total
* - claims.additional_items.discount_total
* - claims.additional_items.gift_card_total
* - claims.additional_items.original_tax_total
* - claims.additional_items.original_total
* - claims.additional_items.refundable
* - claims.additional_items.subtotal
* - claims.additional_items.tax_total
* - claims.additional_items.total
* - items.discount_total
* - items.gift_card_total
* - items.original_tax_total
* - items.original_total
* - items.refundable
* - items.subtotal
* - items.tax_total
* - items.total
* - swaps.additional_items.discount_total
* - swaps.additional_items.gift_card_total
* - swaps.additional_items.original_tax_total
* - swaps.additional_items.original_total
* - swaps.additional_items.refundable
* - swaps.additional_items.subtotal
* - swaps.additional_items.tax_total
* - swaps.additional_items.total
* required:
* - orders
* - count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { EntityManager } from "typeorm"
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/StoreCustomersRes"
* $ref: "#/components/schemas/StoreCustomersResetPasswordRes"
* "400":
* $ref: "#/components/responses/400_error"
* "401":
Expand Down
35 changes: 35 additions & 0 deletions packages/medusa/src/api/routes/store/order-edits/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ export default (app) => {
/**
* @schema StoreOrderEditsRes
* type: object
* x-expanded-relations:
* field: order_edit
* relations:
* - changes
* - changes.line_item
* - changes.line_item.variant
* - changes.original_line_item
* - changes.original_line_item.variant
* - items
* - items.adjustments
* - items.tax_lines
* - items.variant
* - payment_collection
* implicit:
* - items
* - items.tax_lines
* - items.adjustments
* - items.variant
* totals:
* - difference_due
* - discount_total
* - gift_card_tax_total
* - gift_card_total
* - shipping_total
* - subtotal
* - tax_total
* - total
* - items.discount_total
* - items.gift_card_total
* - items.original_tax_total
* - items.original_total
* - items.refundable
* - items.subtotal
* - items.tax_total
* - items.total
* required:
* - order_edit
* properties:
Expand Down
Loading

0 comments on commit 522e306

Please sign in to comment.