/**
 * Created by Tony on 2018/4/18.
 */

const mongoose = require("mongoose");
let rpt_customize_cfg_mdl = mongoose.model("rpt_customize_cfg");

module.exports = {
    getCustomizeCfg: getCustomizeCfg,
    saveCustomizeCfg: saveCustomizeCfg
};

async function getCustomizeCfg(userIds) {
    let filter = {"userId": userIds};
    if (userIds instanceof Array) {
        filter.userId = {$in: userIds};
    }
    return await rpt_customize_cfg_mdl.find(filter, '-_id');
}

async function saveCustomizeCfg(custCfg) {
    let filter = {"userId": custCfg.userId};
    return await rpt_customize_cfg_mdl.update(filter, custCfg, {upsert: true});
}
