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

+68 -37
+19 -14
apps/server/src/routes/v1/statusReportUpdates/post.ts
··· 45 45 }); 46 46 47 47 export function registerPostStatusReportUpdate( 48 - api: typeof statusReportUpdatesApi, 48 + api: typeof statusReportUpdatesApi 49 49 ) { 50 50 return api.openapi(createStatusUpdate, async (c) => { 51 51 const workspaceId = c.get("workspace").id; 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({ ··· 87 90 .where( 88 91 and( 89 92 eq(pageSubscriber.pageId, _statusReport.pageId), 90 - isNotNull(pageSubscriber.acceptedAt), 91 - ), 93 + isNotNull(pageSubscriber.acceptedAt) 94 + ) 92 95 ) 93 96 .all(); 94 97 ··· 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 }
+27 -7
apps/server/src/routes/v1/statusReports/post.ts
··· 71 71 and( 72 72 eq(monitor.workspaceId, workspaceId), 73 73 inArray(monitor.id, input.monitorIds), 74 - isNull(monitor.deletedAt), 75 - ), 74 + isNull(monitor.deletedAt) 75 + ) 76 76 ) 77 77 .all(); 78 78 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 } ··· 128 130 monitorId: id, 129 131 statusReportId: _newStatusReport.id, 130 132 }; 131 - }), 133 + }) 132 134 ) 133 135 .returning(); 134 136 } ··· 140 142 .where( 141 143 and( 142 144 eq(pageSubscriber.pageId, _newStatusReport.pageId), 143 - isNotNull(pageSubscriber.acceptedAt), 144 - ), 145 + isNotNull(pageSubscriber.acceptedAt) 146 + ) 145 147 ) 146 148 .all(); 147 149 ··· 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 }
+11 -11
apps/server/src/routes/v1/statusReports/update/post.ts
··· 59 59 .where( 60 60 and( 61 61 eq(statusReport.id, Number(id)), 62 - eq(statusReport.workspaceId, workspaceId), 63 - ), 62 + eq(statusReport.workspaceId, workspaceId) 63 + ) 64 64 ) 65 65 .returning() 66 66 .get(); ··· 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: { ··· 102 102 .where( 103 103 and( 104 104 eq(pageSubscriber.pageId, _statusReport.pageId), 105 - isNotNull(pageSubscriber.acceptedAt), 106 - ), 105 + isNotNull(pageSubscriber.acceptedAt) 106 + ) 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( 119 - (monitor) => monitor.monitor.name, 118 + monitors: _statusReportWithRelations.monitorsToStatusReports.map( 119 + (monitor) => monitor.monitor.name 120 120 ), 121 121 }); 122 122 }
+11 -5
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: { ··· 49 54 50 55 await emailClient.sendStatusReportUpdate({ 51 56 to: _statusReportUpdate.statusReport.page.pageSubscribers.map( 52 - (subscriber) => subscriber.email, 57 + (subscriber) => subscriber.email 53 58 ), 54 59 pageTitle: _statusReportUpdate.statusReport.page.title, 55 60 reportTitle: _statusReportUpdate.statusReport.title, 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 }), ··· 71 77 const _invitation = await opts.ctx.db.query.invitation.findFirst({ 72 78 where: and( 73 79 eq(invitation.id, opts.input.id), 74 - eq(invitation.workspaceId, opts.ctx.workspace.id), 80 + eq(invitation.workspaceId, opts.ctx.workspace.id) 75 81 ), 76 82 }); 77 83