import { MongooseModule, } from "../helpers"; import { Model } from "mongoose"; import { ArcGISKeyType, GlobalSettingsType, WatchDutyApiKeyType, WatchDutySyncType, ZonehavenTokenType, } from "../types/global-settings"; import { EncryptedDataType } from "../types/common"; export interface GlobalSettings extends GlobalSettingsType { } export default async function GlobalSettingsModule(mongoose: MongooseModule) { const { Schema } = mongoose; const EncryptedData = new Schema({ iv: { type: String, default: "", }, encryptedData: { type: String, default: "", }, }, { _id: false, id: false, }); const ArcGISKey = new Schema({ item: { type: EncryptedData, default: null, }, expireAt: { type: Date, }, }, { _id: false, id: false, }); const ZonehavenToken = new Schema({ token: { type: String, default: null, }, expireAt: { type: Date, }, referer: { type: String, default: null, }, }, { _id: false, id: false, }); const WatchDutySync = new Schema({ lastModifiedAt: { type: Date, }, }, { _id: false, id: false, }); const WatchDutyApiKey = new Schema({ item: { type: EncryptedData, default: null, }, }, { _id: false, id: false, }); const modelSchema = new Schema({ _id: { type: Schema.Types.ObjectId, auto: true, }, name: { type: String, default: "global", immutable: true, }, arcgisApiKey: { type: ArcGISKey, }, zonehavenToken: { type: ZonehavenToken, }, watchDutySync: { type: WatchDutySync, }, watchDutyApiKey: { type: WatchDutyApiKey, }, updatedAt: { type: Date, }, }, { timestamps: true, autoIndex: false, toJSON: { virtuals: true, versionKey: false, } }); modelSchema.index({ name: 1, }, { name: "name_1_unique", unique: true, }); return mongoose.model("GlobalSettings", modelSchema, "massive_global_settings", { overwriteModels: true }); } export interface GlobalSettingsModel extends Model { }