feat(F-138): completed feature

This commit is contained in:
chattie
2026-08-22 10:18:37 +02:00
parent 5098723284
commit fb015932b2
23 changed files with 502 additions and 102 deletions

View File

@@ -42,6 +42,10 @@ export class PricingService implements PricingServicePort {
ensureNonNegativeInteger(input.netUnitAmountCents, 'Price must be a non-negative integer');
return this.repository.setVariantPrice(input);
}
async seedVariantPrice(variantId: string): Promise<void> {
await this.repository.seedVariantPrice(variantId);
}
}
function ensurePositiveInteger(value: number, message: string): void {

View File

@@ -9,9 +9,16 @@ export interface PricingService {
calculate(input: PriceCalculationCommand): Promise<PriceCalculation>;
getVariantPrice(variantId: string): Promise<VariantPrice | undefined>;
setVariantPrice(input: SetVariantPriceCommand): Promise<VariantPrice>;
/**
* Seeds a neutral default price row for a freshly created variant so that
* GET /pricing/variants/:id never 404s right after creation (F-138). Idempotent:
* no-op when a row already exists for the given variant_id.
*/
seedVariantPrice(variantId: string): Promise<void>;
}
export interface PricingRepository {
findByVariantId(variantId: string): Promise<VariantPrice | undefined>;
setVariantPrice(input: SetVariantPriceCommand): Promise<VariantPrice>;
seedVariantPrice(variantId: string): Promise<void>;
}

View File

@@ -25,6 +25,15 @@ export class PgPricingRepository implements PricingRepository {
return row ? toVariantPrice(row) : undefined;
}
async seedVariantPrice(variantId: string): Promise<void> {
await this.pool.query(
`INSERT INTO pricing_variant_prices (variant_id, net_unit_amount_cents, offer_cents, cost_cents, vat_rate)
VALUES ($1, 0, NULL, NULL, 'general')
ON CONFLICT (variant_id) DO NOTHING`,
[variantId],
);
}
async setVariantPrice(input: SetVariantPriceCommand): Promise<VariantPrice> {
const client = await this.pool.connect();
try {

View File

@@ -19,6 +19,7 @@ function repository(overrides: Partial<PricingRepository> = {}): PricingReposito
return {
findByVariantId: async () => PRICE,
setVariantPrice: async (_input: SetVariantPriceCommand) => PRICE,
seedVariantPrice: async () => undefined,
...overrides,
};
}