This commit is contained in:
nate 2026-04-08 13:06:16 +04:00
parent 6adeeeb6ea
commit 1fab19e03a
1 changed files with 6 additions and 6 deletions

View File

@ -24,16 +24,16 @@ const MonitorBody = t.Object({
async function replaceMonitorChannels(monitorId: string, accountId: string, channelIds: string[]) { async function replaceMonitorChannels(monitorId: string, accountId: string, channelIds: string[]) {
await sql`DELETE FROM monitor_notifications WHERE monitor_id = ${monitorId}`; await sql`DELETE FROM monitor_notifications WHERE monitor_id = ${monitorId}`;
if (channelIds.length === 0) return; if (channelIds.length === 0) return;
// Only attach channels that belong to the same account. // Only attach channels that belong to the same account. Cast to uuid[] so the
// ANY() comparison against the uuid id column type-checks.
const owned = await sql<{ id: string }[]>` const owned = await sql<{ id: string }[]>`
SELECT id FROM notification_channels SELECT id FROM notification_channels
WHERE account_id = ${accountId} AND id = ANY(${sql.array(channelIds)}) WHERE account_id = ${accountId}
AND id = ANY(${sql.array(channelIds)}::uuid[])
`; `;
if (owned.length === 0) return; if (owned.length === 0) return;
await sql` const rows = owned.map((o) => ({ monitor_id: monitorId, channel_id: o.id }));
INSERT INTO monitor_notifications (monitor_id, channel_id) await sql`INSERT INTO monitor_notifications ${sql(rows, "monitor_id", "channel_id")}`;
SELECT ${monitorId}, id FROM UNNEST(${sql.array(owned.map((o) => o.id))}::uuid[]) AS id
`;
} }
export const monitors = new Elysia({ prefix: "/monitors" }) export const monitors = new Elysia({ prefix: "/monitors" })