({
update,
old,
}: {
update: z.infer<typeof zChannelUpdate>;
old: ChannelWithFlags | null;
})
| 240 | } |
| 241 | |
| 242 | export async function updateChannel({ |
| 243 | update, |
| 244 | old, |
| 245 | }: { |
| 246 | update: z.infer<typeof zChannelUpdate>; |
| 247 | old: ChannelWithFlags | null; |
| 248 | }) { |
| 249 | if (!old) old = await findChannelById(update.id); |
| 250 | if (!old) throw new Error('Channel not found'); |
| 251 | const combinedData = applyChannelSettingsChangesSideEffects({ |
| 252 | old, |
| 253 | updated: update, |
| 254 | }); |
| 255 | await db |
| 256 | .update(dbChannels) |
| 257 | .set(channelInsertSchema.parse(combinedData)) |
| 258 | .where(eq(dbChannels.id, update.id)); |
| 259 | |
| 260 | const updated = await db.query.dbChannels.findFirst({ |
| 261 | where: eq(dbChannels.id, update.id), |
| 262 | }); |
| 263 | |
| 264 | if (!updated) throw new Error('Error updating channel'); |
| 265 | |
| 266 | return addFlagsToChannel(updated); |
| 267 | } |
| 268 | |
| 269 | export async function updateManyChannels( |
| 270 | data: z.infer<typeof zChannelUpdateMany>[], |
no test coverage detected