* Update member profile
(
id: string,
updates: UpdateMemberProfileInput
)
| 142 | * Update member profile |
| 143 | */ |
| 144 | async updateProfile( |
| 145 | id: string, |
| 146 | updates: UpdateMemberProfileInput |
| 147 | ): Promise<MemberProfile | null> { |
| 148 | // Build SET clause dynamically using explicit column mapping |
| 149 | const COLUMN_MAP: Record<keyof UpdateMemberProfileInput, string> = { |
| 150 | display_name: 'display_name', |
| 151 | tagline: 'tagline', |
| 152 | description: 'description', |
| 153 | primary_brand_domain: 'primary_brand_domain', |
| 154 | contact_email: 'contact_email', |
| 155 | contact_website: 'contact_website', |
| 156 | contact_phone: 'contact_phone', |
| 157 | linkedin_url: 'linkedin_url', |
| 158 | twitter_url: 'twitter_url', |
| 159 | offerings: 'offerings', |
| 160 | agents: 'agents', |
| 161 | publishers: 'publishers', |
| 162 | brands: 'brands', |
| 163 | data_providers: 'data_providers', |
| 164 | headquarters: 'headquarters', |
| 165 | markets: 'markets', |
| 166 | metadata: 'metadata', |
| 167 | tags: 'tags', |
| 168 | is_public: 'is_public', |
| 169 | show_in_carousel: 'show_in_carousel', |
| 170 | is_founding_member: 'is_founding_member', |
| 171 | }; |
| 172 | |
| 173 | const setClauses: string[] = []; |
| 174 | const params: unknown[] = []; |
| 175 | let paramIndex = 1; |
| 176 | |
| 177 | for (const [key, value] of Object.entries(updates)) { |
| 178 | const columnName = COLUMN_MAP[key as keyof UpdateMemberProfileInput]; |
| 179 | if (!columnName) { |
| 180 | continue; // Skip unknown fields |
| 181 | } |
| 182 | |
| 183 | setClauses.push(`${columnName} = $${paramIndex++}`); |
| 184 | if (key === 'metadata' || key === 'agents' || key === 'publishers' || key === 'brands' || key === 'data_providers') { |
| 185 | params.push(JSON.stringify(value)); |
| 186 | } else { |
| 187 | params.push(value); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | if (setClauses.length === 0) { |
| 192 | return this.getProfileById(id); |
| 193 | } |
| 194 | |
| 195 | params.push(id); |
| 196 | const sql = ` |
| 197 | UPDATE member_profiles |
| 198 | SET ${setClauses.join(', ')}, updated_at = NOW() |
| 199 | WHERE id = $${paramIndex} |
| 200 | RETURNING * |
| 201 | `; |
no test coverage detected