remove db module
This commit is contained in:
1 parent
e99b87fc1e
commit
9255500bfc
14 files changed
+415
-1417
No files matched your search
@@ -1,47 +1,60 @@
|
||||
import { IStatusPagesRepository } from "@/repositories/index.js";
|
||||
import { type StatusPageDocument, StatusPageModel } from "@/db/models/StatusPage.js";
|
||||
import type { StatusPage } from "@/types/statusPage.js";
|
||||
import type { StatusPage, StatusPageLogo } from "@/types/statusPage.js";
|
||||
import mongoose from "mongoose";
|
||||
|
||||
class MongoStatusPagesRepository implements IStatusPagesRepository {
|
||||
private toEntity(doc: StatusPageDocument): StatusPage {
|
||||
const toStringId = (value: unknown): string => {
|
||||
if (value instanceof mongoose.Types.ObjectId) {
|
||||
return value.toString();
|
||||
}
|
||||
return value?.toString() ?? "";
|
||||
};
|
||||
private toStringId = (value?: mongoose.Types.ObjectId | string | null): string => {
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
return value instanceof mongoose.Types.ObjectId ? value.toString() : String(value);
|
||||
};
|
||||
|
||||
const toDateString = (value: Date | string): string => {
|
||||
return value instanceof Date ? value.toISOString() : value;
|
||||
};
|
||||
private toDateString = (value?: Date | string | null): string => {
|
||||
if (!value) {
|
||||
return new Date(0).toISOString();
|
||||
}
|
||||
return value instanceof Date ? value.toISOString() : new Date(value).toISOString();
|
||||
};
|
||||
|
||||
const mapIdArray = (values?: mongoose.Types.ObjectId[]): string[] => {
|
||||
return values?.map((value) => toStringId(value)) ?? [];
|
||||
};
|
||||
private mapIdArray = (values?: Array<mongoose.Types.ObjectId | string>): string[] => {
|
||||
return values?.map((value) => this.toStringId(value)) ?? [];
|
||||
};
|
||||
|
||||
private mapLogo = (logo?: StatusPageLogo | null): StatusPageLogo | undefined => {
|
||||
if (!logo) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
id: toStringId(doc._id),
|
||||
userId: toStringId(doc.userId),
|
||||
teamId: toStringId(doc.teamId),
|
||||
data: logo.data,
|
||||
contentType: logo.contentType,
|
||||
};
|
||||
};
|
||||
|
||||
private toEntity = (doc: StatusPageDocument): StatusPage => {
|
||||
return {
|
||||
id: this.toStringId(doc._id),
|
||||
userId: this.toStringId(doc.userId),
|
||||
teamId: this.toStringId(doc.teamId),
|
||||
type: doc.type,
|
||||
companyName: doc.companyName,
|
||||
url: doc.url,
|
||||
timezone: doc.timezone ?? undefined,
|
||||
color: doc.color,
|
||||
monitors: mapIdArray(doc.monitors),
|
||||
subMonitors: mapIdArray(doc.subMonitors),
|
||||
originalMonitors: doc.originalMonitors?.map((value) => toStringId(value)),
|
||||
logo: doc.logo ?? undefined,
|
||||
monitors: this.mapIdArray(doc.monitors),
|
||||
subMonitors: this.mapIdArray(doc.subMonitors),
|
||||
originalMonitors: this.mapIdArray(doc.originalMonitors),
|
||||
logo: this.mapLogo(doc.logo),
|
||||
isPublished: doc.isPublished,
|
||||
showCharts: doc.showCharts,
|
||||
showUptimePercentage: doc.showUptimePercentage,
|
||||
showAdminLoginLink: doc.showAdminLoginLink,
|
||||
customCSS: doc.customCSS,
|
||||
createdAt: toDateString(doc.createdAt),
|
||||
updatedAt: toDateString(doc.updatedAt),
|
||||
createdAt: this.toDateString(doc.createdAt),
|
||||
updatedAt: this.toDateString(doc.updatedAt),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
removeMonitorFromStatusPages = async (monitorId: string): Promise<number> => {
|
||||
const res = await StatusPageModel.updateMany({ monitors: monitorId }, { $pull: { monitors: monitorId } });
|
||||
|
||||
Reference in new issue
Block a user