fix: bug
This commit is contained in:
parent
6adeeeb6ea
commit
1fab19e03a
|
|
@ -24,16 +24,16 @@ const MonitorBody = t.Object({
|
|||
async function replaceMonitorChannels(monitorId: string, accountId: string, channelIds: string[]) {
|
||||
await sql`DELETE FROM monitor_notifications WHERE monitor_id = ${monitorId}`;
|
||||
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 }[]>`
|
||||
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;
|
||||
await sql`
|
||||
INSERT INTO monitor_notifications (monitor_id, channel_id)
|
||||
SELECT ${monitorId}, id FROM UNNEST(${sql.array(owned.map((o) => o.id))}::uuid[]) AS id
|
||||
`;
|
||||
const rows = owned.map((o) => ({ monitor_id: monitorId, channel_id: o.id }));
|
||||
await sql`INSERT INTO monitor_notifications ${sql(rows, "monitor_id", "channel_id")}`;
|
||||
}
|
||||
|
||||
export const monitors = new Elysia({ prefix: "/monitors" })
|
||||
|
|
|
|||
Loading…
Reference in New Issue