diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.js b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.js index da3690a085..6263ebafe2 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.js @@ -1,6 +1,100 @@ import { MedusaError, Validator } from "medusa-core-utils" import { defaultFields, defaultRelations } from "." +/** + * @oas [post] /draft-orders + * operationId: "PostDraftOrders" + * summary: "Create a Draft Order" + * description: "Creates a Draft Order" + * requestBody: + * content: + * application/json: + * schema: + * properties: + * status: + * description: "The status of the draft order" + * type: string + * email: + * description: "The email of the customer of the draft order" + * type: string + * billing_address: + * description: "The Address to be used for billing purposes." + * anyOf: + * - $ref: "#/components/schemas/address" + * shipping_address: + * description: "The Address to be used for shipping." + * anyOf: + * - $ref: "#/components/schemas/address" + * billing_address_id: + * description: The id of an existing billing Address + * type: string + * shipping_address_id: + * description: The id of an existing shipping Address + * type: string + * items: + * description: The Line Items that have been received. + * type: array + * items: + * properties: + * variant_id: + * description: The id of the Product Variant to generate the Line Item from. + * type: string + * unit_price: + * description: The potential custom price of the item. + * type: integer + * title: + * description: The potential custom title of the item. + * type: string + * quantity: + * description: The quantity of the Line Item. + * type: integer + * metadata: + * description: The optional key-value map with additional details about the Line Item. + * type: object + * region_id: + * description: The id of the region for the draft order + * type: string + * discounts: + * description: The discounts to add on the draft order + * type: array + * items: + * properties: + * code: + * description: The code of the discount to apply + * type: string + * customer_id: + * description: The id of the customer to add on the draft order + * type: string + * shipping_methods: + * description: The shipping methods for the draft order + * type: array + * items: + * properties: + * option_id: + * description: The id of the shipping option in use + * type: string + * data: + * description: The optional additional data needed for the shipping method + * type: object + * price: + * description: The potential custom price of the shipping + * type: integer + * metadata: + * description: The optional key-value map with additional details about the Draft Order. + * type: object + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { const schema = Validator.object().keys({ status: Validator.string() diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.js b/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.js index 8d1ed67e16..efcac4cfa7 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.js @@ -1,6 +1,44 @@ import { MedusaError, Validator } from "medusa-core-utils" import { defaultCartFields, defaultCartRelations, defaultFields } from "." +/** + * @oas [post] /draft-orders/{id}/line-items + * operationId: "PostDraftOrdersDraftOrderLineItems" + * summary: "Create a Line Item for Draft Order" + * description: "Creates a Line Item for the Draft Order" + * requestBody: + * content: + * application/json: + * schema: + * properties: + * variant_id: + * description: The id of the Product Variant to generate the Line Item from. + * type: string + * unit_price: + * description: The potential custom price of the item. + * type: integer + * title: + * description: The potential custom title of the item. + * type: string + * quantity: + * description: The quantity of the Line Item. + * type: integer + * metadata: + * description: The optional key-value map with additional details about the Line Item. + * type: object + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.js b/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.js index f668ebf893..c27af61d7a 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.js @@ -1,3 +1,29 @@ +/** + * @oas [delete] /draft-orders/{id} + * operationId: DeleteDraftOrdersDraftOrder + * summary: Delete a Draft Order + * description: "Deletes a Draft Order" + * parameters: + * - (path) id=* {string} The id of the Draft Order. + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * id: + * type: string + * description: The id of the deleted Draft Order. + * object: + * type: string + * description: The type of the object that was deleted. + * deleted: + * type: boolean + */ + export default async (req, res) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.js b/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.js index c6fba46165..e1eeaf95bf 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.js @@ -1,6 +1,27 @@ import { MedusaError, Validator } from "medusa-core-utils" import { defaultCartFields, defaultCartRelations, defaultFields } from "." +/** + * @oas [delete] /draft-orders/{id}/line-items/{line_id} + * operationId: DeleteDraftOrdersDraftOrderLineItemsItem + * summary: Delete a Line Item + * description: "Removes a Line Item from a Draft Order." + * parameters: + * - (path) id=* {string} The id of the Draft Order. + * - (path) line_id=* {string} The id of the Draft Order. + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { const { id, line_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.js b/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.js index 719b166cb9..7453df0ded 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.js @@ -5,6 +5,26 @@ import { defaultCartFields, } from "." +/** + * @oas [get] /draft-orders/{id} + * operationId: "GetDraftOrdersDraftOrder" + * summary: "Retrieve a Draft Order" + * description: "Retrieves a Draft Order." + * parameters: + * - (path) id=* {string} The id of the Draft Order. + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.js b/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.js index 76161e933c..9868cd1da8 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.js @@ -1,6 +1,24 @@ import _ from "lodash" import { defaultFields, defaultRelations } from "./" +/** + * @oas [get] /draft-orders + * operationId: "GetDraftOrders" + * summary: "List Draft Orders" + * description: "Retrieves an list of Draft Orders" + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { try { const draftOrderService = req.scope.resolve("draftOrderService") diff --git a/packages/medusa/src/api/routes/admin/draft-orders/register-payment.js b/packages/medusa/src/api/routes/admin/draft-orders/register-payment.js index 48beb64c71..e38bc93d54 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/register-payment.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/register-payment.js @@ -3,6 +3,26 @@ import { defaultRelations as defaultOrderRelations, } from "../orders/index" +/** + * @oas [post] /draft-orders/{id}/register-payment + * summary: "Registers a payment for a Draft Order" + * operationId: "PostDraftOrdersDraftOrderRegisterPayment" + * description: "Registers a payment for a Draft Order." + * parameters: + * - (path) id=* {String} The Draft Order id. + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.js b/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.js index 736bc89729..2075bcb7bb 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.js +++ b/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.js @@ -1,6 +1,59 @@ import { MedusaError, Validator } from "medusa-core-utils" import { defaultCartFields, defaultCartRelations, defaultFields } from "." +/** + * @oas [post] /admin/draft-orders/{id} + * operationId: PostDraftOrdersDraftOrder + * summary: Update a Draft Order" + * description: "Updates a Draft Order." + * parameters: + * - (path) id=* {string} The id of the Draft Order. + * requestBody: + * content: + * application/json: + * schema: + * properties: + * region_id: + * type: string + * description: The id of the Region to create the Draft Order in. + * country_code: + * type: string + * description: "The 2 character ISO country code to create the Draft Order in." + * email: + * type: string + * description: "An email to be used on the Draft Order." + * billing_address: + * description: "The Address to be used for billing purposes." + * anyOf: + * - $ref: "#/components/schemas/address" + * shipping_address: + * description: "The Address to be used for shipping." + * anyOf: + * - $ref: "#/components/schemas/address" + * discounts: + * description: "An array of Discount codes to add to the Draft Order." + * type: array + * items: + * properties: + * code: + * description: "The code that a Discount is identifed by." + * type: string + * customer_id: + * description: "The id of the Customer to associate the Draft Order with." + * type: string + * tags: + * - Draft Order + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * properties: + * draft_order: + * $ref: "#/components/schemas/draft-order" + */ + export default async (req, res) => { const { id } = req.params diff --git a/packages/medusa/src/models/draft-order.ts b/packages/medusa/src/models/draft-order.ts index 031a7f8fc7..2406133ff4 100644 --- a/packages/medusa/src/models/draft-order.ts +++ b/packages/medusa/src/models/draft-order.ts @@ -9,22 +9,11 @@ import { PrimaryColumn, OneToOne, JoinColumn, - ManyToOne, - JoinTable, - ManyToMany, - OneToMany, } from "typeorm" import { ulid } from "ulid" -import { Address } from "./address" import { Cart } from "./cart" -import { Customer } from "./customer" -import { Discount } from "./discount" -import { LineItem } from "./line-item" import { Order } from "./order" -import { Payment } from "./payment" -import { Region } from "./region" -import { ShippingMethod } from "./shipping-method" enum DraftOrderStatus { OPEN = "open", @@ -83,3 +72,47 @@ export class DraftOrder { this.id = `dorder_${id}` } } + +/** + * @schema draft-order + * title: "DraftOrder" + * description: "Represents a draft order" + * x-resourceId: draft-order + * properties: + * id: + * type: string + * status: + * type: string + * enum: + * - open + * - awaiting + * - completed + * display_id: + * type: string + * cart_id: + * type: string + * cart: + * anyOf: + * - $ref: "#/components/schemas/cart" + * order_id: + * type: string + * order: + * anyOf: + * - $ref: "#/components/schemas/order" + * canceled_at: + * type: string + * format: date-time + * created_at: + * type: string + * format: date-time + * update_at: + * type: string + * format: date-time + * deleted_at: + * type: string + * format: date-time + * metadata: + * type: object + * idempotency_key: + * type: string + */