feat(ADM-018): completed feature

This commit is contained in:
chattie
2026-08-17 22:23:10 +02:00
parent cf1c69fc8b
commit d595b4871f
871 changed files with 47411 additions and 281 deletions

View File

@@ -0,0 +1,13 @@
export class PriceNotFoundError extends Error {
constructor() {
super('Variant price not found');
this.name = 'PriceNotFoundError';
}
}
export class InvalidPriceError extends Error {
constructor(message = 'Invalid price command') {
super(message);
this.name = 'InvalidPriceError';
}
}

View File

@@ -0,0 +1,17 @@
import type {
PriceCalculation,
PriceCalculationCommand,
SetVariantPriceCommand,
VariantPrice,
} from './price.js';
export interface PricingService {
calculate(input: PriceCalculationCommand): Promise<PriceCalculation>;
getVariantPrice(variantId: string): Promise<VariantPrice | undefined>;
setVariantPrice(input: SetVariantPriceCommand): Promise<VariantPrice>;
}
export interface PricingRepository {
findByVariantId(variantId: string): Promise<VariantPrice | undefined>;
setVariantPrice(input: SetVariantPriceCommand): Promise<VariantPrice>;
}

View File

@@ -0,0 +1,46 @@
export type VatRate = 'general' | 'reduced';
export const VAT_BASIS_POINTS: Record<VatRate, number> = {
general: 2100,
reduced: 1000,
};
export interface VariantPrice {
variantId: string;
netUnitAmountCents: number;
offerCents: number | null;
costCents: number | null;
vatRate: VatRate;
currency: 'EUR';
createdAt: Date;
updatedAt: Date;
}
export interface SetVariantPriceCommand {
variantId: string;
netUnitAmountCents: number;
offerCents?: number | null;
costCents?: number | null;
vatRate: VatRate;
}
export interface PriceCalculationCommand {
variantId: string;
quantity: number;
}
export interface PriceCalculation {
variantId: string;
quantity: number;
currency: 'EUR';
vatRate: VatRate;
vatBasisPoints: number;
netUnitAmountCents: number;
netSubtotalCents: number;
vatAmountCents: number;
totalCents: number;
}
export function calculateVatAmountCents(netSubtotalCents: number, vatRate: VatRate): number {
return Math.round((netSubtotalCents * VAT_BASIS_POINTS[vatRate]) / 10_000);
}