feat: add returns admin endpoints to medusa-js (#935)
* add: returns admin endpoint to medusa-js * fix: http verbs * fix duplicate import * fix: type for cancel * fix: conflicting import Co-authored-by: Sebastian Rindom <seb@medusajs.com>
This commit is contained in:
co-authored by
Sebastian Rindom
parent
321c271e53
commit
b9d6f95dbd
@@ -7,6 +7,7 @@ import AdminDraftOrdersResource from "./draft-orders"
|
|||||||
import AdminGiftCardsResource from "./gift-cards"
|
import AdminGiftCardsResource from "./gift-cards"
|
||||||
import AdminInvitesResource from "./invites"
|
import AdminInvitesResource from "./invites"
|
||||||
import AdminNotesResource from "./notes"
|
import AdminNotesResource from "./notes"
|
||||||
|
import AdminReturnsResource from "./returns"
|
||||||
import AdminOrdersResource from "./orders"
|
import AdminOrdersResource from "./orders"
|
||||||
import AdminReturnReasonsResource from "./return-reasons"
|
import AdminReturnReasonsResource from "./return-reasons"
|
||||||
import AdminVariantsResource from "./variants"
|
import AdminVariantsResource from "./variants"
|
||||||
@@ -24,6 +25,7 @@ class Admin extends BaseResource {
|
|||||||
public giftCards = new AdminGiftCardsResource(this.client)
|
public giftCards = new AdminGiftCardsResource(this.client)
|
||||||
public invites = new AdminInvitesResource(this.client)
|
public invites = new AdminInvitesResource(this.client)
|
||||||
public notes = new AdminNotesResource(this.client)
|
public notes = new AdminNotesResource(this.client)
|
||||||
|
public returns = new AdminReturnsResource(this.client)
|
||||||
public orders = new AdminOrdersResource(this.client)
|
public orders = new AdminOrdersResource(this.client)
|
||||||
public returnReasons = new AdminReturnReasonsResource(this.client)
|
public returnReasons = new AdminReturnReasonsResource(this.client)
|
||||||
public variants = new AdminVariantsResource(this.client)
|
public variants = new AdminVariantsResource(this.client)
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import {
|
||||||
|
AdminGetReturnsParams,
|
||||||
|
AdminReturnsCancelRes,
|
||||||
|
AdminReturnsListRes,
|
||||||
|
AdminReturnsRes,
|
||||||
|
} from "@medusajs/medusa"
|
||||||
|
import { ResponsePromise } from "../../typings"
|
||||||
|
import BaseResource from "../base"
|
||||||
|
|
||||||
|
class AdminReturnsResource extends BaseResource {
|
||||||
|
/**
|
||||||
|
* @description cancels a return
|
||||||
|
* @param id id of return to cancel
|
||||||
|
* @returns the order for which the return was canceled
|
||||||
|
*/
|
||||||
|
cancel(id: string): ResponsePromise<AdminReturnsCancelRes> {
|
||||||
|
const path = `/admin/returns/${id}/cancel`
|
||||||
|
return this.client.request("POST", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description receive a return
|
||||||
|
* @param id id of the return to receive.
|
||||||
|
* @returns the return
|
||||||
|
*/
|
||||||
|
receive(id: string): ResponsePromise<AdminReturnsRes> {
|
||||||
|
const path = `/admin/returns/${id}/receive`
|
||||||
|
return this.client.request("POST", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description lists returns matching a query
|
||||||
|
* @param query query for searching returns
|
||||||
|
* @returns a list of returns matching the query
|
||||||
|
*/
|
||||||
|
list(query?: AdminGetReturnsParams): ResponsePromise<AdminReturnsListRes> {
|
||||||
|
let path = `/admin/returns/`
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
const queryString = Object.entries(query).map(([key, value]) => {
|
||||||
|
return typeof value !== "undefined" ? `${key}=${value}` : ""
|
||||||
|
})
|
||||||
|
path = `/admin/returns?${queryString.join("&")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminReturnsResource
|
||||||
@@ -31,6 +31,7 @@ export * from "./routes/admin/orders"
|
|||||||
export * from "./routes/admin/variants"
|
export * from "./routes/admin/variants"
|
||||||
export * from "./routes/admin/return-reasons"
|
export * from "./routes/admin/return-reasons"
|
||||||
export * from "./routes/admin/swaps"
|
export * from "./routes/admin/swaps"
|
||||||
|
export * from "./routes/admin/returns"
|
||||||
export * from "./routes/admin/shipping-options"
|
export * from "./routes/admin/shipping-options"
|
||||||
export * from "./routes/admin/regions"
|
export * from "./routes/admin/regions"
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export default async (req, res) => {
|
|||||||
res.status(200).json({ return: receivedReturn })
|
res.status(200).json({ return: receivedReturn })
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Item {
|
class Item {
|
||||||
@IsString()
|
@IsString()
|
||||||
item_id: string
|
item_id: string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user