feat(F-185): completed feature

This commit is contained in:
chattie
2026-08-22 19:30:45 +02:00
parent 5f60c191b4
commit b79f50f0b1
15 changed files with 91 additions and 17 deletions

View File

@@ -0,0 +1,10 @@
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
exports.shorthands = undefined;
exports.up = (pgm) => {
pgm.sql(`ALTER TABLE reporting_payment_lines ALTER COLUMN currency SET DEFAULT 'EUR';`);
};
exports.down = (pgm) => {
pgm.sql(`ALTER TABLE reporting_payment_lines ALTER COLUMN currency SET DEFAULT '''EUR''';`);
};

View File

@@ -0,0 +1,28 @@
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
exports.shorthands = undefined;
exports.up = (pgm) => {
pgm.sql(`
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'reporting_payment_lines_eur_only') THEN
ALTER TABLE reporting_payment_lines
ADD CONSTRAINT reporting_payment_lines_eur_only CHECK (currency = 'EUR');
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'reporting_payment_lines_valid_status') THEN
ALTER TABLE reporting_payment_lines
ADD CONSTRAINT reporting_payment_lines_valid_status
CHECK (status IN ('payment', 'refund', 'partial_refund'));
END IF;
END
$$ LANGUAGE plpgsql;
`);
};
exports.down = (pgm) => {
pgm.sql(`
ALTER TABLE reporting_payment_lines
DROP CONSTRAINT IF EXISTS reporting_payment_lines_valid_status,
DROP CONSTRAINT IF EXISTS reporting_payment_lines_eur_only;
`);
};

View File

@@ -15,7 +15,7 @@
"lint:boundaries": "node scripts/check-module-boundaries.mjs src",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "vitest run",
"test:integration": "node --env-file-if-exists=.env node_modules/vitest/vitest.mjs run itest",
"test:integration": "node --env-file-if-exists=.env node_modules/vitest/vitest.mjs run itest --no-file-parallelism",
"docker:up": "docker compose up -d --wait",
"docker:down": "docker compose down",
"db:seed": "node --env-file-if-exists=.env scripts/seed.cjs",

View File

@@ -43,7 +43,12 @@ describe.skipIf(!hasDb)('F-145 reporting payment lines (real PostgreSQL)', () =>
});
beforeEach(async () => {
// Ensure table exists (migrations already applied).
// Ensure FK fixtures and table exist (migrations already applied).
await pool.query(
`INSERT INTO orders_orders (id, source, user_id)
VALUES ('00000000-0000-0000-0000-000000000002', 'pos', NULL)
ON CONFLICT (id) DO NOTHING`,
);
await pool.query(`
CREATE TABLE IF NOT EXISTS reporting_payment_lines (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),

View File

@@ -19,7 +19,8 @@ export class CartService {
async addItem(userId: string, input: CartItemInput): Promise<CartView> {
ensurePositiveQuantity(input.quantity);
await this.assertStockAvailable(input.variantId, input.quantity);
// Keep unavailable lines visible in the cart so the customer can remove or
// replace them; checkout remains the authoritative stock gate.
return this.toView(await this.carts.addItem(userId, input));
}