add TODOs
This commit is contained in:
1 parent
3763b668ed
commit
b708e83cce
5 files changed
+14
-1
No files matched your search
@@ -172,9 +172,10 @@ class MonitorController {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO rename to Import, change to accept JSON
|
||||
createBulkMonitors = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const userId = req.user?.id;
|
||||
const userId = req.user?.id; // TODO use the correct helper function
|
||||
if (!userId) {
|
||||
throw new AppError({ message: "User ID is required", status: 400 });
|
||||
}
|
||||
@@ -182,6 +183,9 @@ class MonitorController {
|
||||
const teamId = requireTeamId(req?.user?.teamId);
|
||||
|
||||
const data = req.body;
|
||||
|
||||
// TODO extract JSON, validate?
|
||||
|
||||
const monitors = await this.monitorService.createBulkMonitors(data, userId, teamId);
|
||||
|
||||
return res.status(200).json({
|
||||
|
||||
@@ -17,6 +17,7 @@ export interface SummaryConfig {
|
||||
export interface IMonitorsRepository {
|
||||
// create
|
||||
create(monitor: Monitor, teamId: string, userId: string): Promise<Monitor | null>;
|
||||
// TODO rename createMonitors
|
||||
createBulkMonitors(monitors: Monitor[]): Promise<Monitor[]>;
|
||||
// single fetch
|
||||
findById(monitorId: string, teamId: string): Promise<Monitor>;
|
||||
|
||||
@@ -12,6 +12,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
return this.toEntity(saved);
|
||||
};
|
||||
|
||||
// TODO rename to createMonitors, must accept JSON
|
||||
createBulkMonitors = async (monitors: Monitor[]): Promise<Monitor[]> => {
|
||||
if (!monitors.length) {
|
||||
return [];
|
||||
|
||||
@@ -26,6 +26,7 @@ class MonitorRoutes {
|
||||
|
||||
// Hardware routes
|
||||
this.router.get("/hardware/details/:monitorId", this.monitorController.getHardwareDetailsById);
|
||||
|
||||
// PageSpeed routes
|
||||
this.router.get("/pagespeed/details/:monitorId", this.monitorController.getPageSpeedDetailsById);
|
||||
|
||||
@@ -44,7 +45,11 @@ class MonitorRoutes {
|
||||
// Other static routes
|
||||
this.router.post("/demo", isAllowed(["admin", "superadmin"]), this.monitorController.addDemoMonitors);
|
||||
this.router.get("/export/json", isAllowed(["admin", "superadmin"]), this.monitorController.exportMonitorsToJSON);
|
||||
|
||||
// TODO this needs to be modified to accept JSON, change to /import
|
||||
this.router.post("/bulk", isAllowed(["admin", "superadmin"]), upload.single("csvFile"), this.monitorController.createBulkMonitors);
|
||||
// END TODO
|
||||
|
||||
this.router.post("/test-email", isAllowed(["admin", "superadmin"]), this.monitorController.sendTestEmail);
|
||||
this.router.get("/games", this.monitorController.getAllGames);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface IMonitorService {
|
||||
|
||||
// create
|
||||
createMonitor(teamId: string, userId: string, body: Monitor): Promise<void>;
|
||||
// TODO rename createMonitors
|
||||
createBulkMonitors(monitors: Array<Monitor>, userId: string, teamId: string): Promise<Monitor[] | null>;
|
||||
addDemoMonitors(args: { userId: string; teamId: string }): Promise<Monitor[]>;
|
||||
|
||||
@@ -158,6 +159,7 @@ export class MonitorService implements IMonitorService {
|
||||
};
|
||||
|
||||
createBulkMonitors = async (monitors: Array<Monitor>, userId: string, teamId: string): Promise<Monitor[] | null> => {
|
||||
// TDO rename createMonitors, change to accept JSON
|
||||
const createdMonitors = await this.monitorsRepository.createBulkMonitors(monitors);
|
||||
if (!monitors || monitors.length === 0) {
|
||||
throw new AppError({ message: "Failed to create monitors", status: 500, service: SERVICE_NAME, method: "createBulkMonitors" });
|
||||
|
||||
Reference in new issue
Block a user