Merge branch 'develop' into feat/draft-orders

This commit is contained in:
olivermrbl
2021-03-11 08:35:41 +01:00
275 changed files with 37662 additions and 1454 deletions
@@ -17,4 +17,73 @@ Joi.address = () => {
})
}
Joi.dateFilter = () => {
return Joi.object({
lt: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
gt: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
gte: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
lte: Joi.alternatives(Joi.date().timestamp("unix"), Joi.date()),
})
}
Joi.orderFilter = () => {
return Joi.object().keys({
id: Joi.string(),
q: Joi.string(),
status: Joi.array()
.items(
Joi.string().valid(
"pending",
"completed",
"archived",
"canceled",
"requires_action"
)
)
.single(),
fulfillment_status: Joi.array()
.items(
Joi.string().valid(
"not_fulfilled",
"fulfilled",
"partially_fulfilled",
"shipped",
"partially_shipped",
"canceled",
"returned",
"partially_returned",
"requires_action"
)
)
.single(),
payment_status: Joi.array()
.items(
Joi.string().valid(
"captured",
"awaiting",
"not_paid",
"refunded",
"partially_refunded",
"canceled",
"requires_action"
)
)
.single(),
display_id: Joi.string(),
cart_id: Joi.string(),
offset: Joi.string(),
limit: Joi.string(),
expand: Joi.string(),
fields: Joi.string(),
customer_id: Joi.string(),
email: Joi.string(),
region_id: Joi.string(),
currency_code: Joi.string(),
tax_rate: Joi.string(),
canceled_at: Joi.dateFilter(),
created_at: Joi.dateFilter(),
updated_at: Joi.dateFilter(),
})
}
export default Joi
@@ -11,9 +11,6 @@ describe("BaseService", () => {
id: "1234",
test1: ["123", "12", "1"],
test2: Not("this"),
rec: {
first: ["1", "2", "3"],
},
},
{
relations: ["1234"],
@@ -25,9 +22,6 @@ describe("BaseService", () => {
id: "1234",
test1: In(["123", "12", "1"]),
test2: Not("this"),
rec: {
first: In(["1", "2", "3"]),
},
},
relations: ["1234"],
})
+27 -2
View File
@@ -1,5 +1,5 @@
import { MedusaError } from "medusa-core-utils"
import { In, FindOperator, getManager } from "typeorm"
import { In, FindOperator, Raw } from "typeorm"
/**
* Common functionality for Services
@@ -29,7 +29,32 @@ class BaseService {
acc[key] = In([...value])
break
case value !== null && typeof value === "object":
acc[key] = build(value)
const subquery = []
Object.entries(value).map(([modifier, val]) => {
switch (modifier) {
case "lt":
subquery.push({ operator: "<", value: val })
break
case "gt":
subquery.push({ operator: ">", value: val })
break
case "lte":
subquery.push({ operator: "<=", value: val })
break
case "gte":
subquery.push({ operator: ">=", value: val })
break
}
})
acc[key] = Raw(
a =>
subquery
.map((s, index) => `${a} ${s.operator} :${index}`)
.join(" AND "),
subquery.map(s => s.value)
)
break
default:
acc[key] = value
@@ -47,8 +47,63 @@ const order = {
email: "test@example.com",
}
const roundingOrder = {
region: {
tax_code: "1234",
},
items: [
{
id: "rounding-item",
title: "Test",
allow_discounts: true,
variant: {
sku: "TEST",
},
unit_price: 31600,
quantity: 1,
},
],
shipping_total: 0,
shipping_methods: [
{
name: "standard",
price: 0,
},
],
discounts: [
{
code: "testdiscount",
rule: {
type: "percentage",
allocation: "total",
value: 50,
},
},
],
payment_method: {
id: "123",
},
tax_rate: 25,
currency_code: "DKK",
display_id: "1234",
id: "rounding",
shipping_address: {
first_name: "Test",
last_name: "Testson",
address_1: "Test",
address_2: "TEst",
postal_code: "1234",
country_code: "DK",
phone: "12345678",
},
email: "test@example.com",
}
const OrderService = {
retrieve: () => {
retrieve: (id) => {
if (id === "rounding") {
return Promise.resolve(roundingOrder)
}
return Promise.resolve(order)
},
update: () => {
@@ -60,17 +115,29 @@ const TotalsService = {
getTotal: () => {
return Promise.resolve(123)
},
getLineDiscounts: () => {
return Promise.resolve([])
getLineDiscounts: (o) => {
if (o.id === "rounding") {
return [
{
item: { id: "rounding-item", quantity: 1 },
amount: 15800,
},
]
}
return []
},
getShippingTotal: () => {
getShippingTotal: (o) => {
if (o.id === "rounding") {
return 0
}
return 12399
},
rounded: (value) => {
const decimalPlaces = 4
return Number(
Math.round(parseFloat(value + "e" + decimalPlaces)) + "e-" + decimalPlaces
)
return Math.round(value)
// const decimalPlaces = 4
// return Number(
// Math.round(parseFloat(value + "e" + decimalPlaces)) + "e-" + decimalPlaces
// )
},
}
@@ -146,6 +213,8 @@ describe("BrightpearlService", () => {
)
it("successfully builds sales order", async () => {
jest.clearAllMocks()
await bpService.createSalesOrder(order)
expect(mockCreateOrder).toHaveBeenCalledWith({
@@ -201,4 +270,132 @@ describe("BrightpearlService", () => {
})
})
})
describe("rounding", () => {
const bpService = new BrightpearlService(
{
orderService: OrderService,
totalsService: TotalsService,
oauthService: OAuthService,
regionService: RegionService,
},
{ account: "test" }
)
it("rounds correctly", async () => {
jest.clearAllMocks()
await bpService.createSalesOrder("rounding")
expect(mockCreateOrder).toHaveBeenCalledTimes(1)
expect(mockCreateOrder).toHaveBeenCalledWith({
currency: { code: "DKK" },
ref: "1234",
externalRef: "rounding",
channelId: "1",
installedIntegrationInstanceId: undefined,
statusId: "3",
customer: {
id: "12345",
address: {
addressFullName: "Test Testson",
addressLine1: "Test",
addressLine2: "TEst",
postalCode: "1234",
countryIsoCode: "DK",
telephone: "12345678",
email: "test@example.com",
},
},
delivery: {
shippingMethodId: 0,
address: {
addressFullName: "Test Testson",
addressLine1: "Test",
addressLine2: "TEst",
postalCode: "1234",
countryIsoCode: "DK",
telephone: "12345678",
email: "test@example.com",
},
},
rows: [
{
name: "Test",
net: 158,
tax: 39.5,
quantity: 1,
taxCode: "1234",
externalRef: "rounding-item",
nominalCode: "4000",
},
{
name: "Shipping: standard",
quantity: 1,
net: 0,
tax: 0,
taxCode: "1234",
nominalCode: "4040",
},
],
})
})
it("rounds correctly", async () => {
jest.clearAllMocks()
await bpService.createSalesOrder("rounding")
expect(mockCreateOrder).toHaveBeenCalledTimes(1)
expect(mockCreateOrder).toHaveBeenCalledWith({
currency: { code: "DKK" },
ref: "1234",
externalRef: "rounding",
channelId: "1",
installedIntegrationInstanceId: undefined,
statusId: "3",
customer: {
id: "12345",
address: {
addressFullName: "Test Testson",
addressLine1: "Test",
addressLine2: "TEst",
postalCode: "1234",
countryIsoCode: "DK",
telephone: "12345678",
email: "test@example.com",
},
},
delivery: {
shippingMethodId: 0,
address: {
addressFullName: "Test Testson",
addressLine1: "Test",
addressLine2: "TEst",
postalCode: "1234",
countryIsoCode: "DK",
telephone: "12345678",
email: "test@example.com",
},
},
rows: [
{
name: "Test",
net: 158,
tax: 39.5,
quantity: 1,
taxCode: "1234",
externalRef: "rounding-item",
nominalCode: "4000",
},
{
name: "Shipping: standard",
quantity: 1,
net: 0,
tax: 0,
taxCode: "1234",
nominalCode: "4040",
},
],
})
})
})
})
@@ -355,10 +355,10 @@ class BrightpearlService extends BaseService {
return row.externalRef === i.item_id
})
return {
net: this.totalsService_.rounded(
net: this.bpround_(
(parentRow.net / parentRow.quantity) * i.quantity
),
tax: this.totalsService_.rounded(
tax: this.bpround_(
(parentRow.tax / parentRow.quantity) * i.quantity
),
productId: parentRow.productId,
@@ -697,10 +697,10 @@ class BrightpearlService extends BaseService {
return row.externalRef === i.item_id
})
return {
net: this.totalsService_.rounded(
net: this.bpround_(
(parentRow.net / parentRow.quantity) * i.quantity
),
tax: this.totalsService_.rounded(
tax: this.bpround_(
(parentRow.tax / parentRow.quantity) * i.quantity
),
productId: parentRow.productId,
@@ -1096,9 +1096,16 @@ class BrightpearlService extends BaseService {
return { contactId: customer }
}
bpround_(n) {
const decimalPlaces = 4
return Number(
Math.round(parseFloat(n + "e" + decimalPlaces)) + "e-" + decimalPlaces
)
}
bpnum_(number, taxRate = 100) {
const bpNumber = number / 100
return this.totalsService_.rounded(bpNumber * (taxRate / 100))
return this.bpround_(bpNumber * (taxRate / 100))
}
}
@@ -381,6 +381,10 @@ class SendGridService extends NotificationService {
relations: ["region", "order"],
})
if (!giftCard.order) {
return
}
const taxRate = giftCard.region.tax_rate / 100
return {
@@ -1,9 +1,11 @@
import { default as authenticateCustomer } from "./authenticate-customer"
import { default as authenticate } from "./authenticate"
import { default as normalizeQuery } from "./normalized-query"
import { default as wrap } from "./await-middleware"
export default {
authenticate,
authenticateCustomer,
normalizeQuery,
wrap,
}
@@ -0,0 +1,16 @@
export default () => {
return (req, res, next) => {
const clean = Object.entries(req.query).reduce((acc, [key, val]) => {
if (Array.isArray(val) && val.length === 1) {
acc[key] = val[0].split(",")
} else {
acc[key] = val
}
return acc
}, {})
req.query = clean
next()
}
}
@@ -2,6 +2,26 @@ import jwt from "jsonwebtoken"
import { Validator } from "medusa-core-utils"
import config from "../../../../config"
/**
* @oas [post] /auth
* operationId: "PostAuth"
* summary: "Authenticate a User"
* description: "Logs a User in and authorizes them to manage Store settings."
* parameters:
* - (body) email=* {string} The User's email.
* - (body) password=* {string} The User's password.
* tags:
* - Auth
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* customer:
* $ref: "#/components/schemas/user"
*/
export default async (req, res) => {
const { body } = req
const schema = Validator.object().keys({
@@ -1,5 +1,22 @@
import passport from "passport"
/**
* @oas [get] /auth
* operationId: "GetAuth"
* summary: "Get Session"
* description: "Gets the currently logged in User."
* tags:
* - Auth
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* customer:
* $ref: "#/components/schemas/user"
*/
export default async (req, res) => {
const userService = req.scope.resolve("userService")
const user = await userService.retrieve(req.user.userId)
@@ -1,5 +1,38 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /collections
* operationId: "PostCollections"
* summary: "Create a Product Collection"
* description: "Creates a Product Collection."
* requestBody:
* content:
* application/json:
* schema:
* required:
* - title
* properties:
* title:
* type: string
* description: The title to identify the Collection by.
* handle:
* type: string
* description: An optional handle to be used in slugs, if none is provided we will kebab-case the title.
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Collection
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* collection:
* $ref: "#/components/schemas/product_collection"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
title: Validator.string().required(),
@@ -1,3 +1,28 @@
/**
* @oas [delete] /collections/{id}
* operationId: "DeleteCollectionsCollection"
* summary: "Delete a Product Collection"
* description: "Deletes a Product Collection."
* parameters:
* - (path) id=* {string} The id of the Collection.
* tags:
* - Collection
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Collection
* 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,3 +1,23 @@
/**
* @oas [get] /collections/{id}
* operationId: "GetCollectionsCollection"
* summary: "Retrieve a Product Collection"
* description: "Retrieves a Product Collection."
* parameters:
* - (path) id=* {string} The id of the Product Collection
* tags:
* - Collection
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* collection:
* $ref: "#/components/schemas/product_collection"
*/
export default async (req, res) => {
const { id } = req.params
try {
@@ -1,5 +1,22 @@
import { defaultFields, defaultRelations } from "."
/**
* @oas [get] /collections
* operationId: "GetCollections"
* summary: "List Product Collections"
* description: "Retrieve a list of Product Collection."
* tags:
* - Collection
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* collection:
* $ref: "#/components/schemas/product_collection"
*/
export default async (req, res) => {
try {
const selector = {}
@@ -1,5 +1,38 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /collections/{id}
* operationId: "PostCollectionsCollection"
* summary: "Update a Product Collection"
* description: "Updates a Product Collection."
* parameters:
* - (path) id=* {string} The id of the Collection.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* type: string
* description: The title to identify the Collection by.
* handle:
* type: string
* description: An optional handle to be used in slugs, if none is provided we will kebab-case the title.
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Collection
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* properties:
* collection:
* $ref: "#/components/schemas/product_collection"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,5 +1,27 @@
import { Validator, MedusaError } from "medusa-core-utils"
/**
* @oas [post] /customers
* operationId: "PostCustomers"
* summary: "Create a Customer"
* description: "Creates a Customer."
* parameters:
* - (body) email=* {string} The Customer's email address.
* - (body) first_name=* {string} The Customer's first name.
* - (body) last_name=* {string} The Customer's last name.
* - (body) phone {string} The Customer's phone number.
* tags:
* - Customer
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* customer:
* $ref: "#/components/schemas/customer"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
email: Validator.string()
@@ -1,3 +1,22 @@
/**
* @oas [get] /customers/{id}
* operationId: "GetCustomersCustomer"
* summary: "Retrieve a Customer"
* description: "Retrieves a Customer."
* parameters:
* - (path) id=* {string} The id of the Customer.
* tags:
* - Customer
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* customer:
* $ref: "#/components/schemas/customer"
*/
export default async (req, res) => {
const { id } = req.params
try {
@@ -1,3 +1,20 @@
/**
* @oas [get] /customers
* operationId: "GetCustomers"
* summary: "List Customers"
* description: "Retrieves a list of Customers."
* tags:
* - Customer
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* customer:
* $ref: "#/components/schemas/customer"
*/
export default async (req, res) => {
try {
const customerService = req.scope.resolve("customerService")
@@ -1,5 +1,38 @@
import { Validator, MedusaError } from "medusa-core-utils"
/**
* @oas [post] /customers/{id}
* operationId: "PostCustomersCustomer"
* summary: "Update a Customer"
* description: "Updates a Customer."
* parameters:
* - (path) id=* {string} The id of the Customer.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* first_name:
* type: string
* description: The Customer's first name.
* last_name:
* type: string
* description: The Customer's last name.
* phone:
* description: The Customer's phone number.
* type: object
* tags:
* - Customer
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* customer:
* $ref: "#/components/schemas/customer"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,5 +1,25 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /discounts/{id}/regions/{region_id}
* operationId: "PostDiscountsDiscountRegionsRegion"
* summary: "Adds Region availability"
* description: "Adds a Region to the list of Regions that a Discount can be used in."
* parameters:
* - (path) id=* {string} The id of the Discount.
* - (path) region_id=* {string} The id of the Region.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, region_id } = req.params
try {
@@ -1,5 +1,25 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /discounts/{id}/products/{product_id}
* operationId: "PostDiscountsDiscountProductsProduct"
* summary: "Adds Product availability"
* description: "Adds a Product to the list of Products that a Discount can be used for."
* parameters:
* - (path) id=* {string} The id of the Discount.
* - (path) product_id=* {string} The id of the Product.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, variant_id } = req.params
@@ -1,5 +1,56 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /discounts
* operationId: "PostDiscounts"
* summary: "Creates a Discount"
* description: "Creates a Discount with a given set of rules that define how the Discount behaves."
* requestBody:
* content:
* application/json:
* schema:
* properties:
* code:
* type: string
* description: A unique code that will be used to redeem the Discount
* is_dynamic:
* type: string
* description: Whether the Discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated codes that all have to follow a common set of rules.
* rule:
* description: The Discount Rule that defines how Discounts are calculated
* oneOf:
* - $ref: "#/components/schemas/discount_rule"
* is_disabled:
* type: boolean
* description: Whether the Discount code is disabled on creation. You will have to enable it later to make it available to Customers.
* starts_at:
* type: string
* format: date-time
* description: The time at which the Discount should be available.
* ends_at:
* type: string
* format: date-time
* description: The time at which the Discount should no longer be available.
* regions:
* description: A list of Region ids representing the Regions in which the Discount can be used.
* type: array
* items:
* type: string
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
code: Validator.string().required(),
@@ -1,5 +1,26 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /discounts/{id}/dynamic-codes
* operationId: "PostDiscountsDiscountDynamicCodes"
* summary: "Create a dynamic Discount code"
* description: "Creates a unique code that can map to a parent Discount. This is useful if you want to automatically generate codes with the same behaviour."
* parameters:
* - (path) id=* {string} The id of the Discount to create the dynamic code from."
* - (body) code=* {string} The unique code that will be used to redeem the Discount.
* - (body) metadata {object} An optional set of key-value paris to hold additional information.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id } = req.params
@@ -1,3 +1,28 @@
/**
* @oas [delete] /discounts/{id}
* operationId: "DeleteDiscountsDiscount"
* summary: "Delete a Discount"
* description: "Deletes a Discount."
* parameters:
* - (path) id=* {string} The id of the Discount
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Discount
* object:
* type: string
* description: The type of the object that was deleted.
* deleted:
* type: boolean
*/
export default async (req, res) => {
const { discount_id } = req.params
@@ -1,3 +1,23 @@
/**
* @oas [delete] /discounts/{id}/dynamic-codes/{code}
* operationId: "DeleteDiscountsDiscountDynamicCodesCode"
* summary: "Delete a dynamic code"
* description: "Deletes a dynamic code from a Discount."
* parameters:
* - (path) id=* {string} The id of the Discount
* - (path) code=* {string} The id of the Discount
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, code } = req.params
@@ -1,5 +1,24 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /discounts/{id}
* operationId: "GetDiscountsDiscount"
* summary: "Retrieve a Discount"
* description: "Retrieves a Discount"
* parameters:
* - (path) id=* {string} The id of the Discount
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id } = req.params
try {
@@ -1,5 +1,22 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /discounts
* operationId: "GetDiscounts"
* summary: "List Discounts"
* description: "Retrieves a list of Discounts"
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
try {
const discountService = req.scope.resolve("discountService")
@@ -1,5 +1,25 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [delete] /discounts/{id}/regions/{region_id}
* operationId: "DeleteDiscountsDiscountRegionsRegion"
* summary: "Remove Region availability"
* description: "Removes a Region from the list of Regions that a Discount can be used in."
* parameters:
* - (path) id=* {string} The id of the Discount.
* - (path) region_id=* {string} The id of the Region.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, region_id } = req.params
@@ -1,5 +1,25 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /discounts/{id}/products/{product_id}
* operationId: "DeleteDiscountsDiscountProductsProduct"
* summary: "Remove Product availability"
* description: "Removes a Product from the list of Products that a Discount can be used for."
* parameters:
* - (path) id=* {string} The id of the Discount.
* - (path) product_id=* {string} The id of the Product.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, variant_id } = req.params
@@ -1,6 +1,56 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /discounts/{id}
* operationId: "PostDiscountsDiscount"
* summary: "Update a Discount"
* description: "Updates a Discount with a given set of rules that define how the Discount behaves."
* parameters:
* - (path) id=* {string} The id of the Discount.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* code:
* type: string
* description: A unique code that will be used to redeem the Discount
* is_dynamic:
* type: string
* description: Whether the Discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated codes that all have to follow a common set of rules.
* rule:
* description: The Discount Rule that defines how Discounts are calculated
* oneOf:
* - $ref: "#/components/schemas/discount_rule"
* is_disabled:
* type: boolean
* description: Whether the Discount code is disabled on creation. You will have to enable it later to make it available to Customers.
* starts_at:
* type: string
* format: date-time
* description: The time at which the Discount should be available.
* ends_at:
* type: string
* format: date-time
* description: The time at which the Discount should no longer be available.
* regions:
* description: A list of Region ids representing the Regions in which the Discount can be used.
* type: array
* items:
* type: string
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id } = req.params
const schema = Validator.object().keys({
@@ -1,6 +1,46 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /gift-cards
* operationId: "PostGiftCards"
* summary: "Create a Gift Card"
* description: "Creates a Gift Card that can redeemed by its unique code. The Gift Card is only valid within 1 region."
* requestBody:
* content:
* application/json:
* schema:
* properties:
* value:
* type: integer
* description: The value (excluding VAT) that the Gift Card should represent.
* is_disabled:
* type: boolean
* description: Whether the Gift Card is disabled on creation. You will have to enable it later to make it available to Customers.
* ends_at:
* type: string
* format: date-time
* description: The time at which the Gift Card should no longer be available.
* region_id:
* description: The id of the Region in which the Gift Card can be used.
* type: array
* items:
* type: string
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Gift Card
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* gift_card:
* $ref: "#/components/schemas/gift_card"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
value: Validator.number()
@@ -20,9 +60,12 @@ export default async (req, res) => {
try {
const giftCardService = req.scope.resolve("giftCardService")
await giftCardService.create(value)
const newly = await giftCardService.create({
...value,
balance: value.value,
})
const giftCard = await giftCardService.retrieve(id, {
const giftCard = await giftCardService.retrieve(newly.id, {
select: defaultFields,
relations: defaultRelations,
})
@@ -1,3 +1,28 @@
/**
* @oas [delete] /gift-cards/{id}
* operationId: "DeleteGiftCardsGiftCard"
* summary: "Delete a Gift Card"
* description: "Deletes a Gift Card"
* parameters:
* - (path) id=* {string} The id of the Gift Card to delete.
* tags:
* - Gift Card
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Gift Card
* 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,5 +1,24 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /gift-cards/{id}
* operationId: "GetGiftCardsGiftCard"
* summary: "Retrieve a Gift Card"
* description: "Retrieves a Gift Card."
* parameters:
* - (path) id=* {string} The id of the Gift Card.
* tags:
* - Gift Card
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* gift_card:
* $ref: "#/components/schemas/gift_card"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,5 +1,24 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /gift-cards
* operationId: "GetGiftCards"
* summary: "List Gift Cards"
* description: "Retrieves a list of Gift Cards."
* tags:
* - Gift Card
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* gift_cards:
* type: array
* items:
* $ref: "#/components/schemas/gift_card"
*/
export default async (req, res) => {
try {
const selector = {}
@@ -1,5 +1,47 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /gift-cards/{id}
* operationId: "PostGiftCardsGiftCard"
* summary: "Create a Gift Card"
* description: "Creates a Gift Card that can redeemed by its unique code. The Gift Card is only valid within 1 region."
* parameters:
* - (path) id=* {string} The id of the Gift Card.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* balance:
* type: integer
* description: The value (excluding VAT) that the Gift Card should represent.
* is_disabled:
* type: boolean
* description: Whether the Gift Card is disabled on creation. You will have to enable it later to make it available to Customers.
* ends_at:
* type: string
* format: date-time
* description: The time at which the Gift Card should no longer be available.
* region_id:
* description: The id of the Region in which the Gift Card can be used.
* type: array
* items:
* type: string
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Gift Card
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* gift_card:
* $ref: "#/components/schemas/gift_card"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,25 @@
import _ from "lodash"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [get] /notifications
* operationId: "GetNotifications"
* summary: "List Notifications"
* description: "Retrieves a list of Notifications."
* tags:
* - Notification
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* notifications:
* type: array
* items:
* $ref: "#/components/schemas/notification"
*/
export default async (req, res) => {
try {
const notificationService = req.scope.resolve("notificationService")
@@ -1,6 +1,25 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /notifications/{id}/resend
* operationId: "PostNotificationsNotificationResend"
* summary: "Resend Notification"
* description: "Resends a previously sent notifications, with the same data but optionally to a different address"
* parameters:
* - (path) id=* {string} The id of the Notification
* tags:
* - Notification
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* notification:
* $ref: "#/components/schemas/notification"
*/
export default async (req, res) => {
const { id } = req.params
@@ -2,6 +2,28 @@ import _ from "lodash"
import { Validator, MedusaError } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /orders/{id}/shipping-methods
* operationId: "PostOrdersOrderShippingMethods"
* summary: "Add a Shipping Method"
* description: "Adds a Shipping Method to an Order. If another Shipping Method exists with the same Shipping Profile, the previous Shipping Method will be replaced."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (body) price=* {integer} The price (excluding VAT) that should be charged for the Shipping Method
* - (body) option_id=* {string} The id of the Shipping Option to create the Shipping Method from.
* - (body) data=* {object} The data required for the Shipping Option to create a Shipping Method. This will depend on the Fulfillment Provider.
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,3 +1,22 @@
/**
* @oas [post] /orders/{id}/cancel
* operationId: "PostOrdersOrderCancel"
* summary: "Cancel an Order"
* description: "Registers an Order as canceled. This triggers a flow that will cancel any created Fulfillments and Payments, may fail if the Payment or Fulfillment Provider is unable to cancel the Payment/Fulfillment."
* parameters:
* - (path) id=* {string} The id of the Order.
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,5 +1,24 @@
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/capture
* operationId: "PostOrdersOrderCapture"
* summary: "Capture an Order"
* description: "Captures all the Payments associated with an Order."
* parameters:
* - (path) id=* {string} The id of the Order.
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,39 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /orders/{id}/claims/{claim_id}/shipments
* operationId: "PostOrdersOrderClaimsClaimShipments"
* summary: "Create Claim Shipment"
* description: "Registers a Claim Fulfillment as shipped."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) claim_id=* {string} The id of the Claim.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* fulfillment_id:
* description: The id of the Fulfillment.
* type: string
* tracking_numbers:
* description: The tracking numbers for the shipment.
* type: array
* items:
* type: string
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, claim_id } = req.params
@@ -1,6 +1,108 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /order/{id}/claims
* operationId: "PostOrdersOrderClaims"
* summary: "Create a Claim"
* description: "Creates a Claim."
* parameters:
* - (path) id=* {string} The id of the Order.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* type:
* description: "The type of the Claim. This will determine how the Claim is treated: `replace` Claims will result in a Fulfillment with new items being created, while a `refund` Claim will refund the amount paid for the claimed items."
* type: string
* enum:
* - replace
* - refund
* claim_items:
* description: The Claim Items that the Claim will consist of.
* type: array
* items:
* properties:
* item_id:
* description: The id of the Line Item that will be claimed.
* type: string
* quantity:
* description: The number of items that will be returned
* type: integer
* note:
* description: Short text describing the Claim Item in further detail.
* type: string
* reason:
* description: The reason for the Claim
* type: string
* enum:
* - missing_item
* - wrong_item
* - production_failure
* - other
* tags:
* description: A list o tags to add to the Claim Item
* type: array
* items:
* type: string
* images:
* description: A list of image URL's that will be associated with the Claim
* items:
* type: string
* return_shipping:
* description: Optional details for the Return Shipping Method, if the items are to be sent back.
* type: object
* properties:
* option_id:
* type: string
* description: The id of the Shipping Option to create the Shipping Method from.
* price:
* type: integer
* description: The price to charge for the Shipping Method.
* additional_items:
* description: The new items to send to the Customer when the Claim type is Replace.
* type: array
* items:
* properties:
* variant_id:
* description: The id of the Product Variant to ship.
* type: string
* quantity:
* description: The quantity of the Product Variant to ship.
* type: integer
* shipping_methods:
* description: The Shipping Methods to send the additional Line Items with.
* type: array
* items:
* properties:
* id:
* description: The id of an existing Shipping Method
* type: string
* option_id:
* description: The id of the Shipping Option to create a Shipping Method from
* type: string
* price:
* description: The price to charge for the Shipping Method
* type: integer
* refund_amount:
* description: The amount to refund the Customer when the Claim type is `refund`.
* type: integer
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,44 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/fulfillments
* operationId: "PostOrdersOrderFulfillments"
* summary: "Create a Fulfillment"
* description: "Creates a Fulfillment of an Order - will notify Fulfillment Providers to prepare a shipment."
* parameters:
* - (path) id=* {string} The id of the Order.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* items:
* description: The Line Items to include in the Fulfillment.
* type: array
* items:
* properties:
* item_id:
* description: The id of Line Item to fulfill.
* type: string
* quantity:
* description: The quantity of the Line Item to fulfill.
* type: integer
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,38 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/shipment
* operationId: "PostOrdersOrderShipment"
* summary: "Create a Shipment"
* description: "Registers a Fulfillment as shipped."
* parameters:
* - (path) id=* {string} The id of the Order.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* fulfillment_id:
* description: The id of the Fulfillment.
* type: string
* tracking_numbers:
* description: The tracking numbers for the shipment.
* type: array
* items:
* type: string
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,39 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /orders/{id}/swaps/{swap_id}/shipments
* operationId: "PostOrdersOrderSwapsSwapShipments"
* summary: "Create Swap Shipment"
* description: "Registers a Swap Fulfillment as shipped."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) swap_id=* {string} The id of the Swap.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* fulfillment_id:
* description: The id of the Fulfillment.
* type: string
* tracking_numbers:
* description: The tracking numbers for the shipment.
* type: array
* items:
* type: string
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, swap_id } = req.params
@@ -1,6 +1,62 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /order/{id}/swaps
* operationId: "PostOrdersOrderSwaps"
* summary: "Create a Swap"
* description: "Creates a Swap. Swaps are used to handle Return of previously purchased goods and Fulfillment of replacements simultaneously."
* parameters:
* - (path) id=* {string} The id of the Swap.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* return_items:
* description: The Line Items to return as part of the Swap.
* type: array
* items:
* properties:
* item_id:
* description: The id of the Line Item that will be claimed.
* type: string
* quantity:
* description: The number of items that will be returned
* type: integer
* return_shipping:
* description: How the Swap will be returned.
* type: object
* properties:
* option_id:
* type: string
* description: The id of the Shipping Option to create the Shipping Method from.
* price:
* type: integer
* description: The price to charge for the Shipping Method.
* additional_items:
* description: The new items to send to the Customer.
* type: array
* items:
* properties:
* variant_id:
* description: The id of the Product Variant to ship.
* type: string
* quantity:
* description: The quantity of the Product Variant to ship.
* type: integer
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,3 +1,23 @@
/**
* @oas [delete] /order/{id}/metadata/{key}
* operationId: "DeleteOrdersOrderMetadataKey"
* summary: "Delete Metadata"
* description: "Deletes a metadata key."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) key=* {string} The metadata key.
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, key } = req.params
@@ -1,6 +1,34 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/claims/{claim_id}/fulfillments
* operationId: "PostOrdersOrderClaimsClaimFulfillments"
* summary: "Create a Claim Fulfillment"
* description: "Creates a Fulfillment for a Claim."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) claim_id=* {string} The id of the Claim.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, claim_id } = req.params
@@ -1,6 +1,34 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/swaps/{swap_id}/fulfillments
* operationId: "PostOrdersOrderSwapsSwapFulfillments"
* summary: "Create a Swap Fulfillment"
* description: "Creates a Fulfillment for a Swap."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) swap_id=* {string} The id of the Swap.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, swap_id } = req.params
@@ -1,5 +1,24 @@
import { defaultRelations, defaultFields } from "./"
/**
* @oas [get] /orders/{id}
* operationId: "GetOrdersOrder"
* summary: "Retrieve an Order"
* description: "Retrieves an Order"
* parameters:
* - (path) id=* {string} The id of the Order.
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -9,7 +9,11 @@ export default app => {
/**
* List orders
*/
route.get("/", middlewares.wrap(require("./list-orders").default))
route.get(
"/",
middlewares.normalizeQuery(),
middlewares.wrap(require("./list-orders").default)
)
/**
* Get an order
@@ -282,3 +286,20 @@ export const allowedRelations = [
"swaps.return_order",
"swaps.additional_items",
]
export const filterableFields = [
"id",
"status",
"fulfillment_status",
"payment_status",
"display_id",
"cart_id",
"customer_id",
"email",
"region_id",
"currency_code",
"tax_rate",
"canceled_at",
"created_at",
"updated_at",
]
@@ -1,8 +1,33 @@
import _ from "lodash"
import { Not } from "typeorm"
import { defaultRelations, defaultFields } from "./"
import { defaultRelations, defaultFields, filterableFields } from "./"
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [get] /orders
* operationId: "GetOrders"
* summary: "List Orders"
* description: "Retrieves an list of Orders"
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const schema = Validator.orderFilter()
const { value, error } = schema.validate(req.query)
if (error) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const orderService = req.scope.resolve("orderService")
@@ -30,6 +55,8 @@ export default async (req, res) => {
let includeFields = []
if ("fields" in req.query) {
includeFields = req.query.fields.split(",")
// Ensure created_at is included, since we are sorting on this
includeFields.push("created_at")
}
let expandFields = []
@@ -37,17 +64,9 @@ export default async (req, res) => {
expandFields = req.query.expand.split(",")
}
if ("new" in req.query) {
selector = {
payment_status: Not("captured"),
fulfillment_status: Not("shipped"),
}
}
if ("requires_more" in req.query) {
selector = {
payment_status: Not("captured"),
fulfillment_status: Not("shipped"),
for (const k of filterableFields) {
if (k in value) {
selector[k] = value[k]
}
}
@@ -64,8 +83,12 @@ export default async (req, res) => {
listConfig
)
let data = orders
const fields = [...includeFields, ...expandFields]
const data = orders.map(o => _.pick(o, fields))
if (fields.length) {
data = orders.map(o => _.pick(o, fields))
}
res.json({ orders: data, count, offset, limit })
} catch (error) {
@@ -1,4 +1,25 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /orders/{id}/swaps/{swap_id}/process-payment
* operationId: "PostOrdersOrderSwapsSwapProcessPayment"
* summary: "Process a Swap difference"
* description: "When there are differences between the returned and shipped Products in a Swap, the difference must be processed. Either a Refund will be issued or a Payment will be captured."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) swap_id=* {string} The id of the Swap.
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, swap_id } = req.params
@@ -1,6 +1,45 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/returns/{return_id}/receive
* operationId: "PostOrdersOrderReturnsReturnReceive"
* summary: "Receive a Return"
* description: "Registers a Return as received."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) return_id=* {string} The id of the Return.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* items:
* description: The Line Items that have been received.
* type: array
* items:
* properties:
* item_id:
* description: The id of the Line Item.
* type: string
* quantity:
* description: The quantity of the Line Item.
* type: integer
* refund:
* description: The amount to refund.
* type: integer
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, return_id } = req.params
@@ -1,6 +1,42 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /orders/{id}/swaps/{swap_id}/receive
* operationId: "PostOrdersOrderSwapsSwapReceive"
* summary: "Receive a Swap"
* description: "Registers a Swap as received."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) swap_id=* {string} The id of the Swap.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* items:
* description: The Line Items that have been received.
* type: array
* items:
* properties:
* item_id:
* description: The id of the Line Item.
* type: string
* quantity:
* description: The quantity of the Line Item.
* type: integer
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, swap_id } = req.params
@@ -1,6 +1,42 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/refunds
* operationId: "PostOrdersOrderRefunds"
* summary: "Create a Refund"
* description: "Issues a Refund."
* parameters:
* - (path) id=* {string} The id of the Order.
* requestBody:
* content:
* application/json:
* schema:
* required:
* - amount
* - reason
* properties:
* amount:
* description: The amount to refund.
* type: integer
* reason:
* description: The reason for the Refund.
* type: string
* note:
* description: A not with additional details about the Refund.
* type: string
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
const schema = Validator.object().keys({
@@ -1,6 +1,57 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /orders/{id}/returns
* operationId: "PostOrdersOrderReturns"
* summary: "Request a Return"
* description: "Requests a Return. If applicable a return label will be created and other plugins notified."
* parameters:
* - (path) id=* {string} The id of the Order.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* items:
* description: The Line Items that will be returned.
* type: array
* items:
* properties:
* item_id:
* description: The id of the Line Item.
* type: string
* quantity:
* description: The quantity of the Line Item.
* type: integer
* return_shipping:
* description: The Shipping Method to be used to handle the return shipment.
* type: object
* properties:
* option_id:
* type: string
* description: The id of the Shipping Option to create the Shipping Method from.
* price:
* type: integer
* description: The price to charge for the Shipping Method.
* receive_now:
* description: A flag to indicate if the Return should be registerd as received immediately.
* type: boolean
* refund:
* description: The amount to refund.
* type: integer
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,82 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /order/{id}/claims/{claim_id}
* operationId: "PostOrdersOrderClaimsClaim"
* summary: "Update a Claim"
* description: "Updates a Claim."
* parameters:
* - (path) id=* {string} The id of the Order.
* - (path) claim_id=* {string} The id of the Claim.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* claim_items:
* description: The Claim Items that the Claim will consist of.
* type: array
* items:
* properties:
* id:
* description: The id of the Claim Item.
* type: string
* item_id:
* description: The id of the Line Item that will be claimed.
* type: string
* quantity:
* description: The number of items that will be returned
* type: integer
* note:
* description: Short text describing the Claim Item in further detail.
* type: string
* reason:
* description: The reason for the Claim
* type: string
* enum:
* - missing_item
* - wrong_item
* - production_failure
* - other
* tags:
* description: A list o tags to add to the Claim Item
* type: array
* items:
* type: string
* images:
* description: A list of image URL's that will be associated with the Claim
* items:
* type: string
* shipping_methods:
* description: The Shipping Methods to send the additional Line Items with.
* type: array
* items:
* properties:
* id:
* description: The id of an existing Shipping Method
* type: string
* option_id:
* description: The id of the Shipping Option to create a Shipping Method from
* type: string
* price:
* description: The price to charge for the Shipping Method
* type: integer
* metadata:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* tags:
* - Order
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* order:
* $ref: "#/components/schemas/order"
*/
export default async (req, res) => {
const { id, claim_id } = req.params
@@ -1,6 +1,33 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /products/{id}/options
* operationId: "PostProductsProductOptions"
* summary: "Add an Option"
* description: "Adds a Product Option to a Product"
* parameters:
* - (path) id=* {string} The id of the Product.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* description: "The title the Product Option will be identified by i.e. \"Size\""
* type: string
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,183 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "."
/**
* @oas [post] /products
* operationId: "PostProducts"
* summary: "Create a Product"
* description: "Creates a Product"
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* description: "The title of the Product"
* type: string
* subtitle:
* description: "The subtitle of the Product"
* type: string
* description:
* description: "A description of the Product."
* type: string
* is_giftcard:
* description: A flag to indicate if the Product represents a Gift Card. Purchasing Products with this flag set to `true` will result in a Gift Card being created.
* type: boolean
* images:
* description: Images of the Product.
* type: array
* items:
* type: string
* thumbnail:
* description: The thumbnail to use for the Product.
* type: string
* handle:
* description: A unique handle to identify the Product by.
* type: string
* type:
* description: The Product Type to associate the Product with.
* type: object
* properties:
* value:
* description: The value of the Product Type.
* type: string
* collection_id:
* description: The id of the Collection the Product should belong to.
* type: string
* tags:
* description: Tags to associate the Product with.
* type: array
* items:
* properties:
* id:
* description: The id of an existing Tag.
* type: string
* value:
* description: The value of the Tag, these will be upserted.
* type: string
* options:
* description: The Options that the Product should have. These define on which properties the Product's Product Variants will differ.
* type: array
* items:
* properties:
* title:
* description: The title to identify the Product Option by.
* type: string
* variants:
* description: A list of Product Variants to create with the Product.
* type: array
* items:
* properties:
* title:
* description: The title to identify the Product Variant by.
* type: string
* sku:
* description: The unique SKU for the Product Variant.
* type: string
* ean:
* description: The EAN number of the item.
* type: string
* upc:
* description: The UPC number of the item.
* type: string
* barcode:
* description: A generic GTIN field for the Product Variant.
* type: string
* hs_code:
* description: The Harmonized System code for the Product Variant.
* type: string
* inventory_quantity:
* description: The amount of stock kept for the Product Variant.
* type: integer
* allow_backorder:
* description: Whether the Product Variant can be purchased when out of stock.
* type: boolean
* manage_inventory:
* description: Whether Medusa should keep track of the inventory for this Product Variant.
* type: boolean
* weight:
* description: The wieght of the Product Variant.
* type: string
* length:
* description: The length of the Product Variant.
* type: string
* height:
* description: The height of the Product Variant.
* type: string
* width:
* description: The width of the Product Variant.
* type: string
* origin_country:
* description: The country of origin of the Product Variant.
* type: string
* mid_code:
* description: The Manufacturer Identification code for the Product Variant.
* type: string
* material:
* description: The material composition of the Product Variant.
* type: string
* metadata:
* description: An optional set of key-value pairs with additional information.
* type: object
* prices:
* type: array
* items:
* properties:
* region_id:
* description: The id of the Region for which the price is used.
* type: string
* currency_code:
* description: The 3 character ISO currency code for which the price will be used.
* type: string
* amount:
* description: The amount to charge for the Product Variant.
* type: integer
* sale_amount:
* description: The sale amount to charge for the Product Variant.
* type: integer
* options:
* type: array
* items:
* properties:
* value:
* description: The value to give for the Product Option at the same index in the Product's `options` field.
* type: string
* weight:
* description: The wieght of the Product.
* type: string
* length:
* description: The length of the Product.
* type: string
* height:
* description: The height of the Product.
* type: string
* width:
* description: The width of the Product.
* type: string
* origin_country:
* description: The country of origin of the Product.
* type: string
* mid_code:
* description: The Manufacturer Identification code for the Product.
* type: string
* material:
* description: The material composition of the Product.
* type: string
* metadata:
* description: An optional set of key-value pairs with additional information.
* type: object
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
title: Validator.string().required(),
@@ -1,6 +1,107 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /products/{id}/variants
* operationId: "PostProductsProductVariants"
* summary: "Create a Product Variant"
* description: "Creates a Product Variant. Each Product Variant must have a unique combination of Product Option Values."
* parameters:
* - (path) id=* {string} The id of the Product.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* description: The title to identify the Product Variant by.
* type: string
* sku:
* description: The unique SKU for the Product Variant.
* type: string
* ean:
* description: The EAN number of the item.
* type: string
* upc:
* description: The UPC number of the item.
* type: string
* barcode:
* description: A generic GTIN field for the Product Variant.
* type: string
* hs_code:
* description: The Harmonized System code for the Product Variant.
* type: string
* inventory_quantity:
* description: The amount of stock kept for the Product Variant.
* type: integer
* allow_backorder:
* description: Whether the Product Variant can be purchased when out of stock.
* type: boolean
* manage_inventory:
* description: Whether Medusa should keep track of the inventory for this Product Variant.
* type: boolean
* weight:
* description: The wieght of the Product Variant.
* type: string
* length:
* description: The length of the Product Variant.
* type: string
* height:
* description: The height of the Product Variant.
* type: string
* width:
* description: The width of the Product Variant.
* type: string
* origin_country:
* description: The country of origin of the Product Variant.
* type: string
* mid_code:
* description: The Manufacturer Identification code for the Product Variant.
* type: string
* material:
* description: The material composition of the Product Variant.
* type: string
* metadata:
* description: An optional set of key-value pairs with additional information.
* type: object
* prices:
* type: array
* items:
* properties:
* region_id:
* description: The id of the Region for which the price is used.
* type: string
* currency_code:
* description: The 3 character ISO currency code for which the price will be used.
* type: string
* amount:
* description: The amount to charge for the Product Variant.
* type: integer
* sale_amount:
* description: The sale amount to charge for the Product Variant.
* type: integer
* options:
* type: array
* items:
* properties:
* option_id:
* description: The id of the Product Option to set the value for.
* type: string
* value:
* description: The value to give for the Product Option.
* type: string
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,5 +1,33 @@
import { defaultRelations, defaultFields } from "."
/**
* @oas [delete] /products/{id}/options/{option_id}
* operationId: "DeleteProductsProductOptionsOption"
* summary: "Delete a Product Option"
* description: "Deletes a Product Option. Before a Product Option can be deleted all Option Values for the Product Option must be the same. You may, for example, have to delete some of your variants prior to deleting the Product Option"
* parameters:
* - (path) id=* {string} The id of the Product.
* - (path) option_id=* {string} The id of the Product Option.
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Product Option
* object:
* type: string
* description: The type of the object that was deleted.
* deleted:
* type: boolean
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id, option_id } = req.params
@@ -1,3 +1,28 @@
/**
* @oas [delete] /products/{id}
* operationId: "DeleteProductsProduct"
* summary: "Delete a Product"
* description: "Deletes a Product and it's associated Product Variants."
* parameters:
* - (path) id=* {string} The id of the Product.
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Product.
* 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,4 +1,31 @@
import { defaultRelations, defaultFields } from "."
/**
* @oas [delete] /products/{id}/variants/{variant_id}
* operationId: "DeleteProductsProductVariantsVariant"
* summary: "Delete a Product Variant"
* description: "Deletes a Product Variant."
* parameters:
* - (path) id=* {string} The id of the Product.
* - (path) variant_id=* {string} The id of the Product Variant.
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Product Variant.
* object:
* type: string
* description: The type of the object that was deleted.
* deleted:
* type: boolean
*/
export default async (req, res) => {
const { id, variant_id } = req.params
@@ -1,5 +1,24 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /products/{id}
* operationId: "GetProductsProduct"
* summary: "Retrieve a Product"
* description: "Retrieves a Product."
* parameters:
* - (path) id=* {string} The id of the Product.
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,3 +1,24 @@
/**
* @oas [get] /products/{id}/variants
* operationId: "GetProductsProductVariants"
* summary: "List a Product's Product Variants"
* description: "Retrieves a list of the Product Variants associated with a Product."
* parameters:
* - (path) id=* {string} The id of the Product.
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* variants:
* type: array
* items:
* $ref: "#/components/schemas/product_variant"
*/
export default async (req, res) => {
const { id } = req.params
@@ -1,6 +1,34 @@
import _ from "lodash"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /products
* operationId: "GetProducts"
* summary: "List Product"
* description: "Retrieves a list of Product"
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* count:
* description: The number of Products.
* type: integer
* offset:
* description: The offset of the Product query.
* type: integer
* limit:
* description: The limit of the Product query.
* type: integer
* products:
* type: array
* items:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
try {
const productService = req.scope.resolve("productService")
@@ -1,3 +1,22 @@
/**
* @oas [get] /products/types
* operationId: "GetProductsTypes"
* summary: "List Product Types"
* description: "Retrieves a list of Product Types."
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* types:
* type: array
* items:
* $ref: "#/components/schemas/product_type"
*/
export default async (req, res) => {
try {
const productService = req.scope.resolve("productService")
@@ -1,6 +1,34 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /products/{id}/options/{option_id}
* operationId: "PostProductsProductOptionsOption"
* summary: "Update a Product Option."
* description: "Updates a Product Option"
* parameters:
* - (path) id=* {string} The id of the Product.
* - (path) option_id=* {string} The id of the Product Option.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* description: "The title of the Product Option"
* type: string
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id, option_id } = req.params
@@ -1,6 +1,185 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "."
/**
* @oas [post] /products/{id}
* operationId: "PostProductsProduct"
* summary: "Update a Product"
* description: "Updates a Product"
* parameters:
* - (path) id=* {string} The id of the Product.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* description: "The title of the Product"
* type: string
* subtitle:
* description: "The subtitle of the Product"
* type: string
* description:
* description: "A description of the Product."
* type: string
* is_giftcard:
* description: A flag to indicate if the Product represents a Gift Card. Purchasing Products with this flag set to `true` will result in a Gift Card being created.
* type: boolean
* images:
* description: Images of the Product.
* type: array
* items:
* type: string
* thumbnail:
* description: The thumbnail to use for the Product.
* type: string
* handle:
* description: A unique handle to identify the Product by.
* type: string
* type:
* description: The Product Type to associate the Product with.
* type: object
* properties:
* value:
* description: The value of the Product Type.
* type: string
* collection_id:
* description: The id of the Collection the Product should belong to.
* type: string
* tags:
* description: Tags to associate the Product with.
* type: array
* items:
* properties:
* id:
* description: The id of an existing Tag.
* type: string
* value:
* description: The value of the Tag, these will be upserted.
* type: string
* options:
* description: The Options that the Product should have. These define on which properties the Product's Product Variants will differ.
* type: array
* items:
* properties:
* title:
* description: The title to identify the Product Option by.
* type: string
* variants:
* description: A list of Product Variants to create with the Product.
* type: array
* items:
* properties:
* title:
* description: The title to identify the Product Variant by.
* type: string
* sku:
* description: The unique SKU for the Product Variant.
* type: string
* ean:
* description: The EAN number of the item.
* type: string
* upc:
* description: The UPC number of the item.
* type: string
* barcode:
* description: A generic GTIN field for the Product Variant.
* type: string
* hs_code:
* description: The Harmonized System code for the Product Variant.
* type: string
* inventory_quantity:
* description: The amount of stock kept for the Product Variant.
* type: integer
* allow_backorder:
* description: Whether the Product Variant can be purchased when out of stock.
* type: boolean
* manage_inventory:
* description: Whether Medusa should keep track of the inventory for this Product Variant.
* type: boolean
* weight:
* description: The wieght of the Product Variant.
* type: string
* length:
* description: The length of the Product Variant.
* type: string
* height:
* description: The height of the Product Variant.
* type: string
* width:
* description: The width of the Product Variant.
* type: string
* origin_country:
* description: The country of origin of the Product Variant.
* type: string
* mid_code:
* description: The Manufacturer Identification code for the Product Variant.
* type: string
* material:
* description: The material composition of the Product Variant.
* type: string
* metadata:
* description: An optional set of key-value pairs with additional information.
* type: object
* prices:
* type: array
* items:
* properties:
* region_id:
* description: The id of the Region for which the price is used.
* type: string
* currency_code:
* description: The 3 character ISO currency code for which the price will be used.
* type: string
* amount:
* description: The amount to charge for the Product Variant.
* type: integer
* sale_amount:
* description: The sale amount to charge for the Product Variant.
* type: integer
* options:
* type: array
* items:
* properties:
* value:
* description: The value to give for the Product Option at the same index in the Product's `options` field.
* type: string
* weight:
* description: The wieght of the Product.
* type: string
* length:
* description: The length of the Product.
* type: string
* height:
* description: The height of the Product.
* type: string
* width:
* description: The width of the Product.
* type: string
* origin_country:
* description: The country of origin of the Product.
* type: string
* mid_code:
* description: The Manufacturer Identification code for the Product.
* type: string
* material:
* description: The material composition of the Product.
* type: string
* metadata:
* description: An optional set of key-value pairs with additional information.
* type: object
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id } = req.params
@@ -90,8 +269,11 @@ export default async (req, res) => {
try {
const productService = req.scope.resolve("productService")
const entityManager = req.scope.resolve("manager")
await productService.update(id, value)
await entityManager.transaction(async manager => {
await productService.withTransaction(manager).update(id, value)
})
const product = await productService.retrieve(id, {
select: defaultFields,
@@ -2,6 +2,108 @@ import _ from "lodash"
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /products/{id}/variants/{variant_id}
* operationId: "PostProductsProductVariantsVariant"
* summary: "Update a Product Variant"
* description: "Update a Product Variant."
* parameters:
* - (path) id=* {string} The id of the Product.
* - (path) variant_id=* {string} The id of the Product Variant.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* title:
* description: The title to identify the Product Variant by.
* type: string
* sku:
* description: The unique SKU for the Product Variant.
* type: string
* ean:
* description: The EAN number of the item.
* type: string
* upc:
* description: The UPC number of the item.
* type: string
* barcode:
* description: A generic GTIN field for the Product Variant.
* type: string
* hs_code:
* description: The Harmonized System code for the Product Variant.
* type: string
* inventory_quantity:
* description: The amount of stock kept for the Product Variant.
* type: integer
* allow_backorder:
* description: Whether the Product Variant can be purchased when out of stock.
* type: boolean
* manage_inventory:
* description: Whether Medusa should keep track of the inventory for this Product Variant.
* type: boolean
* weight:
* description: The wieght of the Product Variant.
* type: string
* length:
* description: The length of the Product Variant.
* type: string
* height:
* description: The height of the Product Variant.
* type: string
* width:
* description: The width of the Product Variant.
* type: string
* origin_country:
* description: The country of origin of the Product Variant.
* type: string
* mid_code:
* description: The Manufacturer Identification code for the Product Variant.
* type: string
* material:
* description: The material composition of the Product Variant.
* type: string
* metadata:
* description: An optional set of key-value pairs with additional information.
* type: object
* prices:
* type: array
* items:
* properties:
* region_id:
* description: The id of the Region for which the price is used.
* type: string
* currency_code:
* description: The 3 character ISO currency code for which the price will be used.
* type: string
* amount:
* description: The amount to charge for the Product Variant.
* type: integer
* sale_amount:
* description: The sale amount to charge for the Product Variant.
* type: integer
* options:
* type: array
* items:
* properties:
* option_id:
* description: The id of the Product Option to set the value for.
* type: string
* value:
* description: The value to give for the Product Option.
* type: string
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* product:
* $ref: "#/components/schemas/product"
*/
export default async (req, res) => {
const { id, variant_id } = req.params
const schema = Validator.object().keys({
@@ -1,6 +1,33 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /regions/{id}/countries
* operationId: "PostRegionsRegionCountries"
* summary: "Add Country"
* description: "Adds a Country to the list of Countries in a Region"
* parameters:
* - (path) id=* {string} The id of the Region.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* country_code:
* description: "The 2 character ISO code for the Country."
* type: string
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id } = req.params
const schema = Validator.object().keys({
@@ -1,6 +1,33 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /regions/{id}/fulfillment-providers
* operationId: "PostRegionsRegionFulfillmentProviders"
* summary: "Add Fulfillment Provider"
* description: "Adds a Fulfillment Provider to a Region"
* parameters:
* - (path) id=* {string} The id of the Region.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* provider_id:
* description: "The id of the Fulfillment Provider to add."
* type: string
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id } = req.params
const schema = Validator.object().keys({
@@ -1,6 +1,33 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /regions/{id}/payment-providers
* operationId: "PostRegionsRegionPaymentProviders"
* summary: "Add Payment Provider"
* description: "Adds a Payment Provider to a Region"
* parameters:
* - (path) id=* {string} The id of the Region.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* provider_id:
* description: "The id of the Payment Provider to add."
* type: string
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id } = req.params
const schema = Validator.object().keys({
@@ -1,6 +1,55 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /regions
* operationId: "PostRegions"
* summary: "Create a Region"
* description: "Creates a Region"
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Region"
* type: string
* currency_code:
* description: "The 3 character ISO currency code to use for the Region."
* type: string
* tax_code:
* description: "An optional tax code the Region."
* type: string
* tax_rate:
* description: "The tax rate to use on Orders in the Region."
* type: number
* payment_providers:
* description: "A list of Payment Providers that should be enabled for the Region"
* type: array
* items:
* type: string
* fulfillment_providers:
* description: "A list of Fulfillment Providers that should be enabled for the Region"
* type: array
* items:
* type: string
* countries:
* description: "A list of countries that should be included in the Region."
* type: array
* items:
* type: string
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
name: Validator.string().required(),
@@ -1,5 +1,25 @@
import { defaultRelations, defaultFields } from "./"
/**
* @oas [delete] /regions/{id}/metadata/{key}
* operationId: "DeleteRegionsRegionMetadataKey"
* summary: "Delete Metadata"
* description: "Deletes a metadata key."
* parameters:
* - (path) id=* {string} The id of the Region.
* - (path) key=* {string} The metadata key.
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { id, key } = req.params
@@ -1,5 +1,30 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [delete] /regions/{id}
* operationId: "DeleteRegionsRegion"
* summary: "Delete a Region"
* description: "Deletes a Region."
* parameters:
* - (path) id=* {string} The id of the Region.
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Region.
* object:
* type: string
* description: The type of the object that was deleted.
* deleted:
* type: boolean
*/
export default async (req, res) => {
const { region_id } = req.params
try {
@@ -1,3 +1,24 @@
/**
* @oas [get] /regions/{id}/fulfillment-options
* operationId: "GetRegionsRegionFulfillmentOptions"
* summary: "List Fulfillment Options available in the Region"
* description: "Gathers all the fulfillment options available to in the Region."
* parameters:
* - (path) id=* {string} The id of the Region.
* tags:
* - Product
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* fulfillment_options:
* type: array
* items:
* type: object
*/
export default async (req, res) => {
const { region_id } = req.params
@@ -1,6 +1,25 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [get] /regions/{id}
* operationId: "GetRegionsRegion"
* summary: "Retrieve a Region"
* description: "Retrieves a Region."
* parameters:
* - (path) id=* {string} The id of the Region.
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id } = req.params
try {
@@ -1,5 +1,24 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /regions
* operationId: "GetRegions"
* summary: "List Regions"
* description: "Retrieves a list of Regions."
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* regions:
* type: array
* items:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
try {
const regionService = req.scope.resolve("regionService")
@@ -1,6 +1,26 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [delete] /regions/{id}/countries/{country_code}
* operationId: "PostRegionsRegionCountriesCountry"
* summary: "Remove Country"
* description: "Removes a Country from the list of Countries in a Region"
* parameters:
* - (path) id=* {string} The id of the Region.
* - (path) country_code=* {string} The 2 character ISO code for the Country.
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id, country_code } = req.params
try {
@@ -1,6 +1,26 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [delete] /regions/{id}/fulfillment-providers/{provider_id}
* operationId: "PostRegionsRegionFulfillmentProvidersProvider"
* summary: "Remove Fulfillment Provider"
* description: "Removes a Fulfillment Provider."
* parameters:
* - (path) id=* {string} The id of the Region.
* - (path) provider_id=* {string} The id of the Fulfillment Provider.
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id, provider_id } = req.params
try {
@@ -1,6 +1,26 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [delete] /regions/{id}/payment-providers/{provider_id}
* operationId: "PostRegionsRegionPaymentProvidersProvider"
* summary: "Remove Payment Provider"
* description: "Removes a Payment Provider."
* parameters:
* - (path) id=* {string} The id of the Region.
* - (path) provider_id=* {string} The id of the Payment Provider.
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id, provider_id } = req.params
try {
@@ -1,6 +1,57 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /regions/{id}
* operationId: "PostRegionsRegion"
* summary: "Update a Region"
* description: "Updates a Region"
* parameters:
* - (path) id=* {string} The id of the Region.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Region"
* type: string
* currency_code:
* description: "The 3 character ISO currency code to use for the Region."
* type: string
* tax_code:
* description: "An optional tax code the Region."
* type: string
* tax_rate:
* description: "The tax rate to use on Orders in the Region."
* type: number
* payment_providers:
* description: "A list of Payment Providers that should be enabled for the Region"
* type: array
* items:
* type: string
* fulfillment_providers:
* description: "A list of Fulfillment Providers that should be enabled for the Region"
* type: array
* items:
* type: string
* countries:
* description: "A list of countries that should be included in the Region."
* type: array
* items:
* type: string
* tags:
* - Region
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* region:
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
const { region_id } = req.params
const schema = Validator.object().keys({
@@ -1,5 +1,24 @@
import _ from "lodash"
/**
* @oas [get] /returns
* operationId: "GetReturns"
* summary: "List Returns"
* description: "Retrieves a list of Returns"
* tags:
* - Return
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* returns:
* type: array
* items:
* $ref: "#/components/schemas/return"
*/
export default async (req, res) => {
try {
const returnService = req.scope.resolve("returnService")
@@ -1,6 +1,69 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /shipping-options
* operationId: "PostShippingOptions"
* summary: "Create Shipping Option"
* description: "Creates a Shipping Option"
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Shipping Option"
* type: string
* region_id:
* description: "The id of the Region in which the Shipping Option will be available."
* type: string
* provider_id:
* description: "The id of the Fulfillment Provider that handles the Shipping Option."
* type: string
* profile_id:
* description: "The id of the Shipping Profile to add the Shipping Option to."
* type: number
* data:
* description: "The data needed for the Fulfillment Provider to handle shipping with this Shipping Option."
* type: object
* price_type:
* description: "The type of the Shipping Option price."
* type: string
* enum:
* - flat_rate
* - calculated
* amount:
* description: "The amount to charge for the Shipping Option."
* type: integer
* requirements:
* description: "The requirements that must be satisfied for the Shipping Option to be available."
* type: array
* items:
* properties:
* type:
* description: The type of the requirement
* type: string
* enum:
* - max_subtotal
* - min_subtotal
* amount:
* description: The amount to compare with.
* type: integer
* is_return:
* description: Whether the Shipping Option defines a return shipment.
* type: boolean
* tags:
* - Shipping Option
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_option:
* $ref: "#/components/schemas/shipping_option"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
name: Validator.string().required(),
@@ -1,3 +1,28 @@
/**
* @oas [delete] /shipping-options/{id}
* operationId: "DeleteShippingOptionsOption"
* summary: "Delete a Shipping Option"
* description: "Deletes a Shipping Option."
* parameters:
* - (path) id=* {string} The id of the Shipping Option.
* tags:
* - Shipping Option
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Shipping Option.
* object:
* type: string
* description: The type of the object that was deleted.
* deleted:
* type: boolean
*/
export default async (req, res) => {
const { option_id } = req.params
try {
@@ -1,3 +1,22 @@
/**
* @oas [get] /shipping-options/{id}
* operationId: "GetShippingOptionsOption"
* summary: "Retrieve a Shipping Option"
* description: "Retrieves a Shipping Option."
* parameters:
* - (path) id=* {string} The id of the Shipping Option.
* tags:
* - Shipping Option
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_option:
* $ref: "#/components/schemas/shipping_option"
*/
export default async (req, res) => {
const { option_id } = req.params
try {
@@ -1,6 +1,25 @@
import _ from "lodash"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /shipping-options
* operationId: "GetShippingOptions"
* summary: "List Shipping Options"
* description: "Retrieves a list of Shipping Options."
* tags:
* - Shipping Option
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_options:
* type: array
* items:
* $ref: "#/components/schemas/shipping_option"
*/
export default async (req, res) => {
try {
const query = _.pick(req.query, ["region_id", "is_return", "admin_only"])
@@ -2,6 +2,50 @@ import _ from "lodash"
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /shipping-options/{id}
* operationId: "PostShippingOptionsOption"
* summary: "Update Shipping Option"
* description: "Updates a Shipping Option"
* parameters:
* - (path) id=* {string} The id of the Shipping Option.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Shipping Option"
* type: string
* amount:
* description: "The amount to charge for the Shipping Option."
* type: integer
* requirements:
* description: "The requirements that must be satisfied for the Shipping Option to be available."
* type: array
* items:
* properties:
* type:
* description: The type of the requirement
* type: string
* enum:
* - max_subtotal
* - min_subtotal
* amount:
* description: The amount to compare with.
* type: integer
* tags:
* - Shipping Option
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_option:
* $ref: "#/components/schemas/shipping_option"
*/
export default async (req, res) => {
const { option_id } = req.params
const schema = Validator.object().keys({
@@ -1,5 +1,30 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /shipping-profiles
* operationId: "PostShippingProfiles"
* summary: "Create a Shipping Profile"
* description: "Creates a Shipping Profile"
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Shipping Profile"
* type: string
* tags:
* - Shipping Profile
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_profile:
* $ref: "#/components/schemas/shipping_profile"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
name: Validator.string().required(),
@@ -1,3 +1,28 @@
/**
* @oas [delete] /shipping-profiles/{id}
* operationId: "DeleteShippingProfilesProfile"
* summary: "Delete a Shipping Profile"
* description: "Deletes a Shipping Profile."
* parameters:
* - (path) id=* {string} The id of the Shipping Profile.
* tags:
* - Shipping Profile
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* id:
* type: string
* description: The id of the deleted Shipping Profile.
* object:
* type: string
* description: The type of the object that was deleted.
* deleted:
* type: boolean
*/
export default async (req, res) => {
const { profile_id } = req.params
try {
@@ -1,4 +1,24 @@
import { defaultFields, defaultRelations } from "./"
/**
* @oas [get] /shipping-profiles/{id}
* operationId: "GetShippingProfilesProfile"
* summary: "Retrieve a Shipping Profile"
* description: "Retrieves a Shipping Profile."
* parameters:
* - (path) id=* {string} The id of the Shipping Profile.
* tags:
* - Shipping Profile
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_profile:
* $ref: "#/components/schemas/shipping_profile"
*/
export default async (req, res) => {
const { profile_id } = req.params
try {
@@ -1,3 +1,22 @@
/**
* @oas [get] /shipping-profiles
* operationId: "GetShippingProfiles"
* summary: "List Shipping Profiles"
* description: "Retrieves a list of Shipping Profile."
* tags:
* - Shipping Profile
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_profiles:
* type: array
* items:
* $ref: "#/components/schemas/shipping_profile"
*/
export default async (req, res) => {
try {
const profileService = req.scope.resolve("shippingProfileService")
@@ -1,5 +1,32 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /shipping-profiles/{id}
* operationId: "PostShippingProfilesProfile"
* summary: "Update a Shipping Profiles"
* description: "Updates a Shipping Profile"
* parameters:
* - (path) id=* {string} The id of the Shipping Profile.
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Shipping Profile"
* type: string
* tags:
* - Shipping Profile
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* shipping_profiles:
* $ref: "#/components/schemas/shipping_profile"
*/
export default async (req, res) => {
const { profile_id } = req.params
@@ -1,3 +1,22 @@
/**
* @oas [post] /store/currencies/{code}
* operationId: "PostStoreCurrenciesCode"
* summary: "Add a Currency Code"
* description: "Adds a Currency Code to the available currencies."
* parameters:
* - (path) code=* {string} The 3 character ISO currency code.
* tags:
* - Store
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* store:
* $ref: "#/components/schemas/store"
*/
export default async (req, res) => {
const { currency_code } = req.params
@@ -1,3 +1,20 @@
/**
* @oas [get] /store
* operationId: "GetStore"
* summary: "Retrieve Store details."
* description: "Retrieves the Store details"
* tags:
* - Store
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* store:
* $ref: "#/components/schemas/store"
*/
export default async (req, res) => {
try {
const storeService = req.scope.resolve("storeService")
@@ -1,3 +1,22 @@
/**
* @oas [get] /store/payment-providers
* operationId: "GetStorePaymentProviders"
* summary: "Retrieve configured Payment Providers"
* description: "Retrieves the configured Payment Providers"
* tags:
* - Store
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* payment_providers:
* type: array
* items:
* $ref: "#/components/schemas/store"
*/
export default async (req, res) => {
try {
const paymentProviderService = container.resolve("paymentProviderService")
@@ -1,3 +1,22 @@
/**
* @oas [delete] /store/currencies/{code}
* operationId: "DeleteStoreCurrenciesCode"
* summary: "Remvoe a Currency Code"
* description: "Removes a Currency Code from the available currencies."
* parameters:
* - (path) code=* {string} The 3 character ISO currency code.
* tags:
* - Store
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* store:
* $ref: "#/components/schemas/store"
*/
export default async (req, res) => {
const { currency_code } = req.params
@@ -1,5 +1,36 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [post] /store
* operationId: "PostStore"
* summary: "Update Store details."
* description: "Updates the Store details"
* requestBody:
* content:
* application/json:
* schema:
* properties:
* name:
* description: "The name of the Store"
* type: string
* swap_link_template:
* description: "A template for Swap links - use `{{cart_id}}` to insert the Swap Cart id"
* type: string
* default_currency_code:
* description: "The default currency code for the Store."
* type: string
* tags:
* - Store
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* store:
* $ref: "#/components/schemas/store"
*/
export default async (req, res) => {
const schema = Validator.object().keys({
name: Validator.string(),

Some files were not shown because too many files have changed in this diff Show More