73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import { AxiosResponse } from 'axios';
|
|
import { client } from './client';
|
|
|
|
/**
|
|
* chg_0007 lite-demo shop (products) API.
|
|
* 端点形态:POST /api/ssw/dth/books/Product/{List|Create|Update|Remove|getInfo}
|
|
* 响应壳:{code, msg, data} — 见 src/backend/src/common/action-result.filter.ts
|
|
*/
|
|
|
|
export interface ProductRow {
|
|
f_id: string;
|
|
f_name: string;
|
|
f_sku: string | null;
|
|
f_category: string | null;
|
|
f_price: string | null;
|
|
f_stock: number;
|
|
f_creator_user_id: string | null;
|
|
f_creator_time: string;
|
|
f_modify_time: string;
|
|
f_delete_mark: number;
|
|
}
|
|
|
|
interface Envelope<T> {
|
|
code: number;
|
|
msg: string;
|
|
data: T;
|
|
}
|
|
|
|
async function unwrap<T>(p: Promise<AxiosResponse<Envelope<T>>>): Promise<T> {
|
|
const r = await p;
|
|
return r.data.data;
|
|
}
|
|
|
|
export function listProducts(): Promise<ProductRow[]> {
|
|
return unwrap(client.post<Envelope<ProductRow[]>>('/ssw/dth/books/Product/List'));
|
|
}
|
|
|
|
export function createProduct(input: {
|
|
f_name: string;
|
|
f_sku?: string;
|
|
f_category?: string;
|
|
f_price?: string | number;
|
|
f_stock?: number;
|
|
}): Promise<ProductRow> {
|
|
return unwrap(
|
|
client.post<Envelope<ProductRow>>('/ssw/dth/books/Product/Create', input),
|
|
);
|
|
}
|
|
|
|
export function updateProduct(input: {
|
|
id: string;
|
|
f_name?: string;
|
|
f_sku?: string;
|
|
f_category?: string;
|
|
f_price?: string | number;
|
|
f_stock?: number;
|
|
}): Promise<ProductRow> {
|
|
return unwrap(
|
|
client.post<Envelope<ProductRow>>('/ssw/dth/books/Product/Update', input),
|
|
);
|
|
}
|
|
|
|
export function removeProduct(id: string): Promise<{ id: string }> {
|
|
return unwrap(
|
|
client.post<Envelope<{ id: string }>>('/ssw/dth/books/Product/Remove', { id }),
|
|
);
|
|
}
|
|
|
|
export function getProductInfo(id: string): Promise<ProductRow> {
|
|
return unwrap(
|
|
client.post<Envelope<ProductRow>>('/ssw/dth/books/Product/getInfo', { id }),
|
|
);
|
|
} |