feat: harden phase one workflows
This commit is contained in:
@@ -1,8 +1,28 @@
|
||||
import type { Product, ProductCategory, ProductSku } from '../types'
|
||||
import type { PageResponse, Product, ProductCategory, ProductSku } from '../types'
|
||||
import { apiGet, apiPost, apiPut } from './http'
|
||||
|
||||
export function listProducts() {
|
||||
return apiGet<Product[]>('/api/admin/products')
|
||||
export interface ProductQuery {
|
||||
keyword?: string
|
||||
categoryId?: number
|
||||
merchantId?: number
|
||||
pageNo?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export function buildProductQuery(query: ProductQuery = {}) {
|
||||
const params: Record<string, string | number> = {
|
||||
pageNo: query.pageNo || 1,
|
||||
pageSize: query.pageSize || 20
|
||||
}
|
||||
if (query.keyword) params.keyword = query.keyword
|
||||
if (query.categoryId) params.categoryId = query.categoryId
|
||||
if (query.merchantId) params.merchantId = query.merchantId
|
||||
return params
|
||||
}
|
||||
|
||||
export async function listProducts(query: ProductQuery = {}) {
|
||||
const page = await apiGet<PageResponse<Product>>('/api/admin/products/page', buildProductQuery(query))
|
||||
return page.records
|
||||
}
|
||||
|
||||
export function createProduct(data: Partial<Product>) {
|
||||
|
||||
Reference in New Issue
Block a user