"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlobalsRepository = void 0;
const Globals_model_1 = require("../models/Globals.model");
class GlobalsRepository {
    async update(setting, userId) {
        await Promise.all(Object.entries(setting).map(async ([setting, value]) => {
            if (!!userId) {
                await Globals_model_1.GlobalsModel.findOneAndUpdate({ setting }, { value, userId }, { upsert: true });
            }
            else {
                await Globals_model_1.GlobalsModel.findOneAndUpdate({ setting }, { value }, { upsert: true });
            }
        }));
    }
    async getSetting(setting) {
        const settingsValues = await Globals_model_1.GlobalsModel.findOne({ setting }).lean();
        if (!settingsValues) {
            return null;
        }
        return { [setting]: settingsValues.value };
    }
}
exports.GlobalsRepository = GlobalsRepository;
