fix(medusa): Remove unsupported Discount endpoints (#1367)
This commit is contained in:
@@ -15,26 +15,22 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
/**
|
/**
|
||||||
* @description Adds region to discount
|
* @description Adds region to discount
|
||||||
*/
|
*/
|
||||||
addRegion(id: string, regionId: string, customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
addRegion(
|
||||||
|
id: string,
|
||||||
|
regionId: string,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/${id}/regions/${regionId}`
|
const path = `/admin/discounts/${id}/regions/${regionId}`
|
||||||
return this.client.request("POST", path, {}, {}, customHeaders)
|
return this.client.request("POST", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Add valid product
|
|
||||||
*/
|
|
||||||
addValidProduct(
|
|
||||||
id: string,
|
|
||||||
productId: string,
|
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
|
||||||
const path = `/admin/discounts/${id}/products/${productId}`
|
|
||||||
return this.client.request("POST", path, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Creates discounts
|
* @description Creates discounts
|
||||||
*/
|
*/
|
||||||
create(payload: AdminPostDiscountsReq, customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
create(
|
||||||
|
payload: AdminPostDiscountsReq,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts`
|
const path = `/admin/discounts`
|
||||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -45,7 +41,8 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
update(
|
update(
|
||||||
id: string,
|
id: string,
|
||||||
payload: AdminPostDiscountsDiscountReq,
|
payload: AdminPostDiscountsDiscountReq,
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/${id}`
|
const path = `/admin/discounts/${id}`
|
||||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -56,7 +53,8 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
createDynamicCode(
|
createDynamicCode(
|
||||||
id: string,
|
id: string,
|
||||||
payload: AdminPostDiscountsDiscountDynamicCodesReq,
|
payload: AdminPostDiscountsDiscountDynamicCodesReq,
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/${id}/dynamic-codes`
|
const path = `/admin/discounts/${id}/dynamic-codes`
|
||||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -64,7 +62,10 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
/**
|
/**
|
||||||
* @description Deletes a discount
|
* @description Deletes a discount
|
||||||
*/
|
*/
|
||||||
delete(id: string, customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsDeleteRes> {
|
delete(
|
||||||
|
id: string,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsDeleteRes> {
|
||||||
const path = `/admin/discounts/${id}`
|
const path = `/admin/discounts/${id}`
|
||||||
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -75,7 +76,8 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
deleteDynamicCode(
|
deleteDynamicCode(
|
||||||
id: string,
|
id: string,
|
||||||
code: string,
|
code: string,
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/${id}/dynamic-codes/${code}`
|
const path = `/admin/discounts/${id}/dynamic-codes/${code}`
|
||||||
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,10 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
/**
|
/**
|
||||||
* @description Retrieves a discount
|
* @description Retrieves a discount
|
||||||
*/
|
*/
|
||||||
retrieve(id: string, customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
retrieve(
|
||||||
|
id: string,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/${id}`
|
const path = `/admin/discounts/${id}`
|
||||||
return this.client.request("GET", path, {}, {}, customHeaders)
|
return this.client.request("GET", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -91,7 +96,10 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
/**
|
/**
|
||||||
* @description Retrieves a discount by code
|
* @description Retrieves a discount by code
|
||||||
*/
|
*/
|
||||||
retrieveByCode(code: string, customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
retrieveByCode(
|
||||||
|
code: string,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/code/${code}`
|
const path = `/admin/discounts/code/${code}`
|
||||||
return this.client.request("GET", path, {}, {}, customHeaders)
|
return this.client.request("GET", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
@@ -101,7 +109,8 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
*/
|
*/
|
||||||
list(
|
list(
|
||||||
query?: AdminGetDiscountsParams,
|
query?: AdminGetDiscountsParams,
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsListRes> {
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsListRes> {
|
||||||
let path = `/admin/discounts`
|
let path = `/admin/discounts`
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
@@ -118,21 +127,11 @@ class AdminDiscountsResource extends BaseResource {
|
|||||||
removeRegion(
|
removeRegion(
|
||||||
id: string,
|
id: string,
|
||||||
regionId: string,
|
regionId: string,
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminDiscountsRes> {
|
||||||
const path = `/admin/discounts/${id}/regions/${regionId}`
|
const path = `/admin/discounts/${id}/regions/${regionId}`
|
||||||
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Removes a valid product from a discount
|
|
||||||
*/
|
|
||||||
removeValidProduct(
|
|
||||||
id: string,
|
|
||||||
productId: string,
|
|
||||||
customHeaders: Record<string, any> = {}): ResponsePromise<AdminDiscountsRes> {
|
|
||||||
const path = `/admin/discounts/${id}/products/${productId}`
|
|
||||||
return this.client.request("DELETE", path, {}, {}, customHeaders)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdminDiscountsResource
|
export default AdminDiscountsResource
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { adminDiscountKeys } from "./queries"
|
|
||||||
import { buildOptions } from "../../utils/buildOptions"
|
|
||||||
import {
|
import {
|
||||||
AdminDiscountsDeleteRes,
|
AdminDiscountsDeleteRes,
|
||||||
AdminDiscountsRes,
|
AdminDiscountsRes,
|
||||||
@@ -10,6 +8,8 @@ import {
|
|||||||
import { Response } from "@medusajs/medusa-js"
|
import { Response } from "@medusajs/medusa-js"
|
||||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||||
import { useMedusa } from "../../../contexts/medusa"
|
import { useMedusa } from "../../../contexts/medusa"
|
||||||
|
import { buildOptions } from "../../utils/buildOptions"
|
||||||
|
import { adminDiscountKeys } from "./queries"
|
||||||
|
|
||||||
export const useAdminCreateDiscount = (
|
export const useAdminCreateDiscount = (
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
@@ -79,32 +79,6 @@ export const useAdminDiscountRemoveRegion = (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAdminDiscountAddValidProduct = (
|
|
||||||
id: string,
|
|
||||||
options?: UseMutationOptions<Response<AdminDiscountsRes>, Error, string>
|
|
||||||
) => {
|
|
||||||
const { client } = useMedusa()
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
return useMutation(
|
|
||||||
(productId: string) =>
|
|
||||||
client.admin.discounts.addValidProduct(id, productId),
|
|
||||||
buildOptions(queryClient, adminDiscountKeys.detail(id), options)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAdminDiscountRemoveValidProduct = (
|
|
||||||
id: string,
|
|
||||||
options?: UseMutationOptions<Response<AdminDiscountsRes>, Error, string>
|
|
||||||
) => {
|
|
||||||
const { client } = useMedusa()
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
return useMutation(
|
|
||||||
(productId: string) =>
|
|
||||||
client.admin.discounts.removeValidProduct(id, productId),
|
|
||||||
buildOptions(queryClient, adminDiscountKeys.detail(id), options)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAdminCreateDynamicDiscountCode = (
|
export const useAdminCreateDynamicDiscountCode = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import {
|
|
||||||
useAdminCreateDiscount,
|
|
||||||
useAdminUpdateDiscount,
|
|
||||||
useAdminDeleteDiscount,
|
|
||||||
useAdminDiscountAddRegion,
|
|
||||||
useAdminDiscountAddValidProduct,
|
|
||||||
useAdminDiscountRemoveRegion,
|
|
||||||
useAdminDiscountRemoveValidProduct,
|
|
||||||
useAdminCreateDynamicDiscountCode,
|
|
||||||
useAdminDeleteDynamicDiscountCode,
|
|
||||||
} from "../../../../src/"
|
|
||||||
import { renderHook } from "@testing-library/react-hooks"
|
import { renderHook } from "@testing-library/react-hooks"
|
||||||
import { fixtures } from "../../../../mocks/data"
|
import { fixtures } from "../../../../mocks/data"
|
||||||
|
import {
|
||||||
|
useAdminCreateDiscount,
|
||||||
|
useAdminCreateDynamicDiscountCode,
|
||||||
|
useAdminDeleteDiscount,
|
||||||
|
useAdminDeleteDynamicDiscountCode,
|
||||||
|
useAdminDiscountAddRegion,
|
||||||
|
useAdminDiscountRemoveRegion,
|
||||||
|
useAdminUpdateDiscount,
|
||||||
|
} from "../../../../src/"
|
||||||
import { createWrapper } from "../../../utils"
|
import { createWrapper } from "../../../utils"
|
||||||
|
|
||||||
describe("useAdminCreateDiscount hook", () => {
|
describe("useAdminCreateDiscount hook", () => {
|
||||||
@@ -115,28 +113,6 @@ describe("useAdminDiscountAddRegion hook", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("useAdminDiscountAddValidProduct hook", () => {
|
|
||||||
test("adds a product to the discount", async () => {
|
|
||||||
const id = fixtures.get("discount").id
|
|
||||||
|
|
||||||
const { result, waitFor } = renderHook(
|
|
||||||
() => useAdminDiscountAddValidProduct(id),
|
|
||||||
{
|
|
||||||
wrapper: createWrapper(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
result.current.mutate("test-product")
|
|
||||||
|
|
||||||
await waitFor(() => result.current.isSuccess)
|
|
||||||
|
|
||||||
expect(result.current.data.response.status).toEqual(200)
|
|
||||||
expect(result.current.data.discount).toEqual(
|
|
||||||
expect.objectContaining(fixtures.get("discount"))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("useAdminCreateDynamicDiscountCode hook", () => {
|
describe("useAdminCreateDynamicDiscountCode hook", () => {
|
||||||
test("creates a dynamic discount code", async () => {
|
test("creates a dynamic discount code", async () => {
|
||||||
const discount = {
|
const discount = {
|
||||||
@@ -187,28 +163,6 @@ describe("useAdminDiscountRemoveRegion hook", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("useAdminDiscountRemoveValidProduct hook", () => {
|
|
||||||
test("adds a product to the discount", async () => {
|
|
||||||
const id = fixtures.get("discount").id
|
|
||||||
|
|
||||||
const { result, waitFor } = renderHook(
|
|
||||||
() => useAdminDiscountRemoveValidProduct(id),
|
|
||||||
{
|
|
||||||
wrapper: createWrapper(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
result.current.mutate("test-product")
|
|
||||||
|
|
||||||
await waitFor(() => result.current.isSuccess)
|
|
||||||
|
|
||||||
expect(result.current.data.response.status).toEqual(200)
|
|
||||||
expect(result.current.data.discount).toEqual(
|
|
||||||
expect.objectContaining(fixtures.get("discount"))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("useAdminDeleteDynamicDiscountCode hook", () => {
|
describe("useAdminDeleteDynamicDiscountCode hook", () => {
|
||||||
test("creates a dynamic discount code", async () => {
|
test("creates a dynamic discount code", async () => {
|
||||||
const id = fixtures.get("discount").id
|
const id = fixtures.get("discount").id
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
import { IdMap } from "medusa-test-utils"
|
|
||||||
import { request } from "../../../../../helpers/test-request"
|
|
||||||
import { DiscountServiceMock } from "../../../../../services/__mocks__/discount"
|
|
||||||
|
|
||||||
describe("POST /admin/discounts/:discount_id/products/:product_id", () => {
|
|
||||||
describe("successful addition", () => {
|
|
||||||
let subject
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
subject = await request(
|
|
||||||
"POST",
|
|
||||||
`/admin/discounts/${IdMap.getId("total10")}/products/${IdMap.getId(
|
|
||||||
"testVariant"
|
|
||||||
)}`,
|
|
||||||
{
|
|
||||||
adminSession: {
|
|
||||||
jwt: {
|
|
||||||
userId: IdMap.getId("admin_user"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns 200", () => {
|
|
||||||
expect(subject.status).toEqual(200)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls service retrieve", () => {
|
|
||||||
expect(DiscountServiceMock.retrieve).toHaveBeenCalledTimes(1)
|
|
||||||
expect(DiscountServiceMock.retrieve).toHaveBeenCalledWith(
|
|
||||||
IdMap.getId("total10"),
|
|
||||||
{
|
|
||||||
select: [
|
|
||||||
"id",
|
|
||||||
"code",
|
|
||||||
"is_dynamic",
|
|
||||||
"is_disabled",
|
|
||||||
"rule_id",
|
|
||||||
"parent_discount_id",
|
|
||||||
"usage_limit",
|
|
||||||
"usage_count",
|
|
||||||
"starts_at",
|
|
||||||
"ends_at",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"deleted_at",
|
|
||||||
"metadata",
|
|
||||||
"valid_duration",
|
|
||||||
],
|
|
||||||
relations: ["rule", "parent_discount", "regions", "rule.conditions"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(DiscountServiceMock.addValidProduct).toHaveBeenCalledTimes(1)
|
|
||||||
expect(DiscountServiceMock.addValidProduct).toHaveBeenCalledWith(
|
|
||||||
IdMap.getId("total10"),
|
|
||||||
IdMap.getId("testVariant")
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
import { IdMap } from "medusa-test-utils"
|
|
||||||
import { request } from "../../../../../helpers/test-request"
|
|
||||||
import { DiscountServiceMock } from "../../../../../services/__mocks__/discount"
|
|
||||||
|
|
||||||
const defaultFields = [
|
|
||||||
"id",
|
|
||||||
"code",
|
|
||||||
"is_dynamic",
|
|
||||||
"is_disabled",
|
|
||||||
"rule_id",
|
|
||||||
"parent_discount_id",
|
|
||||||
"usage_limit",
|
|
||||||
"usage_count",
|
|
||||||
"starts_at",
|
|
||||||
"ends_at",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"deleted_at",
|
|
||||||
"metadata",
|
|
||||||
"valid_duration",
|
|
||||||
]
|
|
||||||
|
|
||||||
const defaultRelations = [
|
|
||||||
"rule",
|
|
||||||
"parent_discount",
|
|
||||||
"regions",
|
|
||||||
"rule.conditions",
|
|
||||||
]
|
|
||||||
|
|
||||||
describe("DELETE /admin/discounts/:discount_id/products/:product_id", () => {
|
|
||||||
describe("successful addition", () => {
|
|
||||||
let subject
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
subject = await request(
|
|
||||||
"DELETE",
|
|
||||||
`/admin/discounts/${IdMap.getId("total10")}/products/${IdMap.getId(
|
|
||||||
"testVariant"
|
|
||||||
)}`,
|
|
||||||
{
|
|
||||||
adminSession: {
|
|
||||||
jwt: {
|
|
||||||
userId: IdMap.getId("admin_user"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns 200", () => {
|
|
||||||
expect(subject.status).toEqual(200)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls service retrieve", () => {
|
|
||||||
expect(DiscountServiceMock.retrieve).toHaveBeenCalledTimes(1)
|
|
||||||
expect(DiscountServiceMock.retrieve).toHaveBeenCalledWith(
|
|
||||||
IdMap.getId("total10"),
|
|
||||||
{
|
|
||||||
select: defaultFields,
|
|
||||||
relations: defaultRelations,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(DiscountServiceMock.removeValidProduct).toHaveBeenCalledTimes(1)
|
|
||||||
expect(DiscountServiceMock.removeValidProduct).toHaveBeenCalledWith(
|
|
||||||
IdMap.getId("total10"),
|
|
||||||
IdMap.getId("testVariant")
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
|
|
||||||
import { Discount } from "../../../.."
|
|
||||||
import DiscountService from "../../../../services/discount"
|
|
||||||
/**
|
|
||||||
* @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) 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, product_id } = req.params
|
|
||||||
|
|
||||||
const discountService: DiscountService = req.scope.resolve("discountService")
|
|
||||||
await discountService.addValidProduct(discount_id, product_id)
|
|
||||||
|
|
||||||
const discount: Discount = await discountService.retrieve(discount_id, {
|
|
||||||
select: defaultAdminDiscountsFields,
|
|
||||||
relations: defaultAdminDiscountsRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ discount })
|
|
||||||
}
|
|
||||||
@@ -39,16 +39,6 @@ export default (app) => {
|
|||||||
middlewares.wrap(require("./delete-dynamic-code").default)
|
middlewares.wrap(require("./delete-dynamic-code").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Discount valid variants management
|
|
||||||
route.post(
|
|
||||||
"/:discount_id/products/:product_id",
|
|
||||||
middlewares.wrap(require("./add-valid-product").default)
|
|
||||||
)
|
|
||||||
route.delete(
|
|
||||||
"/:discount_id/products/:product_id",
|
|
||||||
middlewares.wrap(require("./remove-valid-product").default)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Discount region management
|
// Discount region management
|
||||||
route.post(
|
route.post(
|
||||||
"/:discount_id/regions/:region_id",
|
"/:discount_id/regions/:region_id",
|
||||||
@@ -98,7 +88,6 @@ export type AdminDiscountsListRes = PaginatedResponse & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export * from "./add-region"
|
export * from "./add-region"
|
||||||
export * from "./add-valid-product"
|
|
||||||
export * from "./create-discount"
|
export * from "./create-discount"
|
||||||
export * from "./create-dynamic-code"
|
export * from "./create-dynamic-code"
|
||||||
export * from "./delete-discount"
|
export * from "./delete-discount"
|
||||||
@@ -107,5 +96,4 @@ export * from "./get-discount"
|
|||||||
export * from "./get-discount-by-code"
|
export * from "./get-discount-by-code"
|
||||||
export * from "./list-discounts"
|
export * from "./list-discounts"
|
||||||
export * from "./remove-region"
|
export * from "./remove-region"
|
||||||
export * from "./remove-valid-product"
|
|
||||||
export * from "./update-discount"
|
export * from "./update-discount"
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
|
|
||||||
import DiscountService from "../../../../services/discount"
|
|
||||||
/**
|
|
||||||
* @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."
|
|
||||||
* x-authenticated: true
|
|
||||||
* 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, product_id } = req.params
|
|
||||||
|
|
||||||
const discountService: DiscountService = req.scope.resolve("discountService")
|
|
||||||
await discountService.removeValidProduct(discount_id, product_id)
|
|
||||||
|
|
||||||
const discount = await discountService.retrieve(discount_id, {
|
|
||||||
select: defaultAdminDiscountsFields,
|
|
||||||
relations: defaultAdminDiscountsRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ discount })
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user