( channel, values, formattedValues, channelStreams )
| 233 | }; |
| 234 | |
| 235 | export const handleEpgUpdate = async ( |
| 236 | channel, |
| 237 | values, |
| 238 | formattedValues, |
| 239 | channelStreams |
| 240 | ) => { |
| 241 | // Auto-synced channels route identity edits into the override row. Sync |
| 242 | // keeps writing provider values to Channel.* unmodified, so the override |
| 243 | // is what actually persists user changes across refreshes. `hidden_from_output` |
| 244 | // stays as a direct Channel field even for auto-created channels because |
| 245 | // it is a status flag, not a value replacement. |
| 246 | if (channel.auto_created) { |
| 247 | const overridePayload = buildOverridePayload(channel, formattedValues); |
| 248 | const payload = { |
| 249 | id: channel.id, |
| 250 | hidden_from_output: formattedValues.hidden_from_output, |
| 251 | }; |
| 252 | if (overridePayload !== undefined) { |
| 253 | payload.override = overridePayload; |
| 254 | } |
| 255 | await updateChannel(payload); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | // Manual channels: existing behavior preserved. When the EPG has changed, |
| 260 | // the dedicated set-EPG endpoint triggers an EPG refresh; other field |
| 261 | // updates go through the regular PATCH and are skipped entirely when |
| 262 | // there is nothing besides epg_data_id to update. |
| 263 | if (values.epg_data_id !== (channel.epg_data_id ?? '')) { |
| 264 | await setChannelEPG(channel, values); |
| 265 | |
| 266 | const { epg_data_id: _epg_data_id, ...otherValues } = formattedValues; |
| 267 | if (Object.keys(otherValues).length > 0) { |
| 268 | await updateChannel({ |
| 269 | id: channel.id, |
| 270 | ...otherValues, |
| 271 | streams: channelStreams.map((stream) => stream.id), |
| 272 | }); |
| 273 | } |
| 274 | } else { |
| 275 | await updateChannel({ |
| 276 | id: channel.id, |
| 277 | ...formattedValues, |
| 278 | streams: channelStreams.map((stream) => stream.id), |
| 279 | }); |
| 280 | } |
| 281 | }; |
no test coverage detected