* Create a new community brand with pending review status and initial revision.
(
input: UpsertDiscoveredBrandInput,
editor: { user_id: string; email?: string; name?: string }
)
| 831 | * Create a new community brand with pending review status and initial revision. |
| 832 | */ |
| 833 | async createDiscoveredBrand( |
| 834 | input: UpsertDiscoveredBrandInput, |
| 835 | editor: { user_id: string; email?: string; name?: string } |
| 836 | ): Promise<DiscoveredBrand> { |
| 837 | const client = await getClient(); |
| 838 | try { |
| 839 | await client.query('BEGIN'); |
| 840 | |
| 841 | const insertResult = await client.query<DiscoveredBrand>( |
| 842 | `INSERT INTO brands ( |
| 843 | domain, canonical_domain, house_domain, brand_name, brand_names, |
| 844 | keller_type, parent_brand, brand_agent_url, brand_agent_capabilities, |
| 845 | has_brand_manifest, brand_manifest, source_type, review_status, last_validated, expires_at |
| 846 | ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, 'pending', NOW(), $13) |
| 847 | RETURNING *`, |
| 848 | [ |
| 849 | input.domain.toLowerCase(), |
| 850 | input.canonical_domain || null, |
| 851 | input.house_domain || null, |
| 852 | input.brand_name || null, |
| 853 | input.brand_names ? JSON.stringify(input.brand_names) : '[]', |
| 854 | input.keller_type || null, |
| 855 | input.parent_brand || null, |
| 856 | input.brand_agent_url || null, |
| 857 | input.brand_agent_capabilities || null, |
| 858 | input.has_brand_manifest ?? false, |
| 859 | input.brand_manifest ? JSON.stringify(input.brand_manifest) : null, |
| 860 | input.source_type, |
| 861 | input.expires_at || null, |
| 862 | ] |
| 863 | ); |
| 864 | |
| 865 | const brand = insertResult.rows[0]; |
| 866 | |
| 867 | // Create revision #1 |
| 868 | await client.query( |
| 869 | `INSERT INTO brand_revisions ( |
| 870 | brand_domain, revision_number, snapshot, |
| 871 | editor_user_id, editor_email, editor_name, edit_summary |
| 872 | ) VALUES ($1, 1, $2, $3, $4, $5, 'Initial record')`, |
| 873 | [ |
| 874 | brand.domain, |
| 875 | JSON.stringify(brand), |
| 876 | editor.user_id, |
| 877 | editor.email || null, |
| 878 | editor.name || null, |
| 879 | ] |
| 880 | ); |
| 881 | |
| 882 | await client.query('COMMIT'); |
| 883 | return this.deserializeDiscoveredBrand(brand); |
| 884 | } catch (error) { |
| 885 | await client.query('ROLLBACK'); |
| 886 | throw error; |
| 887 | } finally { |
| 888 | client.release(); |
| 889 | } |
| 890 | } |
no test coverage detected