import { Model } from "mongoose"; import { currentDate, MongooseModule, } from "../helpers"; import { IncidentFilterKind } from "../constants"; import { IncidentFilterOption, IncidentFilterType } from "../types/incident-filter"; export interface IncidentFilter extends IncidentFilterType { } export default async function CADIncidentFilterModule(mongoose: MongooseModule) { const { Schema } = mongoose; const IncidentFilterOptionSchema = new Schema({ name: { type: String, default: "", }, visible: { type: Boolean, default: true, }, position: { type: Number, default: 1, }, value: { type: String, default: "", }, values: { type: [String], default: [], }, }, { _id: false, id: false, }); const modelSchema = new Schema({ _id: { type: Schema.Types.ObjectId, auto: true, }, departmentId: { type: String, required: true, }, name: { type: String, default: "", required: true, }, position: { type: Number, default: 1, }, kind: { type: String, enum: [ IncidentFilterKind.AgencyId, IncidentFilterKind.AreaCalOES, IncidentFilterKind.AreaUnit, IncidentFilterKind.City, IncidentFilterKind.County, IncidentFilterKind.RadioName, IncidentFilterKind.ReportNumber, IncidentFilterKind.ShowNoUnits, ], }, options: { type: [IncidentFilterOptionSchema], default: [], }, // When options are shared between multiple accounts (e.g. counties) // Reference which of the options are used by this filter reference: { type: String, default: "", }, createdAt: { type: Date, default: currentDate, }, updatedAt: { type: Date, default: currentDate, }, }, { timestamps: true, autoIndex: false, toJSON: { virtuals: true, versionKey: false, } }); modelSchema.index({ departmentId: 1, kind: 1, }, { name: "departmentId_1_kind_1_unique", unique: true, }); return mongoose.model("IncidentFilter", modelSchema, "massive_incident_filter", { overwriteModels: true }); } export interface IncidentFilterModel extends Model { }