feat: clickthrough historical data view for status page downtime (#3972)
This adds the ability for users to click on any day block in the historical uptime chart to see the specific incidents that occurred on that day. Closes #3972
This commit is contained in:
1 parent
da8b230cec
commit
7f0e577dd2
15 files changed
+234
-33
No files matched your search
@@ -17,6 +17,7 @@ export interface IIncidentsRepository {
|
||||
monitorId?: string,
|
||||
resolutionType?: string
|
||||
): Promise<Incident[]>;
|
||||
findByMonitorIdAndDate(monitorId: string, teamId: string, dateStart: Date, dateEnd: Date): Promise<Incident[]>;
|
||||
findSummaryByTeamId(teamId: string, limit?: number): Promise<IncidentSummary>;
|
||||
countByTeamId(teamId: string, startDate: Date | undefined, status?: boolean, monitorId?: string, resolutionType?: string): Promise<number>;
|
||||
|
||||
|
||||
@@ -120,6 +120,17 @@ class MongoIncidentsRepository implements IIncidentsRepository {
|
||||
return this.mapDocuments(incidents);
|
||||
};
|
||||
|
||||
findByMonitorIdAndDate = async (monitorId: string, teamId: string, dateStart: Date, dateEnd: Date): Promise<Incident[]> => {
|
||||
const matchStage = {
|
||||
monitorId: new mongoose.Types.ObjectId(monitorId),
|
||||
teamId: new mongoose.Types.ObjectId(teamId),
|
||||
startTime: { $lt: dateEnd },
|
||||
$or: [{ endTime: null }, { endTime: { $gte: dateStart } }],
|
||||
};
|
||||
const incidents = await IncidentModel.find(matchStage).sort({ startTime: -1 });
|
||||
return this.mapDocuments(incidents);
|
||||
};
|
||||
|
||||
updateById = async (incidentId: string, teamId: string, patch: Partial<Incident>) => {
|
||||
const updatedIncident = await IncidentModel.findOneAndUpdate(
|
||||
{ _id: new mongoose.Types.ObjectId(incidentId), teamId: new mongoose.Types.ObjectId(teamId) },
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { type IIncidentsRepository } from "@/domain/incidents/incident.repository.interface.js";
|
||||
import type { Incident } from "@/domain/incidents/incident.type.js";
|
||||
import { type IStatusPagesRepository } from "@/domain/status-pages/status-page-repository.interface.js";
|
||||
import { ISettingsService } from "@/domain/app-settings/app-settings.service.js";
|
||||
import { IMonitorsRepository } from "@/domain/monitors/monitor.repository.interface.js";
|
||||
import { IChecksRepository } from "@/domain/checks/check.repository.interface.js";
|
||||
import type { DailyCheckBucket } from "@/domain/checks/check.type.js";
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc.js";
|
||||
import timezone from "dayjs/plugin/timezone.js";
|
||||
import {
|
||||
DEFAULT_STATUS_PAGE_THEME,
|
||||
DEFAULT_STATUS_PAGE_THEME_MODE,
|
||||
@@ -12,8 +19,9 @@ import {
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import { normalizeStatusPageDomain } from "@/utils/statusPageDomain.js";
|
||||
import { Monitor } from "@/domain/monitors/monitor.type.js";
|
||||
import { IChecksRepository } from "@/domain/checks/check.repository.interface.js";
|
||||
import type { DailyCheckBucket } from "@/domain/checks/check.type.js";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export interface IStatusPageService {
|
||||
createStatusPage(userId: string, teamId: string, image: Express.Multer.File | undefined, data: Partial<StatusPage>): Promise<StatusPage>;
|
||||
@@ -21,6 +29,7 @@ export interface IStatusPageService {
|
||||
getStatusPageByCustomDomain(customDomain: string): Promise<StatusPage>;
|
||||
getStatusPagesByTeamId(teamId: string): Promise<StatusPage[]>;
|
||||
getPublicStatusPagePayload(statusPage: StatusPage, requesterTeamId: string | undefined, range: StatusPageRange): Promise<PublicStatusPagePayload>;
|
||||
getPublicMonitorIncidents(url: string, monitorId: string, date: string): Promise<Incident[]>;
|
||||
updateStatusPage(id: string, teamId: string, image: Express.Multer.File | undefined, data: Partial<StatusPage>): Promise<StatusPage>;
|
||||
|
||||
deleteStatusPage(statusPageId: string, teamId: string): Promise<StatusPage>;
|
||||
@@ -31,7 +40,8 @@ export class StatusPageService implements IStatusPageService {
|
||||
private statusPagesRepository: IStatusPagesRepository,
|
||||
private settingsService: ISettingsService,
|
||||
private monitorsRepository: IMonitorsRepository,
|
||||
private checksRepository: IChecksRepository
|
||||
private checksRepository: IChecksRepository,
|
||||
private incidentsRepository: IIncidentsRepository
|
||||
) {}
|
||||
|
||||
private assertCustomDomainAllowed = (customDomain: string | null | undefined) => {
|
||||
@@ -167,6 +177,26 @@ export class StatusPageService implements IStatusPageService {
|
||||
};
|
||||
};
|
||||
|
||||
getPublicMonitorIncidents = async (url: string, monitorId: string, date: string): Promise<Incident[]> => {
|
||||
const statusPage = await this.getStatusPageByUrl(url);
|
||||
|
||||
// Ensure the status page is public
|
||||
if (!statusPage.isPublished) {
|
||||
throw new AppError({ message: "Forbidden", status: 403 });
|
||||
}
|
||||
|
||||
// Ensure the requested monitor actually belongs to this status page
|
||||
if (!statusPage.monitors.includes(monitorId)) {
|
||||
throw new AppError({ message: "Monitor not found on this status page", status: 404 });
|
||||
}
|
||||
|
||||
const tz = statusPage.timezone ?? "Etc/UTC";
|
||||
const dateStart = dayjs.tz(date, tz).startOf("day").toDate();
|
||||
const dateEnd = dayjs.tz(date, tz).endOf("day").toDate();
|
||||
|
||||
return this.incidentsRepository.findByMonitorIdAndDate(monitorId, statusPage.teamId, dateStart, dateEnd);
|
||||
};
|
||||
|
||||
updateStatusPage = async (id: string, teamId: string, image: Express.Multer.File | undefined, data: Partial<StatusPage>): Promise<StatusPage> => {
|
||||
const normalizedData = this.normalizeCustomDomainInput(this.normalizeInput(data));
|
||||
const updated = await this.statusPagesRepository.updateById(id, teamId, image, normalizedData);
|
||||
|
||||
Reference in new issue
Block a user