import
This commit is contained in:
1 parent
7ef1803cf0
commit
cdc58e5905
3 files changed
+53
-34
No files matched your search
@@ -37,6 +37,13 @@ export interface IMonitorRepository {
|
||||
monitorData: Monitor
|
||||
): Promise<Monitor>;
|
||||
|
||||
createMany(
|
||||
userId: string,
|
||||
orgId: string,
|
||||
teamId: string,
|
||||
monitorData: Monitor[]
|
||||
): Promise<Monitor[]>;
|
||||
|
||||
// Single fetch
|
||||
findAll(): Promise<Monitor[]>;
|
||||
findById(monitorId: string, teamId: string): Promise<Monitor | null>;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Monitor, IMonitor } from "@/db/models/index.js";
|
||||
import { IMonitorRepository, TeamQueryConfig } from "@/repositories/index.js";
|
||||
import { IImportedMonitor } from "@/services/business/MonitorService.js";
|
||||
import type { Monitor as MonitorEntity } from "@/types/domain/monitor.js";
|
||||
import mongoose from "mongoose";
|
||||
class MongoMonitorRepository implements IMonitorRepository {
|
||||
@@ -51,6 +52,28 @@ class MongoMonitorRepository implements IMonitorRepository {
|
||||
return this.toEntity(monitor);
|
||||
};
|
||||
|
||||
createMany = async (
|
||||
userId: string,
|
||||
orgId: string,
|
||||
teamId: string,
|
||||
monitorData: MonitorEntity[]
|
||||
) => {
|
||||
const inserted = await Monitor.insertMany(
|
||||
monitorData.map((monitor) => ({
|
||||
name: monitor.name,
|
||||
type: monitor.type,
|
||||
interval: monitor.interval,
|
||||
url: monitor.url,
|
||||
n: monitor.n,
|
||||
orgId: new mongoose.Types.ObjectId(orgId),
|
||||
teamId: new mongoose.Types.ObjectId(teamId),
|
||||
createdBy: new mongoose.Types.ObjectId(userId),
|
||||
updatedBy: new mongoose.Types.ObjectId(userId),
|
||||
}))
|
||||
);
|
||||
return inserted.map(this.toEntity);
|
||||
};
|
||||
|
||||
// Single fetch
|
||||
findById = async (monitorId: string, teamId: string) => {
|
||||
const monitor = await Monitor.findOne({ _id: monitorId, teamId });
|
||||
|
||||
Reference in new issue
Block a user