diff --git a/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts b/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts index 892a631175..8375f6c7a6 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts @@ -108,7 +108,7 @@ import { Type } from "class-transformer" * // must be previously logged in or use api token * medusa.admin.customerGroups.list() * .then(({ customer_groups, limit, offset, count }) => { - * console.log(customer_groups.id); + * console.log(customer_groups.length); * }); * - lang: Shell * label: cURL diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts index 84e11460bb..9c850efe18 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts @@ -49,10 +49,10 @@ import { validator } from "../../../../utils/validator" * format: email * billing_address: * description: "The Address to be used for billing purposes." - * $ref: "#/components/schemas/address" + * $ref: "#/components/schemas/address_fields" * shipping_address: * description: "The Address to be used for shipping." - * $ref: "#/components/schemas/address" + * $ref: "#/components/schemas/address_fields" * items: * description: The Line Items that have been received. * type: array diff --git a/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts index d1596e37d7..5ec7f5e7a7 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts @@ -47,10 +47,10 @@ import { validator } from "../../../../utils/validator" * format: email * billing_address: * description: "The Address to be used for billing purposes." - * $ref: "#/components/schemas/address" + * $ref: "#/components/schemas/address_fields" * shipping_address: * description: "The Address to be used for shipping." - * $ref: "#/components/schemas/address" + * $ref: "#/components/schemas/address_fields" * discounts: * description: "An array of Discount codes to add to the Draft Order." * type: array diff --git a/packages/medusa/src/api/routes/admin/orders/update-order.ts b/packages/medusa/src/api/routes/admin/orders/update-order.ts index 9d3b5e8511..c574d9e249 100644 --- a/packages/medusa/src/api/routes/admin/orders/update-order.ts +++ b/packages/medusa/src/api/routes/admin/orders/update-order.ts @@ -35,11 +35,11 @@ import { validator } from "../../../../utils/validator" * billing_address: * description: Billing address * anyOf: - * - $ref: "#/components/schemas/address" + * - $ref: "#/components/schemas/address_fields" * shipping_address: * description: Shipping address * anyOf: - * - $ref: "#/components/schemas/address" + * - $ref: "#/components/schemas/address_fields" * items: * description: The Line Items for the order * type: array diff --git a/packages/medusa/src/api/routes/store/customers/create-address.ts b/packages/medusa/src/api/routes/store/customers/create-address.ts index 87b3f8394f..cf6c34058d 100644 --- a/packages/medusa/src/api/routes/store/customers/create-address.ts +++ b/packages/medusa/src/api/routes/store/customers/create-address.ts @@ -21,8 +21,16 @@ import { EntityManager } from "typeorm" * properties: * address: * description: "The Address to add to the Customer." - * anyOf: - * - $ref: "#/components/schemas/address" + * allOf: + * - $ref: "#/components/schemas/address_fields" + * - type: object + * required: + * - first_name + * - last_name + * - address_1 + * - city + * - country_code + * - postal_code * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/store/customers/update-address.ts b/packages/medusa/src/api/routes/store/customers/update-address.ts index 09173abe21..803b2b0830 100644 --- a/packages/medusa/src/api/routes/store/customers/update-address.ts +++ b/packages/medusa/src/api/routes/store/customers/update-address.ts @@ -18,7 +18,7 @@ import { EntityManager } from "typeorm" * application/json: * schema: * anyOf: - * - $ref: "#/components/schemas/address" + * - $ref: "#/components/schemas/address_fields" * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/store/customers/update-customer.ts b/packages/medusa/src/api/routes/store/customers/update-customer.ts index 52cc5a7f02..7cc495c550 100644 --- a/packages/medusa/src/api/routes/store/customers/update-customer.ts +++ b/packages/medusa/src/api/routes/store/customers/update-customer.ts @@ -27,7 +27,7 @@ import { EntityManager } from "typeorm" * billing_address: * description: "The Address to be used for billing purposes." * anyOf: - * - $ref: "#/components/schemas/address" + * - $ref: "#/components/schemas/address_fields" * description: The full billing address object * - type: string * description: The ID of an existing billing address diff --git a/packages/medusa/src/api/routes/store/products/get-product.ts b/packages/medusa/src/api/routes/store/products/get-product.ts index 9fa95b7883..d9adc18b34 100644 --- a/packages/medusa/src/api/routes/store/products/get-product.ts +++ b/packages/medusa/src/api/routes/store/products/get-product.ts @@ -51,7 +51,16 @@ import { validator } from "../../../../utils/validator" * schema: * properties: * product: - * $ref: "#/components/schemas/product" + * allOf: + * - $ref: "#/components/schemas/product" + * - type: object + * properties: + * variants: + * type: array + * items: + * allOf: + * - $ref: "#/components/schemas/product_variant" + * - $ref: "#/components/schemas/product_variant_prices_fields" * "400": * $ref: "#/components/responses/400_error" * "404": diff --git a/packages/medusa/src/api/routes/store/products/list-products.ts b/packages/medusa/src/api/routes/store/products/list-products.ts index 114e744f4a..20d22253f4 100644 --- a/packages/medusa/src/api/routes/store/products/list-products.ts +++ b/packages/medusa/src/api/routes/store/products/list-products.ts @@ -141,7 +141,16 @@ import { IsType } from "../../../../utils/validators/is-type" * products: * type: array * items: - * $ref: "#/components/schemas/product" + * allOf: + * - $ref: "#/components/schemas/product" + * - type: object + * properties: + * variants: + * type: array + * items: + * allOf: + * - $ref: "#/components/schemas/product_variant" + * - $ref: "#/components/schemas/product_variant_prices_fields" * count: * type: integer * description: The total number of items available diff --git a/packages/medusa/src/api/routes/store/variants/get-variant.ts b/packages/medusa/src/api/routes/store/variants/get-variant.ts index c3c4714b7d..379377a900 100644 --- a/packages/medusa/src/api/routes/store/variants/get-variant.ts +++ b/packages/medusa/src/api/routes/store/variants/get-variant.ts @@ -43,7 +43,9 @@ import { validator } from "../../../../utils/validator" * schema: * properties: * variant: - * $ref: "#/components/schemas/product_variant" + * allOf: + * - $ref: "#/components/schemas/product_variant" + * - $ref: "#/components/schemas/product_variant_prices_fields" * "400": * $ref: "#/components/responses/400_error" * "404": diff --git a/packages/medusa/src/api/routes/store/variants/list-variants.ts b/packages/medusa/src/api/routes/store/variants/list-variants.ts index 1899f82267..614569ff52 100644 --- a/packages/medusa/src/api/routes/store/variants/list-variants.ts +++ b/packages/medusa/src/api/routes/store/variants/list-variants.ts @@ -77,7 +77,9 @@ import { validator } from "../../../../utils/validator" * variants: * type: array * items: - * $ref: "#/components/schemas/product_variant" + * allOf: + * - $ref: "#/components/schemas/product_variant" + * - $ref: "#/components/schemas/product_variant_prices_fields" * "400": * $ref: "#/components/responses/400_error" * "404": diff --git a/packages/medusa/src/models/address.ts b/packages/medusa/src/models/address.ts index d0883fea6d..8ed36a0164 100644 --- a/packages/medusa/src/models/address.ts +++ b/packages/medusa/src/models/address.ts @@ -1,3 +1,126 @@ +import { + BeforeInsert, + Column, + Entity, + Index, + JoinColumn, + ManyToOne, +} from "typeorm" + +import { Country } from "./country" +import { Customer } from "./customer" +import { DbAwareColumn } from "../utils/db-aware-column" +import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity" +import { generateEntityId } from "../utils/generate-entity-id" + +@Entity() +export class Address extends SoftDeletableEntity { + @Index() + @Column({ type: "varchar", nullable: true }) + customer_id: string | null + + @ManyToOne(() => Customer) + @JoinColumn({ name: "customer_id" }) + customer: Customer | null + + @Column({ type: "varchar", nullable: true }) + company: string | null + + @Column({ type: "varchar", nullable: true }) + first_name: string | null + + @Column({ type: "varchar", nullable: true }) + last_name: string | null + + @Column({ type: "varchar", nullable: true }) + address_1: string | null + + @Column({ type: "varchar", nullable: true }) + address_2: string | null + + @Column({ type: "varchar", nullable: true }) + city: string | null + + @Column({ type: "varchar", nullable: true }) + country_code: string | null + + @ManyToOne(() => Country) + @JoinColumn({ name: "country_code", referencedColumnName: "iso_2" }) + country: Country | null + + @Column({ type: "varchar", nullable: true }) + province: string | null + + @Column({ type: "varchar", nullable: true }) + postal_code: string | null + + @Column({ type: "varchar", nullable: true }) + phone: string | null + + @DbAwareColumn({ type: "jsonb", nullable: true }) + metadata: Record + + @BeforeInsert() + private beforeInsert(): void { + this.id = generateEntityId(this.id, "addr") + } +} + +/** + * @schema address_fields + * title: "Address Fields" + * description: "Address fields used when creating/updating an address." + * x-resourceId: address + * properties: + * company: + * type: string + * description: Company name + * example: Acme + * first_name: + * type: string + * description: First name + * example: Arno + * last_name: + * type: string + * description: Last name + * example: Willms + * address_1: + * type: string + * description: Address line 1 + * example: 14433 Kemmer Court + * address_2: + * type: string + * description: Address line 2 + * example: Suite 369 + * city: + * type: string + * description: City + * example: South Geoffreyview + * country_code: + * type: string + * description: The 2 character ISO code of the country in lower case + * externalDocs: + * url: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements + * description: See a list of codes. + * example: st + * province: + * type: string + * description: Province + * example: Kentucky + * postal_code: + * type: string + * description: Postal Code + * example: 72093 + * phone: + * type: string + * description: Phone Number + * example: 16128234334802 + * metadata: + * type: object + * description: An optional key-value map with additional details + * example: {car: "white"} + */ + /** * @schema address * title: "Address" @@ -80,72 +203,4 @@ * type: object * description: An optional key-value map with additional details * example: {car: "white"} - */ - -import { - BeforeInsert, - Column, - Entity, - Index, - JoinColumn, - ManyToOne, -} from "typeorm" - -import { Country } from "./country" -import { Customer } from "./customer" -import { DbAwareColumn } from "../utils/db-aware-column" -import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity" -import { generateEntityId } from "../utils/generate-entity-id" - -@Entity() -export class Address extends SoftDeletableEntity { - @Index() - @Column({ type: "varchar", nullable: true }) - customer_id: string | null - - @ManyToOne(() => Customer) - @JoinColumn({ name: "customer_id" }) - customer: Customer | null - - @Column({ type: "varchar", nullable: true }) - company: string | null - - @Column({ type: "varchar", nullable: true }) - first_name: string | null - - @Column({ type: "varchar", nullable: true }) - last_name: string | null - - @Column({ type: "varchar", nullable: true }) - address_1: string | null - - @Column({ type: "varchar", nullable: true }) - address_2: string | null - - @Column({ type: "varchar", nullable: true }) - city: string | null - - @Column({ type: "varchar", nullable: true }) - country_code: string | null - - @ManyToOne(() => Country) - @JoinColumn({ name: "country_code", referencedColumnName: "iso_2" }) - country: Country | null - - @Column({ type: "varchar", nullable: true }) - province: string | null - - @Column({ type: "varchar", nullable: true }) - postal_code: string | null - - @Column({ type: "varchar", nullable: true }) - phone: string | null - - @DbAwareColumn({ type: "jsonb", nullable: true }) - metadata: Record - - @BeforeInsert() - private beforeInsert(): void { - this.id = generateEntityId(this.id, "addr") - } -} + */ \ No newline at end of file diff --git a/packages/medusa/src/models/product-variant.ts b/packages/medusa/src/models/product-variant.ts index 2045e6c648..66f5942432 100644 --- a/packages/medusa/src/models/product-variant.ts +++ b/packages/medusa/src/models/product-variant.ts @@ -216,3 +216,44 @@ export class ProductVariant extends SoftDeletableEntity { * description: An optional key-value map with additional details * example: {car: "white"} */ + +/** + * @schema product_variant_prices_fields + * title: "Product Variant Prices Fields" + * description: "Product Variants Prices Fields that are only available in some requests." + * x-resourceId: product_variant_prices_fields + * properties: + * original_price: + * type: number + * description: The original price of the variant without any discounted prices applied. + * calculated_price: + * type: number + * description: The calculated price of the variant. Can be a discounted price. + * original_price_incl_tax: + * type: number + * description: The original price of the variant including taxes. + * calculated_price_incl_tax: + * type: number + * description: The calculated price of the variant including taxes. + * original_tax: + * type: number + * description: The taxes applied on the original price. + * calculated_tax: + * type: number + * description: The taxes applied on the calculated price. + * tax_rates: + * type: array + * description: An array of applied tax rates + * items: + * type: object + * properties: + * rate: + * type: number + * description: The tax rate value + * name: + * type: string + * description: The name of the tax rate + * code: + * type: string + * description: The code of the tax rate + */ \ No newline at end of file