import { MongooseModule, } from "../../helpers"; import { WebhookProcessLocationConfigType, WebhookProcessCommentConfigType, WebhookProcessVehicleStatusConfigType, WebhookProcessUnitIncidentUpdatesConfigType, WebhookProcessWatchDutyConfigType, WebhookProcessConfigType, WebhookAuthType, WebhookConfigType, WebhookUnitIncidentUpdateMappingType, WatchDutyFieldsType, } from "../../types/department"; export const WatchDutyFieldsDefault = [ { key: "IncidentNumber", value: "IncidentNumber", required: true, enabled: true, transformationRequired: false, }, { key: "AgencyIncidentCallTypeDescription", value: "AgencyIncidentCallTypeDescription", required: false, enabled: true, transformationRequired: false, }, { key: "Longitude", value: "Longitude", required: false, enabled: true, transformationRequired: false, }, { key: "Latitude", value: "Latitude", required: false, enabled: true, transformationRequired: false, }, { key: "full_address", value: "full_address", required: false, enabled: true, transformationRequired: false, }, { key: "DispatchDateTime", value: "DispatchDateTime", required: false, enabled: true, transformationRequired: false, }, { key: "EntryDateTime", value: "EntryDateTime", required: false, enabled: true, transformationRequired: false, }, { key: "CommandName", value: "CommandName", required: false, enabled: true, transformationRequired: false, } ]; export const WatchDutyFieldsOptsDefault = [ { key: "unitName", value: "unitName", required: true, enabled: true, transformationRequired: false, }, { key: "name", value: "name", required: false, enabled: true, transformationRequired: false, }, { key: "position", value: "position", required: false, enabled: true, transformationRequired: false, }, { key: "mobileNumber", value: "mobileNumber", required: false, enabled: true, transformationRequired: false, }, { key: "comment", value: "comment", required: false, enabled: true, transformationRequired: false, }, ]; export function WebhookProcessSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const WebhookProcessLocationConfig = new Schema({ enabled: { type: Boolean, default: false, }, locationUrl: { type: String, default: "", }, usePartnerUrl: { type: Boolean, default: false }, partnerId: { type: String, default: "" }, }, { _id: false, id: false, }); const WebhookProcessCommentConfig = new Schema({ enabled: { type: Boolean, default: false, }, commentUrl: { type: String, default: "" }, }, { _id: false, id: false, }); const WebhookProcessVehicleStatusConfig = new Schema({ enabled: { type: Boolean, default: false, }, vehicleStatusUrl: { type: String, default: "" }, vehicleStatusListUrl: { type: String, default: "" }, }, { _id: false, id: false, }); const WebhookUnitIncidentUpdateMapping = new Schema({ unitStatus: { type: String, default: "", }, unitStatusCode: { type: String, default: "", }, incidentUnitStatus: { type: String, default: "", }, }, { _id: false, id: false, }); const WebhookProcessUnitIncidentUpdatesConfig = new Schema({ enabled: { type: Boolean, default: false, }, statuses: { type: [WebhookUnitIncidentUpdateMapping], default: [], }, }, { _id: false, id: false, }); const WatchDutyFields = new Schema({ key: { type: String, default: "", }, value: { type: String, default: "", }, transformationRequired: { type: Boolean, default: false, }, required: { type: Boolean, default: false, }, enabled: { type: Boolean, default: true, }, }, { _id: false, id: false, }); const WebhookProcessWatchDutyConfig = new Schema({ enabled: { type: Boolean, default: false, }, toEmail: { type: String, default: "", }, ccEmail: { type: [String], default: [], }, incidentFields: { type: [WatchDutyFields], default: WatchDutyFieldsDefault, }, optFields: { type: [WatchDutyFields], default: WatchDutyFieldsOptsDefault, }, }, { _id: false, id: false, }); const WebhookProcessingConfig = new Schema({ location: { type: WebhookProcessLocationConfig, }, comment: { type: WebhookProcessCommentConfig, }, vehicleStatus: { type: WebhookProcessVehicleStatusConfig, }, unitIncidentUpdates: { type: WebhookProcessUnitIncidentUpdatesConfig, }, watchduty: { type: WebhookProcessWatchDutyConfig, }, }, { _id: false, id: false, }); return WebhookProcessingConfig; } export function WebhookAuthSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const WebhookAuthConfig = new Schema({ type: { type: String, default: "", }, apikey: { type: String, default: "", }, key: { type: String, default: "", }, keySecret: { type: String, default: "", }, url: { type: String, default: "", }, }, { _id: false, id: false, }); return WebhookAuthConfig; } export function WebhookSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const WebhookProcessConfig = WebhookProcessSchema(mongoose); const WebhookAuthConfig = WebhookAuthSchema(mongoose); const WebhookConfig = new Schema({ enabled: { type: Boolean, default: false, }, bulkProcessingEnabled: { type: Boolean, default: false, }, type: { type: String, default: "", }, auth: { type: WebhookAuthConfig, }, process: { type: WebhookProcessConfig, }, }, { _id: false, id: false, }); return WebhookConfig; }