This commit is contained in:
olivermrbl
2021-03-11 13:40:20 +01:00
parent 83a7d7ec5a
commit 641c1df14a
9 changed files with 334 additions and 11 deletions
@@ -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()
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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")
@@ -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
@@ -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
+44 -11
View File
@@ -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
*/