48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
"use server"
|
|
|
|
import type { PageRecord } from "@/lib/api"
|
|
import type { ProductDiscount } from "@/models/product_discount"
|
|
import { callByUser } from "./base"
|
|
|
|
export async function getAllProductDiscount() {
|
|
return callByUser<ProductDiscount[]>("/api/admin/discount/all")
|
|
}
|
|
|
|
export async function getPageProductDiscount(params: {
|
|
page: number
|
|
size: number
|
|
}) {
|
|
return callByUser<PageRecord<ProductDiscount>>(
|
|
"/api/admin/discount/page",
|
|
params,
|
|
)
|
|
}
|
|
|
|
export async function createProductDiscount(data: {
|
|
name: string
|
|
discount: string
|
|
}) {
|
|
return callByUser<ProductDiscount>("/api/admin/discount/create", {
|
|
name: data.name,
|
|
discount: Number(data.discount),
|
|
})
|
|
}
|
|
|
|
export async function updateProductDiscount(data: {
|
|
id: number
|
|
name?: string
|
|
discount?: string
|
|
}) {
|
|
return callByUser<ProductDiscount>("/api/admin/discount/update", {
|
|
id: data.id,
|
|
name: data.name,
|
|
discount: data.discount ? Number(data.discount) : undefined,
|
|
})
|
|
}
|
|
|
|
export async function deleteProductDiscount(id: number) {
|
|
return callByUser<ProductDiscount>("/api/admin/discount/remove", {
|
|
id,
|
|
})
|
|
}
|