feat: initial commit
This commit is contained in:
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
import type { CreateOrderDto, CustomerBalanceDto } from '@gold-bank/shared-types';
|
||||
export interface CustomerSummary {
|
||||
id: string;
|
||||
fullName: string;
|
||||
mobile: string;
|
||||
goldDebtGrams: string;
|
||||
fiatDebtRial: string;
|
||||
goldCreditLimitGrams: string;
|
||||
}
|
||||
export interface ProductVariantSummary {
|
||||
id: string;
|
||||
title: string;
|
||||
rashWeightGrams: string;
|
||||
defaultWagePercent: string;
|
||||
}
|
||||
export interface ProductSummary {
|
||||
id: string;
|
||||
title: string;
|
||||
variants: ProductVariantSummary[];
|
||||
}
|
||||
export interface OrderDetail {
|
||||
id: string;
|
||||
orderNumber: string;
|
||||
status: string;
|
||||
totalGoldWeightGrams: string;
|
||||
wageWeightGrams: string;
|
||||
flatRialCharge: string;
|
||||
isSuspendedOverCreditLimit: boolean;
|
||||
deliveredAt: string | null;
|
||||
items: Array<{
|
||||
id: string;
|
||||
quantity: number;
|
||||
computedWeightGrams: string;
|
||||
}>;
|
||||
statusEvents: Array<{
|
||||
toStatus: string;
|
||||
note: string | null;
|
||||
createdAt: string;
|
||||
}>;
|
||||
}
|
||||
export declare const api: {
|
||||
listCustomers: () => Promise<CustomerSummary[]>;
|
||||
getCustomerBalance: (id: string) => Promise<CustomerBalanceDto>;
|
||||
listProducts: () => Promise<ProductSummary[]>;
|
||||
createOrder: (dto: CreateOrderDto) => Promise<OrderDetail>;
|
||||
getOrder: (id: string) => Promise<OrderDetail>;
|
||||
updateOrderStatus: (id: string, status: string, note?: string) => Promise<OrderDetail>;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
const BASE = '/api';
|
||||
async function request(path, options) {
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
...options,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.text();
|
||||
throw new Error(`API ${path} failed (${res.status}): ${body}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
export const api = {
|
||||
listCustomers: () => request('/customers'),
|
||||
getCustomerBalance: (id) => request(`/accounting/customers/${id}/balance`),
|
||||
listProducts: () => request('/catalog/products'),
|
||||
createOrder: (dto) => request('/orders', { method: 'POST', body: JSON.stringify(dto) }),
|
||||
getOrder: (id) => request(`/orders/${id}`),
|
||||
updateOrderStatus: (id, status, note) => request(`/orders/${id}/status`, { method: 'PATCH', body: JSON.stringify({ status, note }) }),
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
import type { CreateOrderDto, CustomerBalanceDto } from '@gold-bank/shared-types';
|
||||
|
||||
const BASE = '/api';
|
||||
|
||||
async function request<T>(path: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
...options,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.text();
|
||||
throw new Error(`API ${path} failed (${res.status}): ${body}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export interface CustomerSummary {
|
||||
id: string;
|
||||
fullName: string;
|
||||
mobile: string;
|
||||
goldDebtGrams: string;
|
||||
fiatDebtRial: string;
|
||||
goldCreditLimitGrams: string;
|
||||
}
|
||||
|
||||
export interface ProductVariantSummary {
|
||||
id: string;
|
||||
title: string;
|
||||
rashWeightGrams: string;
|
||||
defaultWagePercent: string;
|
||||
}
|
||||
|
||||
export interface ProductSummary {
|
||||
id: string;
|
||||
title: string;
|
||||
variants: ProductVariantSummary[];
|
||||
}
|
||||
|
||||
export interface OrderDetail {
|
||||
id: string;
|
||||
orderNumber: string;
|
||||
status: string;
|
||||
totalGoldWeightGrams: string;
|
||||
wageWeightGrams: string;
|
||||
flatRialCharge: string;
|
||||
isSuspendedOverCreditLimit: boolean;
|
||||
deliveredAt: string | null;
|
||||
items: Array<{ id: string; quantity: number; computedWeightGrams: string }>;
|
||||
statusEvents: Array<{ toStatus: string; note: string | null; createdAt: string }>;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
listCustomers: () => request<CustomerSummary[]>('/customers'),
|
||||
getCustomerBalance: (id: string) => request<CustomerBalanceDto>(`/accounting/customers/${id}/balance`),
|
||||
listProducts: () => request<ProductSummary[]>('/catalog/products'),
|
||||
createOrder: (dto: CreateOrderDto) =>
|
||||
request<OrderDetail>('/orders', { method: 'POST', body: JSON.stringify(dto) }),
|
||||
getOrder: (id: string) => request<OrderDetail>(`/orders/${id}`),
|
||||
updateOrderStatus: (id: string, status: string, note?: string) =>
|
||||
request<OrderDetail>(`/orders/${id}/status`, { method: 'PATCH', body: JSON.stringify({ status, note }) }),
|
||||
};
|
||||
Reference in New Issue
Block a user