Files
co-lite/solvway-admin-portal/app/lib/services/adminStock.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

102 lines
4.1 KiB
TypeScript

import { apiGet, apiPost } from "@/app/lib/clientApi";
import type {
StockInPayload,
StockOnHandPage,
ProductVariationOption,
SkuCatalogRow,
TransferPayload,
AdjustmentPayload,
MovementHistoryPage,
} from "@/app/lib/types";
// Client-side wrappers for the stock-in / stock-on-hand / product-variations BFF routes.
// Mirrors app/lib/services/adminWarehouses.ts — calls only the portal's own /api/stock/*
// route handlers (which forward the admin JWT to mobile-api's /api/admin/stock/* endpoints).
/** POST /api/stock/in — submit a stock-in transaction. */
export async function postStockIn(payload: StockInPayload): Promise<unknown> {
return apiPost<unknown>("/api/stock/in", payload);
}
export interface StockOnHandParams {
locale?: string;
warehouseId?: string;
skuVariationId?: string;
/** SKU code or name (backend `q`). */
q?: string;
page?: number;
size?: number;
sortBy?: string;
sortDir?: string;
}
/** GET /api/stock/on-hand — paged stock-on-hand listing with optional filters. */
export async function getStockOnHand(params: StockOnHandParams = {}): Promise<StockOnHandPage> {
const qs = new URLSearchParams();
if (params.locale !== undefined) qs.set("locale", params.locale);
if (params.warehouseId !== undefined) qs.set("warehouseId", params.warehouseId);
if (params.skuVariationId !== undefined) qs.set("skuVariationId", params.skuVariationId);
if (params.q) qs.set("q", params.q);
if (params.page !== undefined) qs.set("page", String(params.page));
if (params.size !== undefined) qs.set("size", String(params.size));
if (params.sortBy) {
qs.set("sortBy", params.sortBy);
if (params.sortDir) qs.set("sortDir", params.sortDir);
}
const suffix = qs.toString() ? `?${qs.toString()}` : "";
return apiGet<StockOnHandPage>(`/api/stock/on-hand${suffix}`);
}
/** GET /api/stock/product-variations/{productId} — variation options for the stock-in picker. */
export async function getProductVariations(
productId: string | number,
): Promise<ProductVariationOption[]> {
return apiGet<ProductVariationOption[]>(`/api/stock/product-variations/${productId}`);
}
/** GET /api/stock/sku-catalog — full SKU catalog (locale-parsed) for the stock-in import picker.
* Returns [] when the backend is unreachable; consumers must handle an empty catalog gracefully. */
export async function getSkuCatalog(): Promise<SkuCatalogRow[]> {
return apiGet<SkuCatalogRow[]>("/api/stock/sku-catalog");
}
/** POST /api/stock/transfer — submit a stock transfer between warehouses. */
export async function transferStock(payload: TransferPayload): Promise<unknown> {
return apiPost<unknown>("/api/stock/transfer", payload);
}
/** POST /api/stock/adjustment — submit a stock adjustment (increase or decrease) for a warehouse. */
export async function adjustStock(payload: AdjustmentPayload): Promise<unknown> {
return apiPost<unknown>("/api/stock/adjustment", payload);
}
export interface MovementsParams {
warehouseId?: string;
skuVariationId?: string;
trxnType?: string;
dateFrom?: string;
dateTo?: string;
page?: number;
size?: number;
sortBy?: string;
sortDir?: "asc" | "desc";
}
/** GET /api/stock/movements — paged movement history with optional filters. */
export async function getMovements(params: MovementsParams = {}): Promise<MovementHistoryPage> {
const qs = new URLSearchParams();
if (params.warehouseId !== undefined) qs.set("warehouseId", params.warehouseId);
if (params.skuVariationId !== undefined) qs.set("skuVariationId", params.skuVariationId);
if (params.trxnType !== undefined) qs.set("trxnType", params.trxnType);
if (params.dateFrom !== undefined) qs.set("dateFrom", params.dateFrom);
if (params.dateTo !== undefined) qs.set("dateTo", params.dateTo);
if (params.page !== undefined) qs.set("page", String(params.page));
if (params.size !== undefined) qs.set("size", String(params.size));
if (params.sortBy) {
qs.set("sortBy", params.sortBy);
if (params.sortDir) qs.set("sortDir", params.sortDir);
}
const suffix = qs.toString() ? `?${qs.toString()}` : "";
return apiGet<MovementHistoryPage>(`/api/stock/movements${suffix}`);
}