feat(admin-shared,dashboard,js-sdk,types): refund reasons in dashboard (#13575)
CLOSES CORE-1209 This PR just adds the stuff necessary to support refund reasons in the dashboard. It adds the option in the settings tab and allows viewing, creating, editing and deleting refund reasons. I hate to open such a big PR but most of it is copy pasted from the return reasons. Major difference is only the fact that refund reasons don't have a `value` field
This commit is contained in:
@@ -15,28 +15,28 @@ export class RefundReason {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves a list of refund reasons. It sends a request to the
|
||||
* This method retrieves a list of refund reasons. It sends a request to the
|
||||
* [List Refund Reasons](https://docs.medusajs.com/api/admin#refund-reasons_getrefundreasons)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param query - Filters and pagination configurations.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The paginated list of refund reasons.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve the list of refund reasons:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.refundReason.list()
|
||||
* .then(({ refund_reasons, count, limit, offset }) => {
|
||||
* console.log(refund_reasons)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
||||
*
|
||||
*
|
||||
* For example, to retrieve only 10 items and skip 10 items:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.refundReason.list({
|
||||
* limit: 10,
|
||||
@@ -46,23 +46,26 @@ export class RefundReason {
|
||||
* console.log(refund_reasons)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
||||
* in each refund reason:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.refundReason.list({
|
||||
* fields: "id,name"
|
||||
* fields: "id,label"
|
||||
* })
|
||||
* .then(({ refund_reasons, count, limit, offset }) => {
|
||||
* console.log(refund_reasons)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin#select-fields-and-relations).
|
||||
*
|
||||
*
|
||||
*/
|
||||
async list(query?: HttpTypes.RefundReasonFilters, headers?: ClientHeaders) {
|
||||
async list(
|
||||
query?: HttpTypes.AdminRefundReasonListParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.RefundReasonsResponse>(
|
||||
`/admin/refund-reasons`,
|
||||
{
|
||||
@@ -71,4 +74,154 @@ export class RefundReason {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves a refund reason by ID. It sends a request to the
|
||||
* [Get Refund Reason](https://docs.medusajs.com/api/admin#refund-reasons_getrefundreasonsid)
|
||||
* API route.
|
||||
*
|
||||
* @param id - The refund reason's ID.
|
||||
* @param query - Configure the fields and relations to retrieve in the refund reason.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The refund reason's details.
|
||||
*
|
||||
* @example
|
||||
* To retrieve a refund reason by its ID:
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.refundReason.retrieve("refr_123")
|
||||
* .then(({ refund_reason }) => {
|
||||
* console.log(refund_reason)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To specify the fields and relations to retrieve:
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.refundReason.retrieve("refr_123", {
|
||||
* fields: "id,value"
|
||||
* })
|
||||
* .then(({ refund_reason }) => {
|
||||
* console.log(refund_reason)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin#select-fields-and-relations).
|
||||
*/
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminRefundReasonParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminRefundReasonResponse>(
|
||||
`/admin/refund-reasons/${id}`,
|
||||
{
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates a refund reason. It sends a request to the
|
||||
* [Create Refund Reason](https://docs.medusajs.com/api/admin#refund-reasons_postrefundreasons)
|
||||
* API route.
|
||||
*
|
||||
* @param body - The details of the refund reason to create.
|
||||
* @param query - Configure the fields and relations to retrieve in the refund reason.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The refund reason's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.refundReason.create({
|
||||
* value: "refund",
|
||||
* label: "Refund",
|
||||
* })
|
||||
* .then(({ refund_reason }) => {
|
||||
* console.log(refund_reason)
|
||||
* })
|
||||
*/
|
||||
async create(
|
||||
body: HttpTypes.AdminCreateRefundReason,
|
||||
query?: HttpTypes.AdminRefundReasonParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminRefundReasonResponse>(
|
||||
`/admin/refund-reasons`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method updates a refund reason. It sends a request to the
|
||||
* [Update Refund Reason](https://docs.medusajs.com/api/admin#refund-reasons_postrefundreasonsid)
|
||||
* API route.
|
||||
*
|
||||
* @param id - The refund reason's ID.
|
||||
* @param body - The details of the refund reason to update.
|
||||
* @param query - Configure the fields and relations to retrieve in the refund reason.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The refund reason's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.refundReason.update("ret_123", {
|
||||
* value: "refund",
|
||||
* label: "Refund",
|
||||
* })
|
||||
* .then(({ refund_reason }) => {
|
||||
* console.log(refund_reason)
|
||||
* })
|
||||
*/
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateRefundReason,
|
||||
query?: HttpTypes.AdminRefundReasonParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminRefundReasonResponse>(
|
||||
`/admin/refund-reasons/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method deletes a refund reason. It sends a request to the
|
||||
* [Delete Refund Reason](https://docs.medusajs.com/api/admin#refund-reasons_deleterefundreasonsid)
|
||||
* API route.
|
||||
*
|
||||
* @param id - The refund reason's ID.
|
||||
* @param query - Query parameters to pass to the request.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The deletion's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.refundReason.delete("ret_123")
|
||||
* .then(({ deleted }) => {
|
||||
* console.log(deleted)
|
||||
* })
|
||||
*/
|
||||
async delete(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminRefundReasonParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminRefundReasonDeleteResponse>(
|
||||
`/admin/refund-reasons/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export * from "./product-category"
|
||||
export * from "./product-tag"
|
||||
export * from "./product-type"
|
||||
export * from "./promotion"
|
||||
export * from "./refund-reason"
|
||||
export * from "./region"
|
||||
export * from "./reservation"
|
||||
export * from "./return"
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
BasePaymentProvider,
|
||||
BasePaymentSession,
|
||||
BaseRefund,
|
||||
RefundReason,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminPaymentProvider extends BasePaymentProvider {
|
||||
@@ -49,4 +48,3 @@ export interface AdminPaymentSession extends BasePaymentSession {
|
||||
payment_collection?: AdminPaymentCollection
|
||||
}
|
||||
export interface AdminRefund extends BaseRefund {}
|
||||
export interface AdminRefundReason extends RefundReason {}
|
||||
|
||||
@@ -22,11 +22,6 @@ export interface AdminRefundPayment {
|
||||
note?: string | null
|
||||
}
|
||||
|
||||
export interface AdminCreateRefundReason {
|
||||
label: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export interface AdminCreatePaymentCollection {
|
||||
/**
|
||||
* The ID of the order this payment collection belongs to.
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
BasePaymentFilters,
|
||||
BasePaymentSessionFilters,
|
||||
} from "../common"
|
||||
import { AdminRefundReason } from "./entities"
|
||||
import { AdminRefundReason } from "../../refund-reason"
|
||||
|
||||
export interface AdminPaymentProviderFilters
|
||||
extends FindParams,
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
AdminPaymentCollection,
|
||||
AdminPaymentProvider,
|
||||
AdminRefund,
|
||||
AdminRefundReason,
|
||||
} from "./entities"
|
||||
import { AdminRefundReason } from "../../refund-reason"
|
||||
|
||||
export interface AdminPaymentCollectionResponse {
|
||||
/**
|
||||
@@ -60,5 +60,3 @@ export type AdminPaymentProviderListResponse = PaginatedResponse<{
|
||||
*/
|
||||
payment_providers: AdminPaymentProvider[]
|
||||
}>
|
||||
|
||||
export type AdminRefundReasonDeleteResponse = DeleteResponse<"refund_reason">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
import { BaseRefundReason } from "../refund-reason/common"
|
||||
|
||||
/**
|
||||
* The payment collection's status.
|
||||
@@ -254,7 +255,7 @@ export interface BaseRefund {
|
||||
/**
|
||||
* The id of the refund_reason that is associated with the refund
|
||||
*/
|
||||
refund_reason?: RefundReason | null
|
||||
refund_reason?: BaseRefundReason | null
|
||||
|
||||
/**
|
||||
* A field to add some additional information about the refund
|
||||
@@ -337,33 +338,6 @@ export interface BasePaymentSession {
|
||||
payment?: BasePayment
|
||||
}
|
||||
|
||||
export interface RefundReason {
|
||||
/**
|
||||
* The ID of the refund reason
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The label of the refund reason
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* The description of the refund reason
|
||||
*/
|
||||
description?: string | null
|
||||
/**
|
||||
* The metadata of the refund reason
|
||||
*/
|
||||
metadata: Record<string, unknown> | null
|
||||
/**
|
||||
* When the refund reason was created
|
||||
*/
|
||||
created_at: Date | string
|
||||
/**
|
||||
* When the refund reason was updated
|
||||
*/
|
||||
updated_at: Date | string
|
||||
}
|
||||
|
||||
/**
|
||||
* The filters to apply on the retrieved payment collection.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import { BaseRefundReason } from "../common"
|
||||
|
||||
export interface AdminRefundReason extends BaseRefundReason {}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
21
packages/core/types/src/http/refund-reason/admin/payloads.ts
Normal file
21
packages/core/types/src/http/refund-reason/admin/payloads.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
type AdminBaseRefundReasonPayload = {
|
||||
/**
|
||||
* The refund reason's label.
|
||||
*
|
||||
* @example
|
||||
* "Refund"
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* The refund reason's description.
|
||||
*/
|
||||
description?: string
|
||||
/**
|
||||
* Custom key-value pairs that can be added to the refund reason.
|
||||
*/
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export interface AdminCreateRefundReason extends AdminBaseRefundReasonPayload {}
|
||||
|
||||
export interface AdminUpdateRefundReason extends AdminBaseRefundReasonPayload {}
|
||||
14
packages/core/types/src/http/refund-reason/admin/queries.ts
Normal file
14
packages/core/types/src/http/refund-reason/admin/queries.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { BaseFilterable, OperatorMap } from "../../../dal"
|
||||
import { SelectParams } from "../../common"
|
||||
import { BaseRefundReasonListParams } from "../common"
|
||||
|
||||
export interface AdminRefundReasonListParams
|
||||
extends BaseRefundReasonListParams,
|
||||
BaseFilterable<AdminRefundReasonListParams> {
|
||||
/**
|
||||
* Apply filters on the refund reason's deletion date.
|
||||
*/
|
||||
deleted_at?: OperatorMap<string>
|
||||
}
|
||||
|
||||
export interface AdminRefundReasonParams extends SelectParams {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminRefundReason } from "./entities"
|
||||
|
||||
export interface AdminRefundReasonResponse {
|
||||
/**
|
||||
* The refund reason's details.
|
||||
*/
|
||||
refund_reason: AdminRefundReason
|
||||
}
|
||||
|
||||
export interface AdminRefundReasonListResponse
|
||||
extends PaginatedResponse<{
|
||||
/**
|
||||
* The list of refund reasons.
|
||||
*/
|
||||
refund_reasons: AdminRefundReason[]
|
||||
}> {}
|
||||
|
||||
export interface AdminRefundReasonDeleteResponse
|
||||
extends DeleteResponse<"refund_reason"> {}
|
||||
42
packages/core/types/src/http/refund-reason/common.ts
Normal file
42
packages/core/types/src/http/refund-reason/common.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { OperatorMap } from "../../dal"
|
||||
import { FindParams } from "../common"
|
||||
|
||||
export interface BaseRefundReason {
|
||||
/**
|
||||
* The refund reason's ID.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The refund reason's label.
|
||||
*
|
||||
* @example
|
||||
* "Refund"
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* The refund reason's description.
|
||||
*/
|
||||
description?: string | null
|
||||
/**
|
||||
* Custom key-value pairs that can be added to the refund reason.
|
||||
*/
|
||||
metadata?: Record<string, any> | null
|
||||
/**
|
||||
* The date that the refund reason was created.
|
||||
*/
|
||||
created_at: string
|
||||
/**
|
||||
* The date that the refund reason was updated.
|
||||
*/
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface BaseRefundReasonListParams extends FindParams {
|
||||
q?: string
|
||||
id?: string | string[]
|
||||
label?: string | OperatorMap<string>
|
||||
description?: string | OperatorMap<string>
|
||||
parent_refund_reason_id?: string | OperatorMap<string | string[]>
|
||||
created_at?: OperatorMap<string>
|
||||
updated_at?: OperatorMap<string>
|
||||
}
|
||||
1
packages/core/types/src/http/refund-reason/index.ts
Normal file
1
packages/core/types/src/http/refund-reason/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./admin"
|
||||
Reference in New Issue
Block a user