fix(stock): repair Flexoptix stock write path

Two bugs blocked all Flexoptix stock_observations:
1. db.ts: compatible_brands null param needs ::text[] cast; price_currency needs
   ::bpchar cast in stock_observations INSERT
2. flexoptix-api-sync.ts: UPDATE transceivers used $1 in WHERE IS NOT NULL clause
   without explicit type cast — PostgreSQL cant infer type of untyped null params
   in WHERE context. Fixed with $1::text / $2::text casts.

Result: 346 stock observations written on first run after fix.
This commit is contained in:
root 2026-07-07 11:58:09 +00:00
parent 73ad10f1a6
commit 3ebb552647
2 changed files with 5 additions and 5 deletions

View File

@ -361,11 +361,11 @@ async function importProduct(
if (product.imageUrl || product.url) { if (product.imageUrl || product.url) {
await pool.query(` await pool.query(`
UPDATE transceivers SET UPDATE transceivers SET
image_url = COALESCE(NULLIF(image_url, ''), $1), image_url = COALESCE(NULLIF(image_url, ''), $1::text),
product_page_url = COALESCE(NULLIF(product_page_url, ''), $2), product_page_url = COALESCE(NULLIF(product_page_url, ''), $2::text),
updated_at = NOW() updated_at = NOW()
WHERE id = $3 WHERE id = $3
AND ($1 IS NOT NULL OR $2 IS NOT NULL) AND ($1::text IS NOT NULL OR $2::text IS NOT NULL)
`, [product.imageUrl ?? null, product.url ?? null, transceiverId]); `, [product.imageUrl ?? null, product.url ?? null, transceiverId]);
} }

View File

@ -461,8 +461,8 @@ export async function upsertStockObservation(params: {
$5, $6::date, $5, $6::date,
$7, $8::date, $7, $8::date,
$9, $10::date, $9, $10::date,
$11, $12, $13, $14, $15, $11, $12, $13::text[], $14, $15,
$16, $17, $18, $19 $16, $17::bpchar, $18, $19
)`, )`,
[ [
params.transceiverId, params.transceiverId,