purge papaparse
This commit is contained in:
1 parent
63b4779961
commit
3fa370765e
6 files changed
+48
-92
No files matched your search
Generated
-7
@@ -36,7 +36,6 @@
|
|||||||
"mongoose": "^8.3.3",
|
"mongoose": "^8.3.3",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"nodemailer": "^6.9.14",
|
"nodemailer": "^6.9.14",
|
||||||
"papaparse": "^5.5.2",
|
|
||||||
"ping": "0.4.4",
|
"ping": "0.4.4",
|
||||||
"sharp": "0.33.5",
|
"sharp": "0.33.5",
|
||||||
"ssl-checker": "2.0.10",
|
"ssl-checker": "2.0.10",
|
||||||
@@ -11567,12 +11566,6 @@
|
|||||||
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
|
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
|
||||||
"license": "BlueOak-1.0.0"
|
"license": "BlueOak-1.0.0"
|
||||||
},
|
},
|
||||||
"node_modules/papaparse": {
|
|
||||||
"version": "5.5.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.5.3.tgz",
|
|
||||||
"integrity": "sha512-5QvjGxYVjxO59MGU2lHVYpRWBBtKHnlIAcSe1uNFCkkptUh63NFRj0FJQm7nR67puEruUci/ZkjmEFrjCAyP4A==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/parent-module": {
|
"node_modules/parent-module": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
|
||||||
|
|||||||
@@ -48,7 +48,6 @@
|
|||||||
"mongoose": "^8.3.3",
|
"mongoose": "^8.3.3",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"nodemailer": "^6.9.14",
|
"nodemailer": "^6.9.14",
|
||||||
"papaparse": "^5.5.2",
|
|
||||||
"ping": "0.4.4",
|
"ping": "0.4.4",
|
||||||
"sharp": "0.33.5",
|
"sharp": "0.33.5",
|
||||||
"ssl-checker": "2.0.10",
|
"ssl-checker": "2.0.10",
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import InviteService from "../service/business/inviteService.js";
|
|||||||
import MaintenanceWindowService from "../service/business/maintenanceWindowService.js";
|
import MaintenanceWindowService from "../service/business/maintenanceWindowService.js";
|
||||||
import { MonitorService } from "@/service/index.js";
|
import { MonitorService } from "@/service/index.js";
|
||||||
import IncidentService from "../service/business/incidentService.js";
|
import IncidentService from "../service/business/incidentService.js";
|
||||||
import papaparse from "papaparse";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
import ping from "ping";
|
import ping from "ping";
|
||||||
@@ -276,7 +275,6 @@ export const initializeServices = async ({
|
|||||||
const monitorService = new MonitorService({
|
const monitorService = new MonitorService({
|
||||||
jobQueue: superSimpleQueue,
|
jobQueue: superSimpleQueue,
|
||||||
emailService,
|
emailService,
|
||||||
papaparse,
|
|
||||||
logger,
|
logger,
|
||||||
errorService,
|
errorService,
|
||||||
games,
|
games,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class IncidentController {
|
|||||||
|
|
||||||
resolveIncidentManually = async (req: Request, res: Response, next: NextFunction) => {
|
resolveIncidentManually = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
|
console.log({ user: req.user });
|
||||||
const resolvedIncident = await this.incidentService.resolveIncident(
|
const resolvedIncident = await this.incidentService.resolveIncident(
|
||||||
req?.params?.incidentId,
|
req?.params?.incidentId,
|
||||||
req?.user?.id,
|
req?.user?.id,
|
||||||
|
|||||||
@@ -174,27 +174,15 @@ class MonitorController {
|
|||||||
|
|
||||||
createBulkMonitors = async (req: Request, res: Response, next: NextFunction) => {
|
createBulkMonitors = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
if (!req.file) {
|
const userId = req.user?.id;
|
||||||
throw new AppError({ message: "No file uploaded", status: 400 });
|
if (!userId) {
|
||||||
|
throw new AppError({ message: "User ID is required", status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.file.mimetype.includes("csv")) {
|
|
||||||
throw new AppError({ message: "File is not a CSV", status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.file.size === 0) {
|
|
||||||
throw new AppError({ message: "File is empty", status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const userId = requireString(req?.user?.id, "User ID");
|
|
||||||
const teamId = requireTeamId(req?.user?.teamId);
|
const teamId = requireTeamId(req?.user?.teamId);
|
||||||
|
|
||||||
const fileData = req?.file?.buffer?.toString("utf-8");
|
const data = req.body;
|
||||||
if (!fileData) {
|
const monitors = await this.monitorService.createBulkMonitors(data, userId, teamId);
|
||||||
throw new AppError({ message: "Cannot get file from buffer", status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const monitors = await this.monitorService.createBulkMonitors(fileData, userId, teamId);
|
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { createMonitorsBodyValidation } from "@/validation/joi.js";
|
import { createMonitorsBodyValidation } from "@/validation/joi.js";
|
||||||
import { NormalizeData, NormalizeDataUptimeDetails } from "@/utils/dataUtils.js";
|
import { NormalizeData, NormalizeDataUptimeDetails } from "@/utils/dataUtils.js";
|
||||||
import { type Monitor } from "@/types/index.js";
|
import { type Monitor } from "@/types/index.js";
|
||||||
import type { MonitorType, MonitorsWithChecksByTeamIdResult, UptimeDetailsResult, HardwareDetailsResult, PageSpeedDetailsResult } from "@/types/monitor.js";
|
import type {
|
||||||
|
MonitorType,
|
||||||
|
MonitorsWithChecksByTeamIdResult,
|
||||||
|
UptimeDetailsResult,
|
||||||
|
HardwareDetailsResult,
|
||||||
|
PageSpeedDetailsResult,
|
||||||
|
} from "@/types/monitor.js";
|
||||||
import type { IChecksRepository, IMonitorsRepository, IMonitorStatsRepository, IStatusPagesRepository } from "@/repositories/index.js";
|
import type { IChecksRepository, IMonitorsRepository, IMonitorStatsRepository, IStatusPagesRepository } from "@/repositories/index.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
@@ -18,7 +24,7 @@ export interface IMonitorService {
|
|||||||
|
|
||||||
// create
|
// create
|
||||||
createMonitor(teamId: string, userId: string, body: Monitor): Promise<void>;
|
createMonitor(teamId: string, userId: string, body: Monitor): Promise<void>;
|
||||||
createBulkMonitors(fileData: string, userId: string, teamId: string): Promise<Monitor[]>;
|
createBulkMonitors(monitors: Array<Monitor>, userId: string, teamId: string): Promise<Monitor[] | null>;
|
||||||
addDemoMonitors(args: { userId: string; teamId: string }): Promise<Monitor[]>;
|
addDemoMonitors(args: { userId: string; teamId: string }): Promise<Monitor[]>;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -68,7 +74,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
|
|
||||||
private jobQueue: ISuperSimpleQueue;
|
private jobQueue: ISuperSimpleQueue;
|
||||||
private emailService: any;
|
private emailService: any;
|
||||||
private papaparse: any;
|
|
||||||
private logger: any;
|
private logger: any;
|
||||||
private errorService: any;
|
private errorService: any;
|
||||||
private games: any;
|
private games: any;
|
||||||
@@ -80,7 +85,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
constructor({
|
constructor({
|
||||||
jobQueue,
|
jobQueue,
|
||||||
emailService,
|
emailService,
|
||||||
papaparse,
|
|
||||||
logger,
|
logger,
|
||||||
errorService,
|
errorService,
|
||||||
games,
|
games,
|
||||||
@@ -91,7 +95,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
}: {
|
}: {
|
||||||
jobQueue: ISuperSimpleQueue;
|
jobQueue: ISuperSimpleQueue;
|
||||||
emailService: any;
|
emailService: any;
|
||||||
papaparse: any;
|
|
||||||
logger: any;
|
logger: any;
|
||||||
errorService: any;
|
errorService: any;
|
||||||
games: any;
|
games: any;
|
||||||
@@ -102,7 +105,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
}) {
|
}) {
|
||||||
this.jobQueue = jobQueue;
|
this.jobQueue = jobQueue;
|
||||||
this.emailService = emailService;
|
this.emailService = emailService;
|
||||||
this.papaparse = papaparse;
|
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.errorService = errorService;
|
this.errorService = errorService;
|
||||||
this.games = games;
|
this.games = games;
|
||||||
@@ -150,63 +152,14 @@ export class MonitorService implements IMonitorService {
|
|||||||
this.jobQueue.addJob(monitor.id, monitor);
|
this.jobQueue.addJob(monitor.id, monitor);
|
||||||
};
|
};
|
||||||
|
|
||||||
createBulkMonitors = async (fileData: string, userId: string, teamId: string): Promise<Monitor[]> => {
|
createBulkMonitors = async (monitors: Array<Monitor>, userId: string, teamId: string): Promise<Monitor[] | null> => {
|
||||||
const { parse } = this.papaparse;
|
const createdMonitors = await this.monitorsRepository.createBulkMonitors(monitors);
|
||||||
|
if (!monitors || monitors.length === 0) {
|
||||||
|
throw new AppError("Failed to create monitors", 500);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise<Monitor[]>((resolve, reject) => {
|
await Promise.all(createdMonitors.map((monitor) => this.jobQueue.addJob(monitor.id, monitor)));
|
||||||
parse(fileData, {
|
return createdMonitors;
|
||||||
header: true,
|
|
||||||
skipEmptyLines: true,
|
|
||||||
transform: (value: string, header: string): string | number | undefined => {
|
|
||||||
if (value === "") return undefined; // Empty fields become undefined
|
|
||||||
|
|
||||||
// Handle 'port' and 'interval' fields, check if they're valid numbers
|
|
||||||
if (["port", "interval"].includes(header)) {
|
|
||||||
const num = parseInt(value, 10);
|
|
||||||
if (isNaN(num)) {
|
|
||||||
throw this.errorService.createBadRequestError(`${header} should be a valid number, got: ${value}`);
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
complete: async ({ data, errors }: { data: any[]; errors: Error[] }): Promise<void> => {
|
|
||||||
try {
|
|
||||||
if (errors.length > 0) {
|
|
||||||
throw this.errorService.createServerError("Error parsing CSV");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data || data.length === 0) {
|
|
||||||
throw this.errorService.createServerError("CSV file contains no data rows");
|
|
||||||
}
|
|
||||||
|
|
||||||
const enrichedData = data.map((monitor: Monitor) => ({
|
|
||||||
...monitor,
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
description: monitor.description || monitor.name || monitor.url,
|
|
||||||
name: monitor.name || monitor.url,
|
|
||||||
type: monitor.type || "http",
|
|
||||||
}));
|
|
||||||
|
|
||||||
await createMonitorsBodyValidation.validateAsync(enrichedData);
|
|
||||||
|
|
||||||
const monitors = await this.monitorsRepository.createBulkMonitors(enrichedData);
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
monitors.map(async (monitor: Monitor) => {
|
|
||||||
this.jobQueue.addJob(monitor.id, monitor);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
resolve(monitors);
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addDemoMonitors = async ({ userId, teamId }: { userId: string; teamId: string }): Promise<any[]> => {
|
addDemoMonitors = async ({ userId, teamId }: { userId: string; teamId: string }): Promise<any[]> => {
|
||||||
@@ -277,7 +230,15 @@ export class MonitorService implements IMonitorService {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
getHardwareDetailsById = async ({ teamId, monitorId, dateRange }: { teamId: string; monitorId: string; dateRange: string }): Promise<HardwareDetailsResult> => {
|
getHardwareDetailsById = async ({
|
||||||
|
teamId,
|
||||||
|
monitorId,
|
||||||
|
dateRange,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
monitorId: string;
|
||||||
|
dateRange: string;
|
||||||
|
}): Promise<HardwareDetailsResult> => {
|
||||||
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
||||||
@@ -308,7 +269,15 @@ export class MonitorService implements IMonitorService {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
getPageSpeedDetailsById = async ({ teamId, monitorId, dateRange }: { teamId: string; monitorId: string; dateRange: string }): Promise<PageSpeedDetailsResult> => {
|
getPageSpeedDetailsById = async ({
|
||||||
|
teamId,
|
||||||
|
monitorId,
|
||||||
|
dateRange,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
monitorId: string;
|
||||||
|
dateRange: string;
|
||||||
|
}): Promise<PageSpeedDetailsResult> => {
|
||||||
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
||||||
@@ -342,7 +311,15 @@ export class MonitorService implements IMonitorService {
|
|||||||
return monitor;
|
return monitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
getMonitorsByTeamId = async ({ teamId, type, filter }: { teamId: string; type?: MonitorType | MonitorType[]; filter?: string }): Promise<Monitor[] | null> => {
|
getMonitorsByTeamId = async ({
|
||||||
|
teamId,
|
||||||
|
type,
|
||||||
|
filter,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
type?: MonitorType | MonitorType[];
|
||||||
|
filter?: string;
|
||||||
|
}): Promise<Monitor[] | null> => {
|
||||||
const monitors = await this.monitorsRepository.findByTeamId(teamId, {
|
const monitors = await this.monitorsRepository.findByTeamId(teamId, {
|
||||||
type,
|
type,
|
||||||
filter,
|
filter,
|
||||||
|
|||||||
Reference in new issue
Block a user