import { Model } from "mongoose"; import { currentDate, MongooseModule, } from "../helpers"; import { IncidentFilterKind } from "../constants"; import { GeoPolygonSchema } from "./schema/geojson"; import { IncidentFilterGlobalType, } from "../types/incident-filter"; export interface IncidentFilterGlobal extends IncidentFilterGlobalType { } export default async function CADIncidentFilterGlobalModule(mongoose: MongooseModule) { const { Schema } = mongoose; const GeoPolygon = GeoPolygonSchema(mongoose); const modelSchema = new Schema({ _id: { type: Schema.Types.ObjectId, auto: true, }, group: { type: String, default: "", required: true, }, kind: { type: String, enum: [ // Polygon only (for now) IncidentFilterKind.AreaCalOES, IncidentFilterKind.AreaUnit, IncidentFilterKind.County, ], required: true, }, // Parts of IncidentFilterOption area: { type: GeoPolygon, default: { type: "Polygon", coordinates: [], } }, ring: { type: Number, default: 1, required: true, }, value: { type: String, default: "", required: true, }, createdAt: { type: Date, default: currentDate, }, updatedAt: { type: Date, default: currentDate, }, }, { timestamps: true, autoIndex: false, toJSON: { virtuals: true, versionKey: false, } }); modelSchema.index({ kind: 1, group: 1, value: 1, ring: 1, }, { name: "kind_1_group_1_value_1_ring_1_unique", unique: true, }); // Create GeoJSON index modelSchema.index({ area: "2dsphere", }, { name: "area_2dsphere", "2dsphereIndexVersion": 3 }); return mongoose.model("IncidentFilterGlobal", modelSchema, "massive_incident_filter_global", { overwriteModels: true }); } export interface IncidentFilterGlobalModel extends Model { }