import { currentDate, MongooseModule, } from "../helpers"; import { ShareReasonSchema } from "./schema/common-incident"; import { Model } from "mongoose"; import { IncidentShareCodeType } from "../types/cad"; export interface IncidentShareCode extends IncidentShareCodeType { } export default async function IncidentShareCodeModule(mongoose: MongooseModule) { const { Schema } = mongoose; const ShareReason = ShareReasonSchema(mongoose); const modelSchema = new Schema({ _id: { type: Schema.Types.ObjectId, auto: true, }, departmentId: { type: String, required: true, }, IncidentNumber: { type: String, required: true, }, AgencyIncidentCallTypeDescription: { type: String, required: true, }, joinCode: { type: String, required: true, }, createdAt: { type: Date, default: currentDate, }, expireAt: { type: Date, }, reasons: { type: [ShareReason], default: [], } }, { timestamps: true, autoIndex: false, toJSON: { virtuals: true, versionKey: false, } }); modelSchema.index({ departmentId: 1, IncidentNumber: 1, }, { name: "departmentId_1_IncidentNumber_1_unique", unique: true, }); modelSchema.index({ joinCode: 1, }, { name: "joinCode_1_unique", unique: true, }); return mongoose.model("IncidentShareCode", modelSchema, "massive_incident_share_code", { overwriteModels: true }); } export interface IncidentShareCodeModel extends Model { }