Openstatus www.openstatus.dev
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: affected status report monitors (#1284)

* fix: affected status report monitors

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Maximilian Kaske
autofix-ci[bot]
and committed by
GitHub
7d182421 866f96ca

+53 -22
+16 -11
apps/server/src/routes/v1/statusReportUpdates/post.ts
··· 52 52 const input = c.req.valid("json"); 53 53 const limits = c.get("workspace").limits; 54 54 55 - const _statusReport = await db 56 - .select() 57 - .from(statusReport) 58 - .where( 59 - and( 60 - eq(statusReport.id, input.statusReportId), 61 - eq(statusReport.workspaceId, workspaceId), 62 - ), 63 - ) 64 - .get(); 55 + const _statusReport = await db.query.statusReport.findFirst({ 56 + where: and( 57 + eq(statusReport.id, input.statusReportId), 58 + eq(statusReport.workspaceId, workspaceId), 59 + ), 60 + with: { 61 + monitorsToStatusReports: { 62 + with: { 63 + monitor: true, 64 + }, 65 + }, 66 + }, 67 + }); 65 68 66 69 if (!_statusReport) { 67 70 throw new OpenStatusApiError({ ··· 111 114 status: _statusReport.status, 112 115 message: _statusReportUpdate.message, 113 116 date: _statusReportUpdate.date.toISOString(), 114 - monitors: _page.monitorsToPages.map((i) => i.monitor.name), 117 + monitors: _statusReport.monitorsToStatusReports.map( 118 + (i) => i.monitor.name, 119 + ), 115 120 }); 116 121 } 117 122 }
+22 -2
apps/server/src/routes/v1/statusReports/post.ts
··· 79 79 if (_monitors.length !== input.monitorIds.length) { 80 80 throw new OpenStatusApiError({ 81 81 code: "BAD_REQUEST", 82 - message: `Some of the monitors ${input.monitorIds.join(", ")} not found`, 82 + message: `Some of the monitors ${input.monitorIds.join( 83 + ", ", 84 + )} not found`, 83 85 }); 84 86 } 85 87 } ··· 156 158 }, 157 159 }); 158 160 161 + const _statusReport = await db.query.statusReport.findFirst({ 162 + where: eq(statusReport.id, _newStatusReport.id), 163 + with: { 164 + monitorsToStatusReports: { 165 + with: { monitor: true }, 166 + }, 167 + }, 168 + }); 169 + 170 + if (!_statusReport) { 171 + throw new OpenStatusApiError({ 172 + code: "INTERNAL_SERVER_ERROR", 173 + message: "Status report not found", 174 + }); 175 + } 176 + 159 177 if (pageInfo && subscribers.length > 0) { 160 178 await emailClient.sendStatusReportUpdate({ 161 179 to: subscribers.map((subscriber) => subscriber.email), ··· 164 182 status: _newStatusReport.status, 165 183 message: _newStatusReportUpdate.message, 166 184 date: _newStatusReportUpdate.date.toISOString(), 167 - monitors: pageInfo.monitorsToPages.map((i) => i.monitor.name), 185 + monitors: _statusReport.monitorsToStatusReports.map( 186 + (i) => i.monitor.name, 187 + ), 168 188 }); 169 189 } 170 190 }
+6 -6
apps/server/src/routes/v1/statusReports/update/post.ts
··· 84 84 .get(); 85 85 86 86 if (limits.notifications && _statusReport.pageId) { 87 - const allInfo = await db.query.statusReport.findFirst({ 87 + const _statusReportWithRelations = await db.query.statusReport.findFirst({ 88 88 where: eq(statusReport.id, Number(id)), 89 89 with: { 90 90 monitorsToStatusReports: { ··· 107 107 ) 108 108 .all(); 109 109 110 - if (allInfo?.page) { 110 + if (_statusReportWithRelations?.page) { 111 111 await emailClient.sendStatusReportUpdate({ 112 112 to: subscribers.map((subscriber) => subscriber.email), 113 - pageTitle: allInfo.page.title, 114 - reportTitle: allInfo.title, 115 - status: allInfo.status, 113 + pageTitle: _statusReportWithRelations.page.title, 114 + reportTitle: _statusReportWithRelations.title, 115 + status: _statusReportWithRelations.status, 116 116 message: _statusReportUpdate.message, 117 117 date: _statusReportUpdate.date.toISOString(), 118 - monitors: allInfo.monitorsToStatusReports.map( 118 + monitors: _statusReportWithRelations.monitorsToStatusReports.map( 119 119 (monitor) => monitor.monitor.name, 120 120 ), 121 121 });
+9 -3
packages/api/src/router/email/index.ts
··· 25 25 with: { 26 26 statusReport: { 27 27 with: { 28 + monitorsToStatusReports: { 29 + with: { 30 + monitor: true, 31 + }, 32 + }, 28 33 page: { 29 34 with: { 30 35 pageSubscribers: { ··· 56 61 status: _statusReportUpdate.status, 57 62 message: _statusReportUpdate.message, 58 63 date: new Date(_statusReportUpdate.date).toISOString(), 59 - monitors: _statusReportUpdate.statusReport.page.monitorsToPages.map( 60 - (i) => i.monitor.name, 61 - ), 64 + monitors: 65 + _statusReportUpdate.statusReport.monitorsToStatusReports.map( 66 + (i) => i.monitor.name, 67 + ), 62 68 }); 63 69 } 64 70 }),