repo lint errors
This commit is contained in:
1 parent
cdf17bf600
commit
120c5cd472
6 files changed
+52
-58
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import { IGeoChecksRepository } from "./IGeoChecksRepository.js";
|
||||
import type { GeoCheck, GeoCheckMetadata, GeoCheckResult, GroupedGeoCheck, GeoContinent, FlatGeoCheck } from "@/types/geoCheck.js";
|
||||
import type { FlatGeoChecksQueryResult } from "./IGeoChecksRepository.js";
|
||||
import { GeoCheckModel, type GeoCheckDocument } from "@/db/models/index.js";
|
||||
import mongoose from "mongoose";
|
||||
import { GeoCheckMetadataDocument, GeoCheckModel, type GeoCheckDocument } from "@/db/models/index.js";
|
||||
import mongoose, { PipelineStage } from "mongoose";
|
||||
import { getDateForRange } from "@/utils/dataUtils.js";
|
||||
import { ILogger } from "@/utils/logger.js";
|
||||
|
||||
@@ -31,13 +31,13 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
return value instanceof Date ? value.toISOString() : new Date(value).toISOString();
|
||||
};
|
||||
|
||||
const mapMetadata = (metadata: any): GeoCheckMetadata => ({
|
||||
const mapMetadata = (metadata: GeoCheckMetadataDocument): GeoCheckMetadata => ({
|
||||
monitorId: toStringId(metadata.monitorId),
|
||||
teamId: toStringId(metadata.teamId),
|
||||
type: metadata.type,
|
||||
});
|
||||
|
||||
const mapResults = (results: any[]): GeoCheckResult[] => {
|
||||
const mapResults = (results: GeoCheckResult[]): GeoCheckResult[] => {
|
||||
if (!results || !Array.isArray(results)) {
|
||||
return [];
|
||||
}
|
||||
@@ -89,12 +89,12 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
}))
|
||||
);
|
||||
return docs.map((doc) => this.toEntity(doc));
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Failed to createGeoChecks: ${error.message}`,
|
||||
message: error instanceof Error ? `Failed to createGeoChecks: ${error.message}` : "Failed to createGeoChecks",
|
||||
service: SERVICE_NAME,
|
||||
method: "createGeoChecks",
|
||||
stack: error.stack,
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
continents?: GeoContinent[]
|
||||
): Promise<FlatGeoChecksQueryResult> => {
|
||||
try {
|
||||
const matchStage: Record<string, any> = {
|
||||
const matchStage: Record<string, unknown> = {
|
||||
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
|
||||
...(getDateForRange(dateRange) && {
|
||||
createdAt: {
|
||||
@@ -125,22 +125,8 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
skip = page * rowsPerPage;
|
||||
}
|
||||
|
||||
if (continents && continents.length > 0) {
|
||||
const pipeline: any[] = [
|
||||
{ $match: matchStage },
|
||||
{ $unwind: "$results" },
|
||||
{
|
||||
$match: {
|
||||
"results.location.continent": { $in: continents },
|
||||
},
|
||||
},
|
||||
];
|
||||
} else {
|
||||
const pipeline: any[] = [{ $match: matchStage }, { $unwind: "$results" }];
|
||||
}
|
||||
|
||||
// Common pipeline stages for both paths
|
||||
const pipeline: any[] = [
|
||||
const pipeline: PipelineStage[] = [
|
||||
{ $match: matchStage },
|
||||
{ $unwind: "$results" },
|
||||
// Filter by continent if specified
|
||||
@@ -174,7 +160,7 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
];
|
||||
|
||||
// Count pipeline
|
||||
const countPipeline: any[] = [
|
||||
const countPipeline: PipelineStage[] = [
|
||||
{ $match: matchStage },
|
||||
{ $unwind: "$results" },
|
||||
...(continents && continents.length > 0
|
||||
@@ -206,12 +192,12 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
}));
|
||||
|
||||
return { geoChecksCount, geoChecks };
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Error finding geo checks by monitor ID: ${error.message}`,
|
||||
message: error instanceof Error ? `Error finding geo checks by monitor ID: ${error.message}` : "Error finding geo checks by monitor ID",
|
||||
service: SERVICE_NAME,
|
||||
method: "findByMonitorId",
|
||||
stack: error.stack,
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -227,11 +213,15 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
},
|
||||
}).sort({ createdAt: -1 });
|
||||
return docs.map(this.toEntity);
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Error finding geo checks by monitor ID and date range: ${error.message}`,
|
||||
message:
|
||||
error instanceof Error
|
||||
? `Error finding geo checks by monitor ID and date range: ${error.message}`
|
||||
: "Error finding geo checks by monitor ID and date range",
|
||||
service: SERVICE_NAME,
|
||||
method: "findByMonitorIdAndDateRange",
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -245,7 +235,7 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
continents?: GeoContinent[]
|
||||
): Promise<GroupedGeoCheck[]> => {
|
||||
try {
|
||||
const pipeline: any[] = [
|
||||
const pipeline: PipelineStage[] = [
|
||||
// Match geo checks for this monitor in date range
|
||||
{
|
||||
$match: {
|
||||
@@ -325,11 +315,12 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
|
||||
const results = await GeoCheckModel.aggregate(pipeline);
|
||||
return results as GroupedGeoCheck[];
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Error finding grouped geo checks: ${error.message}`,
|
||||
message: error instanceof Error ? `Error finding grouped geo checks: ${error.message}` : "Error finding grouped geo checks",
|
||||
service: SERVICE_NAME,
|
||||
method: "findGroupedByMonitorIdAndDateRange",
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -341,11 +332,12 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
|
||||
});
|
||||
return result.deletedCount || 0;
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Error deleting geo checks by monitor ID: ${error.message}`,
|
||||
message: error instanceof Error ? `Error deleting geo checks by monitor ID: ${error.message}` : "Error deleting geo checks by monitor ID",
|
||||
service: SERVICE_NAME,
|
||||
method: "deleteByMonitorId",
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -357,11 +349,12 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
"metadata.teamId": new mongoose.Types.ObjectId(teamId),
|
||||
});
|
||||
return result.deletedCount || 0;
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Error deleting geo checks by team ID: ${error.message}`,
|
||||
message: error instanceof Error ? `Error deleting geo checks by team ID: ${error.message}` : "Error deleting geo checks by team ID",
|
||||
service: SERVICE_NAME,
|
||||
method: "deleteByTeamId",
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -372,11 +365,12 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
const objectIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||
const result = await GeoCheckModel.deleteMany({ "metadata.monitorId": { $nin: objectIds } });
|
||||
return result.deletedCount || 0;
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
this.logger.error({
|
||||
message: `Error deleting orphaned geo checks: ${error.message}`,
|
||||
message: error instanceof Error ? `Error deleting orphaned geo checks: ${error.message}` : "Error deleting orphaned geo checks",
|
||||
service: SERVICE_NAME,
|
||||
method: "deleteByMonitorIdsNotIn",
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ class MongoIncidentRepository implements IIncidentsRepository {
|
||||
status?: boolean;
|
||||
monitorId?: string;
|
||||
resolutionType?: string;
|
||||
}): Record<string, any> {
|
||||
const matchStage: Record<string, any> = {
|
||||
}): Record<string, unknown> {
|
||||
const matchStage: Record<string, unknown> = {
|
||||
teamId: new mongoose.Types.ObjectId(teamId),
|
||||
...(status !== undefined && { status }),
|
||||
...(monitorId && { monitorId: new mongoose.Types.ObjectId(monitorId) }),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { MaintenanceWindow } from "@/types/index.js";
|
||||
import { type MaintenanceWindowDocument, MaintenanceWindowModel } from "@/db/models/index.js";
|
||||
import { IMaintenanceWindowsRepository } from "./IMaintenanceWindowsRepository.js";
|
||||
import mongoose from "mongoose";
|
||||
import mongoose, { SortOrder } from "mongoose";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
|
||||
class MongoMaintenanceWindowsRepository implements IMaintenanceWindowsRepository {
|
||||
@@ -81,7 +81,7 @@ class MongoMaintenanceWindowsRepository implements IMaintenanceWindowsRepository
|
||||
order?: string,
|
||||
active?: boolean
|
||||
): Promise<MaintenanceWindow[]> => {
|
||||
const maintenanceQuery: Record<string, any> = { teamId };
|
||||
const maintenanceQuery: Record<string, unknown> = { teamId };
|
||||
|
||||
if (active !== undefined) maintenanceQuery.active = active;
|
||||
|
||||
@@ -92,7 +92,7 @@ class MongoMaintenanceWindowsRepository implements IMaintenanceWindowsRepository
|
||||
}
|
||||
|
||||
// Sorting
|
||||
const sort: Record<string, any> = {};
|
||||
const sort: Record<string, SortOrder> = {};
|
||||
if (field !== undefined && order !== undefined) {
|
||||
sort[field] = order === "asc" ? 1 : -1;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ class MongoMaintenanceWindowsRepository implements IMaintenanceWindowsRepository
|
||||
return this.toEntity(deleted);
|
||||
};
|
||||
countByTeamId = async (teamId: string, active?: boolean) => {
|
||||
const maintenanceQuery: Record<string, any> = { teamId };
|
||||
const maintenanceQuery: Record<string, unknown> = { teamId };
|
||||
|
||||
if (active !== undefined) maintenanceQuery.active = active;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { MonitorModel } from "@/db/models/index.js";
|
||||
import type { MonitorDocument, CheckSnapshotDocument } from "@/db/models/index.js";
|
||||
import type { Monitor, MonitorsSummary, CheckSnapshot, Check } from "@/types/index.js";
|
||||
import type { Monitor, MonitorsSummary, CheckSnapshot } from "@/types/index.js";
|
||||
import mongoose, { type FilterQuery, type PipelineStage } from "mongoose";
|
||||
import type { IMonitorsRepository, TeamQueryConfig, SummaryConfig } from "./IMonitorsRepository.js";
|
||||
import { MongoBulkWriteError } from "mongodb";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
|
||||
class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
@@ -20,12 +21,9 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
try {
|
||||
const inserted = await MonitorModel.insertMany(payload, { ordered: false });
|
||||
return this.mapDocuments(inserted);
|
||||
} catch (error: any) {
|
||||
if (error.name === "MongoBulkWriteError" || error.name === "BulkWriteError") {
|
||||
const insertedDocs = error.insertedDocs || [];
|
||||
if (insertedDocs.length > 0) {
|
||||
return this.mapDocuments(insertedDocs);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof MongoBulkWriteError && "insertedDocs" in error && Array.isArray(error.insertedDocs) && error.insertedDocs.length > 0) {
|
||||
return this.mapDocuments(error.insertedDocs);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@@ -46,7 +44,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
};
|
||||
|
||||
findByTeamId = async (teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null> => {
|
||||
const { page = 0, rowsPerPage = 0, filter, field = "createdAt", order = "desc", type, limit } = config ?? {};
|
||||
const { page = 0, rowsPerPage = 0, filter, field = "createdAt", order = "desc", type } = config ?? {};
|
||||
|
||||
const query: Record<string, unknown> = {
|
||||
teamId: new mongoose.Types.ObjectId(teamId),
|
||||
@@ -354,7 +352,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
gameId: doc.gameId ?? undefined,
|
||||
grpcServiceName: doc.grpcServiceName ?? undefined,
|
||||
group: doc.group ?? null,
|
||||
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
||||
recentChecks: (doc.recentChecks ?? []).map((check: CheckSnapshotDocument) => this.toCheckSnapshot(check)),
|
||||
geoCheckEnabled: doc.geoCheckEnabled ?? false,
|
||||
geoCheckLocations: doc.geoCheckLocations ?? [],
|
||||
geoCheckInterval: doc.geoCheckInterval ?? 300000,
|
||||
@@ -363,7 +361,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
};
|
||||
};
|
||||
|
||||
private toEntityWithChecks = (doc: any): Monitor => {
|
||||
private toEntityWithChecks = (doc: MonitorDocument): Monitor => {
|
||||
const toStringId = (value: unknown): string => {
|
||||
if (value instanceof mongoose.Types.ObjectId) {
|
||||
return value.toString();
|
||||
@@ -413,7 +411,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
gameId: doc.gameId ?? undefined,
|
||||
grpcServiceName: doc.grpcServiceName ?? undefined,
|
||||
group: doc.group ?? null,
|
||||
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
||||
recentChecks: (doc.recentChecks ?? []).map((check: CheckSnapshotDocument) => this.toCheckSnapshot(check)),
|
||||
geoCheckEnabled: doc.geoCheckEnabled ?? false,
|
||||
geoCheckLocations: doc.geoCheckLocations ?? [],
|
||||
geoCheckInterval: doc.geoCheckInterval ?? 300000,
|
||||
|
||||
@@ -72,7 +72,8 @@ class MongoStatusPagesRepository implements IStatusPagesRepository {
|
||||
};
|
||||
|
||||
create = async (userId: string, teamId: string, image: Express.Multer.File | undefined, data: Partial<StatusPage>): Promise<StatusPage> => {
|
||||
const { logo: _logo, ...restData } = data;
|
||||
const { logo, ...restData } = data;
|
||||
void logo;
|
||||
const statusPage = new StatusPageModel({
|
||||
...restData,
|
||||
userId,
|
||||
@@ -110,7 +111,8 @@ class MongoStatusPagesRepository implements IStatusPagesRepository {
|
||||
image: Express.Multer.File | undefined,
|
||||
patch: Partial<StatusPage> & { removeLogo?: string }
|
||||
): Promise<StatusPage> => {
|
||||
const { logo: _logo, removeLogo, ...restPatch } = patch;
|
||||
const { logo, removeLogo, ...restPatch } = patch;
|
||||
void logo;
|
||||
const updateData: StatusPageUpdateData = { ...restPatch };
|
||||
if (image) {
|
||||
updateData.logo = {
|
||||
|
||||
@@ -117,7 +117,7 @@ class MongoUsersRepository implements IUsersRepository {
|
||||
|
||||
delete candidateUser.deleteProfileImage;
|
||||
|
||||
const updateQuery: Record<string, any> = { $set: candidateUser };
|
||||
const updateQuery: Record<string, unknown> = { $set: candidateUser };
|
||||
if (unsetFields) {
|
||||
updateQuery.$unset = unsetFields;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user