fix demo monitor import
This commit is contained in:
1 parent
e7f052dfa0
commit
a960e3aba2
2 files changed
+14
-21
No files matched your search
@@ -18,9 +18,7 @@ import type {
|
|||||||
IMonitorStatsRepository,
|
IMonitorStatsRepository,
|
||||||
IStatusPagesRepository,
|
IStatusPagesRepository,
|
||||||
} from "@/repositories/index.js";
|
} from "@/repositories/index.js";
|
||||||
import fs from "fs";
|
import demoMonitorsData from "@/utils/demoMonitors.json" with { type: "json" };
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
import path from "path";
|
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { ISuperSimpleQueue } from "../infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
import { ISuperSimpleQueue } from "../infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
||||||
|
|
||||||
@@ -177,23 +175,17 @@ export class MonitorService implements IMonitorService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
addDemoMonitors = async ({ userId, teamId }: { userId: string; teamId: string }): Promise<any[]> => {
|
addDemoMonitors = async ({ userId, teamId }: { userId: string; teamId: string }): Promise<any[]> => {
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const demoData = demoMonitorsData;
|
||||||
const __dirname = path.dirname(__filename);
|
const monitors = demoData.map((monitor) => ({
|
||||||
const demoMonitorsPath = path.resolve(__dirname, "../../utils/demoMonitors.json");
|
userId,
|
||||||
|
teamId,
|
||||||
const demoData = JSON.parse(fs.readFileSync(demoMonitorsPath, "utf8"));
|
name: monitor.name,
|
||||||
const monitors: Monitor[] = demoData.map((monitor: Monitor) => {
|
description: monitor.name,
|
||||||
return {
|
type: "http" as const,
|
||||||
userId,
|
url: monitor.url,
|
||||||
teamId,
|
interval: 60000,
|
||||||
name: monitor.name,
|
}));
|
||||||
description: monitor.name,
|
const demoMonitors = await this.monitorsRepository.createMonitors(monitors as unknown as Monitor[]);
|
||||||
type: "http",
|
|
||||||
url: monitor.url,
|
|
||||||
interval: 60000,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const demoMonitors = await this.monitorsRepository.createMonitors(monitors);
|
|
||||||
|
|
||||||
await Promise.all(demoMonitors.map((monitor) => this.jobQueue.addJob(monitor.id, monitor)));
|
await Promise.all(demoMonitors.map((monitor) => this.jobQueue.addJob(monitor.id, monitor)));
|
||||||
return demoMonitors;
|
return demoMonitors;
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"noUncheckedIndexedAccess": true,
|
"noUncheckedIndexedAccess": true,
|
||||||
"isolatedModules": true
|
"isolatedModules": true,
|
||||||
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["tests", "dist", "node_modules"]
|
"exclude": ["tests", "dist", "node_modules"]
|
||||||
|
|||||||
Reference in new issue
Block a user