feat(ADM-018): completed feature
This commit is contained in:
20
project/src/modules/inventory/domain/errors.ts
Normal file
20
project/src/modules/inventory/domain/errors.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export class InvalidStockQuantityError extends Error {
|
||||
constructor() {
|
||||
super('Stock quantity must be a positive integer');
|
||||
this.name = 'InvalidStockQuantityError';
|
||||
}
|
||||
}
|
||||
|
||||
export class InsufficientStockError extends Error {
|
||||
constructor() {
|
||||
super('Insufficient stock available');
|
||||
this.name = 'InsufficientStockError';
|
||||
}
|
||||
}
|
||||
|
||||
export class InsufficientReservedStockError extends Error {
|
||||
constructor() {
|
||||
super('Insufficient reserved stock');
|
||||
this.name = 'InsufficientReservedStockError';
|
||||
}
|
||||
}
|
||||
17
project/src/modules/inventory/domain/ports.ts
Normal file
17
project/src/modules/inventory/domain/ports.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { Availability, SetAvailableStockCommand, StockCommand, StockItem } from './stock.js';
|
||||
|
||||
export interface InventoryService {
|
||||
checkAvailability(variantId: string, quantity: number): Promise<Availability>;
|
||||
reserve(input: StockCommand): Promise<StockItem>;
|
||||
release(input: StockCommand): Promise<StockItem>;
|
||||
confirm(input: StockCommand): Promise<StockItem>;
|
||||
setAvailable(input: SetAvailableStockCommand): Promise<StockItem>;
|
||||
}
|
||||
|
||||
export interface InventoryRepository {
|
||||
findByVariantId(variantId: string): Promise<StockItem | undefined>;
|
||||
setAvailable(input: SetAvailableStockCommand): Promise<StockItem>;
|
||||
reserve(input: StockCommand): Promise<StockItem | undefined>;
|
||||
release(input: StockCommand): Promise<StockItem | undefined>;
|
||||
confirm(input: StockCommand): Promise<StockItem | undefined>;
|
||||
}
|
||||
30
project/src/modules/inventory/domain/stock.ts
Normal file
30
project/src/modules/inventory/domain/stock.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export type StockState = 'available' | 'reserved' | 'sold' | 'incoming';
|
||||
|
||||
export interface StockItem {
|
||||
id: string;
|
||||
variantId: string;
|
||||
available: number;
|
||||
reserved: number;
|
||||
sold: number;
|
||||
incoming: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface StockCommand {
|
||||
variantId: string;
|
||||
quantity: number;
|
||||
}
|
||||
|
||||
export type SetAvailableStockCommand = StockCommand;
|
||||
|
||||
export interface Availability {
|
||||
available: boolean;
|
||||
availableQuantity: number;
|
||||
}
|
||||
|
||||
export function assertPositiveQuantity(quantity: number): void {
|
||||
if (!Number.isInteger(quantity) || quantity <= 0) {
|
||||
throw new Error('Stock quantity must be a positive integer');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user