feat(F-138): completed feature
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -19,6 +19,7 @@ function repository(overrides: Partial<PricingRepository> = {}): PricingReposito
|
||||
return {
|
||||
findByVariantId: async () => PRICE,
|
||||
setVariantPrice: async (_input: SetVariantPriceCommand) => PRICE,
|
||||
seedVariantPrice: async () => undefined,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user