feat: Add Discount Admin endpoint to JS client (#919)
This commit is contained in:
committed by
GitHub
parent
25fe224a10
commit
2ca1a8762d
@@ -17,6 +17,7 @@ export default (container, config) => {
|
||||
|
||||
export * from "./routes/admin/auth"
|
||||
export * from "./routes/admin/customers"
|
||||
export * from "./routes/admin/discounts"
|
||||
export * from "./routes/admin/notifications"
|
||||
export * from "./routes/admin/store"
|
||||
export * from "./routes/admin/variants"
|
||||
|
||||
@@ -2,7 +2,7 @@ import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { DiscountServiceMock } from "../../../../../services/__mocks__/discount"
|
||||
|
||||
describe("POST /admin/discounts/:discount_id/variants/:variant_id", () => {
|
||||
describe("POST /admin/discounts/:discount_id/products/:product_id", () => {
|
||||
describe("successful addition", () => {
|
||||
let subject
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ const defaultRelations = [
|
||||
"rule.valid_for",
|
||||
]
|
||||
|
||||
describe("DELETE /admin/discounts/:discount_id/products/:variant_id", () => {
|
||||
describe("DELETE /admin/discounts/:discount_id/products/:product_id", () => {
|
||||
describe("successful addition", () => {
|
||||
let subject
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
|
||||
import { Discount } from "../../../.."
|
||||
import DiscountService from "../../../../services/discount"
|
||||
/**
|
||||
* @oas [post] /discounts/{id}/products/{variant_id}
|
||||
* @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."
|
||||
* x-authenticated: true
|
||||
* parameters:
|
||||
* - (path) id=* {string} The id of the Discount.
|
||||
* - (path) variant_id=* {string} The id of the Product.
|
||||
* - (path) product_id=* {string} The id of the Product.
|
||||
* tags:
|
||||
* - Discount
|
||||
* responses:
|
||||
@@ -23,10 +23,10 @@ import DiscountService from "../../../../services/discount"
|
||||
* $ref: "#/components/schemas/discount"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { discount_id, variant_id } = req.params
|
||||
const { discount_id, product_id } = req.params
|
||||
|
||||
const discountService: DiscountService = req.scope.resolve("discountService")
|
||||
await discountService.addValidProduct(discount_id, variant_id)
|
||||
await discountService.addValidProduct(discount_id, product_id)
|
||||
|
||||
const discount: Discount = await discountService.retrieve(discount_id, {
|
||||
select: defaultAdminDiscountsFields,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Router } from "express"
|
||||
import { Discount } from "../../../.."
|
||||
import middlewares from "../../../middlewares"
|
||||
import "reflect-metadata"
|
||||
import { Discount } from "../../../.."
|
||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -41,11 +41,11 @@ export default (app) => {
|
||||
|
||||
// Discount valid variants management
|
||||
route.post(
|
||||
"/:discount_id/products/:variant_id",
|
||||
"/:discount_id/products/:product_id",
|
||||
middlewares.wrap(require("./add-valid-product").default)
|
||||
)
|
||||
route.delete(
|
||||
"/:discount_id/products/:variant_id",
|
||||
"/:discount_id/products/:product_id",
|
||||
middlewares.wrap(require("./remove-valid-product").default)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import DiscountService from "../../../../services/discount"
|
||||
import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
|
||||
import DiscountService from "../../../../services/discount"
|
||||
/**
|
||||
* @oas [post] /discounts/{id}/products/{product_id}
|
||||
* @oas [delete] /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."
|
||||
@@ -22,10 +22,10 @@ import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
|
||||
* $ref: "#/components/schemas/discount"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { discount_id, variant_id } = req.params
|
||||
const { discount_id, product_id } = req.params
|
||||
|
||||
const discountService: DiscountService = req.scope.resolve("discountService")
|
||||
await discountService.removeValidProduct(discount_id, variant_id)
|
||||
await discountService.removeValidProduct(discount_id, product_id)
|
||||
|
||||
const discount = await discountService.retrieve(discount_id, {
|
||||
select: defaultAdminDiscountsFields,
|
||||
|
||||
Reference in New Issue
Block a user