fix: address PR feedback

This commit is contained in:
nikhil2004 committed 2026-09-22 03:33:27 +05:30
1 parent d5e887903e
commit de4c528d55
9 files changed
+95 -35

No files matched your search

@@ -82,6 +82,7 @@ IncidentSchema.index({ teamId: 1, startTime: -1 });
IncidentSchema.index({ status: 1, startTime: -1 });
IncidentSchema.index({ resolutionType: 1, status: 1 });
IncidentSchema.index({ resolvedBy: 1, status: 1 });
IncidentSchema.index({ monitorId: 1, startTime: -1 });
IncidentSchema.index({ createdAt: -1 });
const IncidentModel = model<IncidentDocument>("Incident", IncidentSchema);
@@ -20,6 +20,8 @@ export interface Incident {
updatedAt: string;
}
export type PublicIncident = Pick<Incident, "id" | "monitorId" | "status" | "startTime" | "endTime" | "resolutionType" | "message" | "statusCode" | "createdAt">;
export interface IncidentSummaryTopMonitor {
monitorId: string;
monitorName: string | null;
@@ -1,5 +1,5 @@
import { type IIncidentsRepository } from "@/domain/incidents/incident.repository.interface.js";
import type { Incident } from "@/domain/incidents/incident.type.js";
import type { Incident, PublicIncident } 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";
@@ -29,7 +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[]>;
getPublicMonitorIncidents(url: string, monitorId: string, date: string): Promise<PublicIncident[]>;
updateStatusPage(id: string, teamId: string, image: Express.Multer.File | undefined, data: Partial<StatusPage>): Promise<StatusPage>;
deleteStatusPage(statusPageId: string, teamId: string): Promise<StatusPage>;
@@ -105,6 +105,19 @@ export class StatusPageService implements IStatusPageService {
return base;
};
private toPublicIncident = (incident: Incident): PublicIncident => ({
id: incident.id,
monitorId: incident.monitorId,
status: incident.status,
startTime: incident.startTime,
endTime: incident.endTime,
resolutionType: incident.resolutionType,
message: incident.message ?? null,
statusCode: incident.statusCode ?? null,
createdAt: incident.createdAt,
});
createStatusPage = async (
userId: string,
teamId: string,
@@ -177,7 +190,7 @@ export class StatusPageService implements IStatusPageService {
};
};
getPublicMonitorIncidents = async (url: string, monitorId: string, date: string): Promise<Incident[]> => {
getPublicMonitorIncidents = async (url: string, monitorId: string, date: string): Promise<PublicIncident[]> => {
const statusPage = await this.getStatusPageByUrl(url);
// Ensure the status page is public
@@ -194,7 +207,8 @@ export class StatusPageService implements IStatusPageService {
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);
const incidents = await this.incidentsRepository.findByMonitorIdAndDate(monitorId, statusPage.teamId, dateStart, dateEnd);
return incidents.map(this.toPublicIncident);
};
updateStatusPage = async (id: string, teamId: string, image: Express.Multer.File | undefined, data: Partial<StatusPage>): Promise<StatusPage> => {