update DB models, create tag db model
This commit is contained in:
1 parent
43ff7ca4bd
commit
a740a9e005
3 files changed
+43
-1
No files matched your search
@@ -18,11 +18,12 @@ type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Dat
|
||||
|
||||
type MonitorDocumentBase = Omit<
|
||||
Monitor,
|
||||
"id" | "userId" | "teamId" | "notifications" | "selectedDisks" | "statusWindow" | "recentChecks" | "createdAt" | "updatedAt"
|
||||
"id" | "userId" | "teamId" | "notifications" | "tags" | "selectedDisks" | "statusWindow" | "recentChecks" | "createdAt" | "updatedAt"
|
||||
> & {
|
||||
statusWindow: boolean[];
|
||||
recentChecks: CheckSnapshotDocument[];
|
||||
notifications: Types.ObjectId[];
|
||||
tags: Types.ObjectId[];
|
||||
selectedDisks: string[];
|
||||
matchMethod?: MonitorMatchMethod;
|
||||
};
|
||||
@@ -284,6 +285,12 @@ const MonitorSchema = new Schema<MonitorDocument>(
|
||||
ref: "Notification",
|
||||
},
|
||||
],
|
||||
tags: [
|
||||
{
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "Tag",
|
||||
},
|
||||
],
|
||||
secret: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Schema, model, type Types } from "mongoose";
|
||||
import type { Tag as TagEntity } from "@/types/index.js";
|
||||
|
||||
type TagDocumentBase = Omit<TagEntity, "id" | "teamId" | "createdAt" | "updatedAt">;
|
||||
|
||||
interface TagDocument extends TagDocumentBase {
|
||||
_id: Types.ObjectId;
|
||||
teamId: Types.ObjectId;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
const TagSchema = new Schema<TagDocument>(
|
||||
{
|
||||
teamId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "Team",
|
||||
immutable: true,
|
||||
required: true,
|
||||
},
|
||||
name: { type: String, required: true },
|
||||
color: { type: String, required: true, default: "#13715B" },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
TagSchema.index({ teamId: 1, name: 1 }, { unique: true });
|
||||
|
||||
const TagModel = model<TagDocument>("Tag", TagSchema);
|
||||
|
||||
export type { TagDocument };
|
||||
export { TagModel };
|
||||
export default TagModel;
|
||||
@@ -39,3 +39,5 @@ export { default as GeoCheckModel } from "@/db/models/GeoCheck.js";
|
||||
|
||||
export * from "@/db/models/DLQItem.js";
|
||||
export { default as DLQItemModel } from "@/db/models/DLQItem.js";
|
||||
export * from "@/db/models/Tag.js";
|
||||
export { default as TagModel } from "@/db/models/Tag.js";
|
||||
Reference in new issue
Block a user