* Upsert a discovered brand (insert or update on conflict)
(input: UpsertDiscoveredBrandInput)
| 535 | * Upsert a discovered brand (insert or update on conflict) |
| 536 | */ |
| 537 | async upsertDiscoveredBrand(input: UpsertDiscoveredBrandInput): Promise<DiscoveredBrand> { |
| 538 | const result = await query<DiscoveredBrand>( |
| 539 | `INSERT INTO brands ( |
| 540 | domain, brand_id, canonical_domain, house_domain, brand_name, brand_names, |
| 541 | keller_type, parent_brand, brand_agent_url, brand_agent_capabilities, |
| 542 | has_brand_manifest, brand_manifest, source_type, last_validated, expires_at |
| 543 | ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, NOW(), $14) |
| 544 | ON CONFLICT (domain) DO UPDATE SET |
| 545 | brand_id = COALESCE(EXCLUDED.brand_id, brands.brand_id), |
| 546 | canonical_domain = EXCLUDED.canonical_domain, |
| 547 | house_domain = EXCLUDED.house_domain, |
| 548 | brand_name = EXCLUDED.brand_name, |
| 549 | brand_names = EXCLUDED.brand_names, |
| 550 | keller_type = EXCLUDED.keller_type, |
| 551 | parent_brand = EXCLUDED.parent_brand, |
| 552 | brand_agent_url = EXCLUDED.brand_agent_url, |
| 553 | brand_agent_capabilities = EXCLUDED.brand_agent_capabilities, |
| 554 | has_brand_manifest = COALESCE(EXCLUDED.has_brand_manifest, brands.has_brand_manifest), |
| 555 | brand_manifest = COALESCE(EXCLUDED.brand_manifest, brands.brand_manifest), |
| 556 | source_type = EXCLUDED.source_type, |
| 557 | last_validated = NOW(), |
| 558 | expires_at = EXCLUDED.expires_at |
| 559 | RETURNING *`, |
| 560 | [ |
| 561 | input.domain.toLowerCase(), |
| 562 | input.brand_id || null, |
| 563 | input.canonical_domain || null, |
| 564 | input.house_domain || null, |
| 565 | input.brand_name || null, |
| 566 | input.brand_names ? JSON.stringify(input.brand_names) : '[]', |
| 567 | input.keller_type || null, |
| 568 | input.parent_brand || null, |
| 569 | input.brand_agent_url || null, |
| 570 | input.brand_agent_capabilities || null, |
| 571 | input.has_brand_manifest != null ? input.has_brand_manifest : null, |
| 572 | input.brand_manifest ? JSON.stringify(input.brand_manifest) : null, |
| 573 | input.source_type, |
| 574 | input.expires_at || null, |
| 575 | ] |
| 576 | ); |
| 577 | return this.deserializeDiscoveredBrand(result.rows[0]); |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Get discovered brand by domain |
no test coverage detected