chore: Remove last trace of client in dashboard (#8873)

This commit is contained in:
Oli Juhl
2024-08-29 17:48:01 +02:00
committed by GitHub
parent bd20d66968
commit 9cf1a5d709
23 changed files with 524 additions and 424 deletions
@@ -0,0 +1,91 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class Campaign {
private client: Client
constructor(client: Client) {
this.client = client
}
async retrieve(
id: string,
query?: HttpTypes.AdminGetCampaignParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
`/admin/campaigns/${id}`,
{
headers,
query,
}
)
}
async list(
query?: HttpTypes.AdminGetCampaignsParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminCampaignListResponse>(
`/admin/campaigns`,
{
headers,
query,
}
)
}
async create(
payload: HttpTypes.AdminCreateCampaign,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
`/admin/campaigns`,
{
method: "POST",
headers,
body: payload,
}
)
}
async update(
id: string,
payload: HttpTypes.AdminUpdateCampaign,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
`/admin/campaigns/${id}`,
{
method: "POST",
headers,
body: payload,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.DeleteResponse<"campaign">>(
`/admin/campaigns/${id}`,
{
method: "DELETE",
headers,
}
)
}
async batchPromotions(
id: string,
payload: HttpTypes.AdminBatchLink,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
`/admin/campaigns/${id}/promotions`,
{
method: "POST",
headers,
body: payload,
}
)
}
}
+6
View File
@@ -1,5 +1,6 @@
import { Client } from "../client"
import { ApiKey } from "./api-key"
import { Campaign } from "./campaign"
import { Claim } from "./claim"
import { Currency } from "./currency"
import { Customer } from "./customer"
@@ -23,6 +24,7 @@ import { ProductCollection } from "./product-collection"
import { ProductTag } from "./product-tag"
import { ProductType } from "./product-type"
import { ProductVariant } from "./product-variant"
import { Promotion } from "./promotion"
import { RefundReason } from "./refund-reasons"
import { Region } from "./region"
import Reservation from "./reservation"
@@ -79,6 +81,8 @@ export class Admin {
public workflowExecution: WorkflowExecution
public reservation: Reservation
public customerGroup: CustomerGroup
public promotion: Promotion
public campaign: Campaign
constructor(client: Client) {
this.invite = new Invite(client)
@@ -120,5 +124,7 @@ export class Admin {
this.workflowExecution = new WorkflowExecution(client)
this.reservation = new Reservation(client)
this.customerGroup = new CustomerGroup(client)
this.promotion = new Promotion(client)
this.campaign = new Campaign(client)
}
}
+170
View File
@@ -0,0 +1,170 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class Promotion {
private client: Client
constructor(client: Client) {
this.client = client
}
async retrieve(
id: string,
query?: HttpTypes.AdminGetPromotionParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
`/admin/promotions/${id}`,
{
headers,
query,
}
)
}
async list(
query?: HttpTypes.AdminGetPromotionsParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionListResponse>(
`/admin/promotions`,
{
headers,
query,
}
)
}
async create(
payload: HttpTypes.AdminCreatePromotion,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
`/admin/promotions`,
{
method: "POST",
headers,
body: payload,
}
)
}
async update(
id: string,
payload: HttpTypes.AdminUpdatePromotion,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
`/admin/promotions/${id}`,
{
method: "POST",
headers,
body: payload,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.DeleteResponse<"promotion">>(
`/admin/promotions/${id}`,
{
method: "DELETE",
headers,
}
)
}
async addRules(
id: string,
ruleType: string,
payload: HttpTypes.BatchAddPromotionRulesReq,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
`/admin/promotions/${id}/${ruleType}/batch`,
{
method: "POST",
headers,
body: { create: payload.rules },
}
)
}
async updateRules(
id: string,
ruleType: string,
payload: HttpTypes.BatchUpdatePromotionRulesReq,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
`/admin/promotions/${id}/${ruleType}/batch`,
{
method: "POST",
headers,
body: { update: payload.rules },
}
)
}
async removeRules(
id: string,
ruleType: string,
payload: HttpTypes.BatchRemovePromotionRulesReq,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
`/admin/promotions/${id}/${ruleType}/batch`,
{
method: "POST",
headers,
body: { delete: payload.rule_ids },
}
)
}
async listRules(
id: string | null,
ruleType: string,
query?: HttpTypes.AdminGetPromotionRuleParams,
headers?: ClientHeaders
) {
// eslint-disable-next-line max-len
return await this.client.fetch<HttpTypes.AdminRuleAttributeOptionsListResponse>(
`/admin/promotions/${id}/${ruleType}`,
{
headers,
query,
}
)
}
async listRuleAttributes(
ruleType: string,
promotionType?: string,
headers?: ClientHeaders
) {
// eslint-disable-next-line max-len
return await this.client.fetch<HttpTypes.AdminRuleAttributeOptionsListResponse>(
`/admin/promotions/rule-attribute-options/${ruleType}`,
{
headers,
query: { promotion_type: promotionType },
}
)
}
async listRuleValues(
ruleType: string,
ruleValue: string,
query?: HttpTypes.AdminGetPromotionsRuleValueParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminRuleValueOptionsListResponse>(
`/admin/promotions/rule-value-options/${ruleType}/${ruleValue}`,
{
headers,
query,
}
)
}
}