feat: initial commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@gold-bank/shared-types",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// Core domain constants and DTOs shared across api / admin-panel / user-app.
|
||||
// Ported from the legacy Laravel "System A" gram-ledger (henza_server), the
|
||||
// authoritative debt model per the migration decision.
|
||||
|
||||
/** Standard purity the ledger normalizes all gold weights to (18k, per-mille). */
|
||||
export const STANDARD_KARAT_PER_MILLE = 750;
|
||||
|
||||
/** Grams per traditional Iranian "mesghal" unit, used for cash<->gram conversion. */
|
||||
export const GRAMS_PER_MESGHAL = 4.331802;
|
||||
|
||||
export enum LedgerCurrency {
|
||||
GOLD_GRAM = "GOLD_GRAM",
|
||||
RIAL = "RIAL",
|
||||
}
|
||||
|
||||
export enum LedgerDirection {
|
||||
DEBIT = "DEBIT", // increases what the customer owes
|
||||
CREDIT = "CREDIT", // decreases what the customer owes (repayment, bonus, adjustment)
|
||||
}
|
||||
|
||||
/** What generated a ledger entry. Mirrors legacy Cash.type + Order debt postings. */
|
||||
export enum LedgerSourceType {
|
||||
ORDER_STOCK = "ORDER_STOCK",
|
||||
ORDER_PRE_ORDER = "ORDER_PRE_ORDER",
|
||||
REPAYMENT_MELTED_GOLD = "REPAYMENT_MELTED_GOLD", // legacy Cash.type=1, ayar-normalized
|
||||
REPAYMENT_TRANSFER = "REPAYMENT_TRANSFER", // legacy Cash.type=2
|
||||
REPAYMENT_CHEQUE = "REPAYMENT_CHEQUE", // legacy Cash.type=3
|
||||
REPAYMENT_CASH = "REPAYMENT_CASH", // legacy Cash.type=4, price/gram-normalized
|
||||
WALLET_BONUS = "WALLET_BONUS", // cashback gold bonus, time-limited
|
||||
ADJUSTMENT = "ADJUSTMENT", // manual admin correction
|
||||
}
|
||||
|
||||
/** Stock order status flow. Debt is only posted once status reaches DELIVERED_TO_AGENT (mirrors legacy sts>4, which first becomes true at sts=5, not sts=6/DELIVERED_TO_CUSTOMER). */
|
||||
export enum OrderStatus {
|
||||
SUSPENDED = "SUSPENDED", // credit limit (gram_level) exceeded at placement
|
||||
PLACED = "PLACED",
|
||||
ADMIN_APPROVED = "ADMIN_APPROVED",
|
||||
SOURCING = "SOURCING",
|
||||
PREPARING = "PREPARING",
|
||||
DELIVERED_TO_AGENT = "DELIVERED_TO_AGENT",
|
||||
DELIVERED_TO_CUSTOMER = "DELIVERED_TO_CUSTOMER",
|
||||
CANCELLED = "CANCELLED",
|
||||
}
|
||||
|
||||
/** Pre-order (custom manufacturing) status flow — distinct from stock orders; no debt posts until priced/converted. */
|
||||
export enum PreOrderStatus {
|
||||
PLACED = "PLACED",
|
||||
ADMIN_APPROVED = "ADMIN_APPROVED",
|
||||
WORKSHOP_APPROVED = "WORKSHOP_APPROVED",
|
||||
READY_TO_SHIP = "READY_TO_SHIP",
|
||||
DELIVERED = "DELIVERED",
|
||||
CANCELLED = "CANCELLED",
|
||||
}
|
||||
|
||||
export interface CreateOrderItemDto {
|
||||
productVariantId: string;
|
||||
quantity: number;
|
||||
/** Making-charge percentage negotiated for this order (rash weight is looked up server-side from the variant, never trusted from the client). */
|
||||
wagePercent: number;
|
||||
/** Promotional discount percentage deducted from wagePercent. */
|
||||
discountPercent?: number;
|
||||
/** Flat Rial charge on this item independent of gold weight (e.g. stones). */
|
||||
flatRialCharge?: number;
|
||||
}
|
||||
|
||||
export interface CreateOrderDto {
|
||||
customerId: string;
|
||||
branchId?: string;
|
||||
items: CreateOrderItemDto[];
|
||||
}
|
||||
|
||||
export interface LedgerEntryDto {
|
||||
id: string;
|
||||
customerId: string;
|
||||
currency: LedgerCurrency;
|
||||
direction: LedgerDirection;
|
||||
sourceType: LedgerSourceType;
|
||||
amount: string; // decimal string — never use floating point for ledger money/weight
|
||||
/** Karat purity of the instrument, when applicable (melted gold repayments). */
|
||||
karatPerMille?: number;
|
||||
/** Gold price per gram at time of a cash-instrument conversion, when applicable. */
|
||||
pricePerGramAtEntry?: string;
|
||||
confirmed: boolean; // pending entries don't count toward balance until confirmed
|
||||
orderId?: string;
|
||||
note?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface CustomerBalanceDto {
|
||||
customerId: string;
|
||||
goldDebtGrams: string;
|
||||
fiatDebtRial: string;
|
||||
goldCreditLimitGrams: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user