"use strict";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

var _require = require('../models/user'),
    User = _require.User;

var Hours = require('../models/hours');

var _require2 = require('mongodb'),
    ObjectId = _require2.ObjectId;

var tools = require('../tools/general');

var shared_consts = require('../tools/shared_nodejs');

var server_constants = require('../tools/server_constants');

var _require3 = require('../models/settings'),
    Settings = _require3.Settings;

var _require4 = require('../models/bot'),
    MyBot = _require4.MyBot;

var _require5 = require('../models/myelem'),
    MyElem = _require5.MyElem;

var telegrambot = require('../telegram/telegrambot');

var Cart = require('../models/cart');

var CartClass = require('../modules/Cart');

var Product = require('../models/product');

var ProductInfo = require('../models/productInfo');

var CatProd = require('../models/catprod');

var SubCatProd = require('../models/subcatprod');

var Order = require('../models/order');

var OrdersCart = require('../models/orderscart');

var Variant = require('../models/variant');

var TypedError = require('../modules/ErrorHandler');

var _require6 = require('../models/mygroup'),
    MyGroup = _require6.MyGroup;

var _require7 = require('../models/circuit'),
    Circuit = _require7.Circuit;

var _require8 = require('../models/province'),
    Province = _require8.Province;

var _require9 = require('../models/city'),
    City = _require9.City;

var _require10 = require('../models/account'),
    Account = _require10.Account;

var Macro = require('../modules/Macro');

var CronMod =
/*#__PURE__*/
function () {
  function CronMod() {
    _classCallCheck(this, CronMod);
  }

  _createClass(CronMod, [{
    key: "eseguiDbOp",
    value: function eseguiDbOp(idapp, mydata, req, res) {
      var ris, populate, globalTables, _require11, Reaction, mystr, macro, _require12, updateAllBook, _require13, _updateAllBook, num, last, ind, myuser, _require14, mssqlmigrateTables, idapporig, idappdest, _globalTables, mytablesstr, numrectot, _i, _mytablesstr, table, mytable, _require15, MyHosp, _require16, Sector, _require17, SectorGood, _require18, Skill, _require19, Good, _require20, _Sector, _require21, _SectorGood, _require22, _Skill, _require23, _Good, _require24, SubSkill, _require25, Contribtype, _require26, AdType, _require27, AdTypeGood, _require28, StatusSkill, _require29, CatGrp, _require30, _City, _require31, _Province, deleteProducts, _deleteProductInfo, deleteCatProd, deleteSubCatProd, deleteOrder, deleteOrdersCart, deleteCart, arrrec, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, rec, _arrrec, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _rec, arrrec2, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, _rec2, _require32, _City2, _require33, _Province2, _require34, MySkill, _require35, MyBacheca, _require36, _MyHosp, _require37, MyGood, _require38, _MySkill, _require39, _MyBacheca, _require40, _MyHosp2, _require41, _MyGood, _require42, _Province3, arrProv, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, recprov;

      return regeneratorRuntime.async(function eseguiDbOp$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return regeneratorRuntime.awrap(User.DbOp(idapp, mydata));

            case 2:
              ris = _context.sent;
              mydata.idapp = idapp;
              populate = require("../populate/populate");
              globalTables = require("../tools/globalTables");
              _require11 = require("../models/reaction"), Reaction = _require11.Reaction;
              mystr = "";
              _context.prev = 8;

              if (!(mydata.dbop === "")) {
                _context.next = 12;
                break;
              }

              _context.next = 682;
              break;

            case 12:
              if (!(mydata.dbop === "ScraperDataAmazon")) {
                _context.next = 17;
                break;
              }

              _context.next = 15;
              return regeneratorRuntime.awrap(ScraperDataAmazon(idapp, mydata.options));

            case 15:
              _context.next = 682;
              break;

            case 17:
              if (!(mydata.dbop === "ReplaceAllCircuits")) {
                _context.next = 22;
                break;
              }

              _context.next = 20;
              return regeneratorRuntime.awrap(Circuit.replaceAllCircuitNames(idapp));

            case 20:
              _context.next = 682;
              break;

            case 22:
              if (!(mydata.dbop === "eliminaCatProds")) {
                _context.next = 29;
                break;
              }

              _context.next = 25;
              return regeneratorRuntime.awrap(CatProd.deleteMany({
                idapp: idapp
              }));

            case 25:
              _context.next = 27;
              return regeneratorRuntime.awrap(SubCatProd.deleteMany({
                idapp: idapp
              }));

            case 27:
              _context.next = 682;
              break;

            case 29:
              if (!(mydata.dbop === "removeProductInfoWithoutDateUpdatedFromGM")) {
                _context.next = 36;
                break;
              }

              _context.next = 32;
              return regeneratorRuntime.awrap(ProductInfo.removeProductInfoWithoutDateUpdatedFromGM(idapp));

            case 32:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 36:
              if (!(mydata.dbop === "StatMacro")) {
                _context.next = 44;
                break;
              }

              macro = new Macro(idapp, {});
              _context.next = 40;
              return regeneratorRuntime.awrap(macro.getStat());

            case 40:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 44:
              if (!(mydata.dbop === "updateAllBook")) {
                _context.next = 52;
                break;
              }

              // chiama updateAllBook
              _require12 = require("../controllers/articleController"), updateAllBook = _require12.updateAllBook;
              _context.next = 48;
              return regeneratorRuntime.awrap(updateAllBook(idapp, mydata.options));

            case 48:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 52:
              if (!(mydata.dbop === "updateAllBooksAndRemoveCanc")) {
                _context.next = 61;
                break;
              }

              // chiama updateAllBooksAndRemoveCanc
              _require13 = require("../controllers/articleController"), _updateAllBook = _require13.updateAllBook;
              console.log('updateAllBooksAndRemoveCanc...');
              _context.next = 57;
              return regeneratorRuntime.awrap(_updateAllBook(idapp, {
                usaDBGMLocale: false,
                caricatutti: true,
                rimuovieventualiCancellati: true
              }));

            case 57:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 61:
              if (!(mydata.dbop === "creaUtentiTest")) {
                _context.next = 95;
                break;
              }

              num = 0;
              _context.next = 65;
              return regeneratorRuntime.awrap(User.find({
                idapp: idapp
              }).sort({
                _id: -1
              }).limit(1));

            case 65:
              lastrec = _context.sent;
              last = 1;

              if (lastrec) {
                last = lastrec[0].index;
              }

              if (!last) {
                last = 1;
              }

              ind = 0;

            case 70:
              if (!(ind < 100)) {
                _context.next = 92;
                break;
              }

              myuser = new User();
              myuser._id = new ObjectId();
              myuser.index = last + ind + 1;
              myuser.idapp = idapp;
              myuser.password = "$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG";
              myuser.lang = "it";
              myuser.email = "miaemail@email.it";
              myuser.name = "U" + myuser.index;
              myuser.surname = "Ar" + myuser.index;
              myuser.verified_email = true;
              myuser.verified_by_aportador = true;
              if (myuser.index < 2) myuser.perm = "3";
              myuser.username = "Userna_" + myuser.name;
              myuser.profile.special_req = true;
              myuser.profile.nationality = "IT";
              _context.next = 88;
              return regeneratorRuntime.awrap(myuser.save());

            case 88:
              num++;

            case 89:
              ind++;
              _context.next = 70;
              break;

            case 92:
              ris = {
                num: num
              };
              _context.next = 682;
              break;

            case 95:
              if (!(mydata.dbop === "CorreggiTabHours")) {
                _context.next = 101;
                break;
              }

              _context.next = 98;
              return regeneratorRuntime.awrap(Hours.correggiHours(idapp));

            case 98:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 101:
              if (!(mydata.dbop === "setVerifiedByAportadorToALL")) {
                _context.next = 107;
                break;
              }

              _context.next = 104;
              return regeneratorRuntime.awrap(User.setVerifiedByAportadorToALL());

            case 104:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 107:
              if (!(mydata.dbop === "RewriteContribType")) {
                _context.next = 111;
                break;
              }

              ris = populate.rewriteTable("contribtypes");
              _context.next = 682;
              break;

            case 111:
              if (!(mydata.dbop === "ReplaceUsername")) {
                _context.next = 115;
                break;
              }

              if (User.isAdmin(req.user.perm)) {
                ris = globalTables.replaceUsername(req.body.idapp, mydata.search_username, mydata.replace_username);
              }

              _context.next = 682;
              break;

            case 115:
              if (!(mydata.dbop === "ExitFromAllCircuitWithZero")) {
                _context.next = 119;
                break;
              }

              if (User.isAdmin(req.user.perm)) {
                ris = globalTables.ExitFromAllCircuitWithZero(req.body.idapp, mydata.search_username);
              }

              _context.next = 682;
              break;

            case 119:
              if (!(mydata.dbop === "replaceAportadorSolidario")) {
                _context.next = 123;
                break;
              }

              if (User.isAdmin(req.user.perm)) {
                ris = globalTables.replaceAportadorSolidario(req.body.idapp, mydata.search_username, mydata.replace_username);
              }

              _context.next = 682;
              break;

            case 123:
              if (!(mydata.dbop === "SearchString")) {
                _context.next = 131;
                break;
              }

              if (!User.isAdmin(req.user.perm)) {
                _context.next = 128;
                break;
              }

              _context.next = 127;
              return regeneratorRuntime.awrap(globalTables.SearchString(req.body.idapp, mydata.search));

            case 127:
              mystr = _context.sent;

            case 128:
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 131:
              if (!(mydata.dbop === "UpdateCatDeleteEmpty")) {
                _context.next = 138;
                break;
              }

              _context.next = 134;
              return regeneratorRuntime.awrap(CatProd.updateCatDeleteEmpty(req.body.idapp));

            case 134:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 138:
              if (!(mydata.dbop === "UpdateStatFatturato")) {
                _context.next = 145;
                break;
              }

              _context.next = 141;
              return regeneratorRuntime.awrap(ProductInfo.updateProductInfoByStats(req.body.idapp));

            case 141:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 145:
              if (!(mydata.dbop === "MigrateMSSQLToMongoDb")) {
                _context.next = 153;
                break;
              }

              _require14 = require("../controllers/articleController"), mssqlmigrateTables = _require14.mssqlmigrateTables;
              _context.next = 149;
              return regeneratorRuntime.awrap(mssqlmigrateTables(req));

            case 149:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 153:
              if (!(mydata.dbop === "copyFrom1To14")) {
                _context.next = 180;
                break;
              }

              idapporig = 1;
              idappdest = 14;

              if (!(!idapporig || !idappdest)) {
                _context.next = 158;
                break;
              }

              return _context.abrupt("return");

            case 158:
              _globalTables = require("../tools/globalTables"); //++ Todo: TO FIXIT !

              mytablesstr = ["settings", "users", "templemail", "destnewsletter", "contribtypes", "bots", "cfgservers"];
              _context.prev = 160;
              numrectot = 0;
              _i = 0, _mytablesstr = mytablesstr;

            case 163:
              if (!(_i < _mytablesstr.length)) {
                _context.next = 172;
                break;
              }

              table = _mytablesstr[_i];
              mytable = _globalTables.getTableByTableName(table);
              tools.mylogshow("copyfromapptoapp: ", table, mytable);
              _context.next = 169;
              return regeneratorRuntime.awrap(mytable.DuplicateAllRecords(idapporig, idappdest).then(function (numrec) {
                // tools.mylogshow(' REC TO MODIFY: ', rec);
                if (numrec) numrectot += numrec;
              }));

            case 169:
              _i++;
              _context.next = 163;
              break;

            case 172:
              ris = true;
              _context.next = 178;
              break;

            case 175:
              _context.prev = 175;
              _context.t0 = _context["catch"](160);
              console.log("e", _context.t0);

            case 178:
              _context.next = 682;
              break;

            case 180:
              if (!(mydata.dbop === "removeRecordsFav")) {
                _context.next = 185;
                break;
              }

              _context.next = 183;
              return regeneratorRuntime.awrap(User.removerecordsFavorite());

            case 183:
              _context.next = 682;
              break;

            case 185:
              if (!(mydata.dbop === "updateReactionsCounts")) {
                _context.next = 190;
                break;
              }

              _context.next = 188;
              return regeneratorRuntime.awrap(Reaction.updateReactionsCounts());

            case 188:
              _context.next = 682;
              break;

            case 190:
              if (!(mydata.dbop === "GeneraCSVOrdineProdotti")) {
                _context.next = 195;
                break;
              }

              _context.next = 193;
              return regeneratorRuntime.awrap(Order.GeneraCSVOrdineProdotti());

            case 193:
              _context.next = 682;
              break;

            case 195:
              if (!(mydata.dbop === "RemoveDeletedOrdersInOrderscart")) {
                _context.next = 200;
                break;
              }

              _context.next = 198;
              return regeneratorRuntime.awrap(Order.RemoveDeletedOrdersInOrderscart());

            case 198:
              _context.next = 682;
              break;

            case 200:
              if (!(mydata.dbop === "CheckTransazioniCircuiti")) {
                _context.next = 205;
                break;
              }

              _context.next = 203;
              return regeneratorRuntime.awrap(Circuit.CheckTransazioniCircuiti(false));

            case 203:
              _context.next = 682;
              break;

            case 205:
              if (!(mydata.dbop === "CorreggiTransazioniCircuiti")) {
                _context.next = 210;
                break;
              }

              _context.next = 208;
              return regeneratorRuntime.awrap(Circuit.CheckTransazioniCircuiti(true));

            case 208:
              _context.next = 682;
              break;

            case 210:
              if (!(mydata.dbop === "RemovePendentTransactions")) {
                _context.next = 216;
                break;
              }

              _context.next = 213;
              return regeneratorRuntime.awrap(SendNotif.RemovePendentTransactions(idapp));

            case 213:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 216:
              if (!(mydata.dbop === "RemoveOldNotif90")) {
                _context.next = 221;
                break;
              }

              _context.next = 219;
              return regeneratorRuntime.awrap(SendNotif.RemoveOldNotif90(idapp));

            case 219:
              _context.next = 682;
              break;

            case 221:
              if (!(mydata.dbop === "RemoveOldNotif30")) {
                _context.next = 226;
                break;
              }

              _context.next = 224;
              return regeneratorRuntime.awrap(SendNotif.RemoveOldNotif30(idapp));

            case 224:
              _context.next = 682;
              break;

            case 226:
              if (!(mydata.dbop === "UpdateCoordProv")) {
                _context.next = 231;
                break;
              }

              _context.next = 229;
              return regeneratorRuntime.awrap(Province.setCoordinatesOnDB());

            case 229:
              _context.next = 682;
              break;

            case 231:
              if (!(mydata.dbop === "insertGeojsonToMongoDB")) {
                _context.next = 236;
                break;
              }

              _context.next = 234;
              return regeneratorRuntime.awrap(City.insertGeojsonToMongoDB("comuni_italia.geojson"));

            case 234:
              _context.next = 682;
              break;

            case 236:
              if (!(mydata.dbop === "listCollectionsBySize")) {
                _context.next = 243;
                break;
              }

              _context.next = 239;
              return regeneratorRuntime.awrap(tools.listCollectionsBySize());

            case 239:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 243:
              if (!(mydata.dbop === "EnableNewsOn_ToAll")) {
                _context.next = 249;
                break;
              }

              _context.next = 246;
              return regeneratorRuntime.awrap(User.setNewsletterToAll(idapp));

            case 246:
              mystr = _context.sent;
              _context.next = 682;
              break;

            case 249:
              if (!(mydata.dbop === "MyElemSetIdPageInsteadThePah")) {
                _context.next = 256;
                break;
              }

              _context.next = 252;
              return regeneratorRuntime.awrap(MyElem.SetIdPageInsteadThePah(idapp));

            case 252:
              mystr = _context.sent;
              ris = {
                mystr: mystr
              };
              _context.next = 682;
              break;

            case 256:
              if (!(mydata.dbop === "AbilitaNewsletterALL")) {
                _context.next = 261;
                break;
              }

              _context.next = 259;
              return regeneratorRuntime.awrap(User.updateMany({
                $or: [{
                  deleted: {
                    $exists: false
                  }
                }, {
                  deleted: {
                    $exists: true,
                    $eq: false
                  }
                }]
              }, {
                $set: {
                  news_on: true
                }
              }, {
                "new": false
              }));

            case 259:
              _context.next = 682;
              break;

            case 261:
              if (!(mydata.dbop === "SvuotaTuttiGliAccessiOnlineConToken")) {
                _context.next = 266;
                break;
              }

              _context.next = 264;
              return regeneratorRuntime.awrap(User.SvuotaTuttiGliAccessiOnlineConToken(idapp));

            case 264:
              _context.next = 682;
              break;

            case 266:
              if (!(mydata.dbop === "SettaAdTypeOffro_In_Hosps")) {
                _context.next = 272;
                break;
              }

              _require15 = require("../models/myhosp"), MyHosp = _require15.MyHosp;
              _context.next = 270;
              return regeneratorRuntime.awrap(MyHosp.SettaAdTypeOffro_In_Hosps(idapp));

            case 270:
              _context.next = 682;
              break;

            case 272:
              if (!(mydata.dbop === "removeRegulations")) {
                _context.next = 277;
                break;
              }

              _context.next = 275;
              return regeneratorRuntime.awrap(Circuit.updateMany({}, {
                $set: {
                  regulation: ""
                }
              }));

            case 275:
              _context.next = 682;
              break;

            case 277:
              if (!(mydata.dbop === "newRecordsFav")) {
                _context.next = 290;
                break;
              }

              _context.next = 280;
              return regeneratorRuntime.awrap(User.moverecordsFavorite(1));

            case 280:
              _context.next = 282;
              return regeneratorRuntime.awrap(User.moverecordsFavorite(2));

            case 282:
              _context.next = 284;
              return regeneratorRuntime.awrap(User.moverecordsFavorite(3));

            case 284:
              _context.next = 286;
              return regeneratorRuntime.awrap(User.moverecordsFavorite(4));

            case 286:
              _context.next = 288;
              return regeneratorRuntime.awrap(User.moverecordsFavorite(5));

            case 288:
              _context.next = 682;
              break;

            case 290:
              if (!(mydata.dbop === "emptyTabCatServiziBeni")) {
                _context.next = 306;
                break;
              }

              _require16 = require("../models/sector"), Sector = _require16.Sector;
              _require17 = require("../models/sectorgood"), SectorGood = _require17.SectorGood;
              _require18 = require("../models/skill"), Skill = _require18.Skill;
              _require19 = require("../models/good"), Good = _require19.Good;
              _context.next = 297;
              return regeneratorRuntime.awrap(Sector.deleteMany({}));

            case 297:
              _context.next = 299;
              return regeneratorRuntime.awrap(SectorGood.deleteMany({}));

            case 299:
              _context.next = 301;
              return regeneratorRuntime.awrap(Skill.deleteMany({}));

            case 301:
              _context.next = 303;
              return regeneratorRuntime.awrap(Good.deleteMany({}));

            case 303:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 306:
              if (!(mydata.dbop === "emptyDbSkill")) {
                _context.next = 342;
                break;
              }

              // Svuota e Ricrea
              _require20 = require("../models/sector"), _Sector = _require20.Sector;
              _require21 = require("../models/sectorgood"), _SectorGood = _require21.SectorGood;
              _require22 = require("../models/skill"), _Skill = _require22.Skill;
              _require23 = require("../models/good"), _Good = _require23.Good;
              _require24 = require("../models/subskill"), SubSkill = _require24.SubSkill;
              _require25 = require("../models/contribtype"), Contribtype = _require25.Contribtype;
              _require26 = require("../models/adtype"), AdType = _require26.AdType;
              _require27 = require("../models/adtypegood"), AdTypeGood = _require27.AdTypeGood;
              _require28 = require("../models/statusSkill"), StatusSkill = _require28.StatusSkill;
              _require29 = require("../models/catgrp"), CatGrp = _require29.CatGrp;
              _context.next = 319;
              return regeneratorRuntime.awrap(_Sector.deleteMany({}));

            case 319:
              _context.next = 321;
              return regeneratorRuntime.awrap(_SectorGood.deleteMany({}));

            case 321:
              _context.next = 323;
              return regeneratorRuntime.awrap(_Skill.deleteMany({}));

            case 323:
              _context.next = 325;
              return regeneratorRuntime.awrap(_Good.deleteMany({}));

            case 325:
              _context.next = 327;
              return regeneratorRuntime.awrap(SubSkill.deleteMany({}));

            case 327:
              _context.next = 329;
              return regeneratorRuntime.awrap(Contribtype.deleteMany({}));

            case 329:
              _context.next = 331;
              return regeneratorRuntime.awrap(AdType.deleteMany({}));

            case 331:
              _context.next = 333;
              return regeneratorRuntime.awrap(AdTypeGood.deleteMany({}));

            case 333:
              _context.next = 335;
              return regeneratorRuntime.awrap(StatusSkill.deleteMany({}));

            case 335:
              _context.next = 337;
              return regeneratorRuntime.awrap(CatGrp.deleteMany({}));

            case 337:
              _context.next = 339;
              return regeneratorRuntime.awrap(populate.popolaTabelleNuove());

            case 339:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 342:
              if (!(mydata.dbop === "ricreaTabCitiesProvinces")) {
                _context.next = 354;
                break;
              }

              // Svuota e Ricrea
              _require30 = require("../models/city"), _City = _require30.City;
              _require31 = require("../models/province"), _Province = _require31.Province;
              _context.next = 347;
              return regeneratorRuntime.awrap(_City.deleteMany({}));

            case 347:
              _context.next = 349;
              return regeneratorRuntime.awrap(_Province.deleteMany({}));

            case 349:
              _context.next = 351;
              return regeneratorRuntime.awrap(populate.popolaTabelleNuove());

            case 351:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 354:
              if (!(mydata.dbop === "PopulateTables")) {
                _context.next = 358;
                break;
              }

              ris = populate.popolaTabelleNuove();
              _context.next = 682;
              break;

            case 358:
              if (!(mydata.dbop === "dropProducts")) {
                _context.next = 371;
                break;
              }

              if (!idapp) {
                _context.next = 368;
                break;
              }

              _context.next = 362;
              return regeneratorRuntime.awrap(Product.deleteMany({
                idapp: idapp
              }));

            case 362:
              deleteProducts = _context.sent;
              console.log("Cancellati ".concat(deleteProducts.deletedCount, " record dalla collezione Product.")); // Cancellazione dei record nella collezione ProductInfo

              _context.next = 366;
              return regeneratorRuntime.awrap(ProductInfo.deleteMany({
                idapp: idapp
              }));

            case 366:
              _deleteProductInfo = _context.sent;
              console.log("Cancellati ".concat(_deleteProductInfo.deletedCount, " record dalla collezione ProductInfo."));

            case 368:
              ris = deleteProductInfo ? true : false;
              _context.next = 682;
              break;

            case 371:
              if (!(mydata.dbop === "dropCatProd")) {
                _context.next = 377;
                break;
              }

              _context.next = 374;
              return regeneratorRuntime.awrap(CatProd.deleteMany({
                idapp: idapp
              }));

            case 374:
              deleteCatProd = _context.sent;
              _context.next = 682;
              break;

            case 377:
              if (!(mydata.dbop === "dropSubCatProd")) {
                _context.next = 383;
                break;
              }

              _context.next = 380;
              return regeneratorRuntime.awrap(SubCatProd.deleteMany({
                idapp: idapp
              }));

            case 380:
              deleteSubCatProd = _context.sent;
              _context.next = 682;
              break;

            case 383:
              if (!(mydata.dbop === "dropAllOrders")) {
                _context.next = 402;
                break;
              }

              _context.prev = 384;
              _context.next = 387;
              return regeneratorRuntime.awrap(Order.deleteMany({
                idapp: idapp
              }));

            case 387:
              deleteOrder = _context.sent;
              _context.next = 390;
              return regeneratorRuntime.awrap(OrdersCart.deleteMany({
                idapp: idapp
              }));

            case 390:
              deleteOrdersCart = _context.sent;
              _context.next = 393;
              return regeneratorRuntime.awrap(Cart.deleteMany({
                idapp: idapp
              }));

            case 393:
              deleteCart = _context.sent;
              ris = deleteCart;
              _context.next = 400;
              break;

            case 397:
              _context.prev = 397;
              _context.t1 = _context["catch"](384);
              console.error("Err:", _context.t1);

            case 400:
              _context.next = 682;
              break;

            case 402:
              if (!(mydata.dbop === "SistemaGasOrdine")) {
                _context.next = 439;
                break;
              }

              _context.next = 405;
              return regeneratorRuntime.awrap(Product.find({}).lean());

            case 405:
              arrrec = _context.sent;
              _iteratorNormalCompletion = true;
              _didIteratorError = false;
              _iteratorError = undefined;
              _context.prev = 409;
              _iterator = arrrec[Symbol.iterator]();

            case 411:
              if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
                _context.next = 423;
                break;
              }

              rec = _step.value;

              if (!(tools.isArray(rec.idGasordines) && rec.idGasordines.length > 0)) {
                _context.next = 418;
                break;
              }

              _context.next = 416;
              return regeneratorRuntime.awrap(Product.findByIdAndUpdate(rec._id, {
                $set: {
                  idGasordine: rec.idGasordines[0]
                }
              }));

            case 416:
              _context.next = 420;
              break;

            case 418:
              _context.next = 420;
              return regeneratorRuntime.awrap(Product.findByIdAndUpdate(rec._id, {
                $set: {
                  idGasordine: null
                }
              }));

            case 420:
              _iteratorNormalCompletion = true;
              _context.next = 411;
              break;

            case 423:
              _context.next = 429;
              break;

            case 425:
              _context.prev = 425;
              _context.t2 = _context["catch"](409);
              _didIteratorError = true;
              _iteratorError = _context.t2;

            case 429:
              _context.prev = 429;
              _context.prev = 430;

              if (!_iteratorNormalCompletion && _iterator["return"] != null) {
                _iterator["return"]();
              }

            case 432:
              _context.prev = 432;

              if (!_didIteratorError) {
                _context.next = 435;
                break;
              }

              throw _iteratorError;

            case 435:
              return _context.finish(432);

            case 436:
              return _context.finish(429);

            case 437:
              _context.next = 682;
              break;

            case 439:
              if (!(mydata.dbop === "CopyPriceToCalc")) {
                _context.next = 506;
                break;
              }

              _context.prev = 440;
              _context.next = 443;
              return regeneratorRuntime.awrap(OrdersCart.find({}).lean());

            case 443:
              _arrrec = _context.sent;
              _iteratorNormalCompletion2 = true;
              _didIteratorError2 = false;
              _iteratorError2 = undefined;
              _context.prev = 447;
              _iterator2 = _arrrec[Symbol.iterator]();

            case 449:
              if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
                _context.next = 456;
                break;
              }

              _rec = _step2.value;
              _context.next = 453;
              return regeneratorRuntime.awrap(OrdersCart.findByIdAndUpdate(_rec._id, {
                $set: {
                  totalPriceCalc: _rec.totalPrice
                }
              }));

            case 453:
              _iteratorNormalCompletion2 = true;
              _context.next = 449;
              break;

            case 456:
              _context.next = 462;
              break;

            case 458:
              _context.prev = 458;
              _context.t3 = _context["catch"](447);
              _didIteratorError2 = true;
              _iteratorError2 = _context.t3;

            case 462:
              _context.prev = 462;
              _context.prev = 463;

              if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
                _iterator2["return"]();
              }

            case 465:
              _context.prev = 465;

              if (!_didIteratorError2) {
                _context.next = 468;
                break;
              }

              throw _iteratorError2;

            case 468:
              return _context.finish(465);

            case 469:
              return _context.finish(462);

            case 470:
              _context.next = 472;
              return regeneratorRuntime.awrap(Order.find({}).lean());

            case 472:
              arrrec2 = _context.sent;
              _iteratorNormalCompletion3 = true;
              _didIteratorError3 = false;
              _iteratorError3 = undefined;
              _context.prev = 476;
              _iterator3 = arrrec2[Symbol.iterator]();

            case 478:
              if (_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done) {
                _context.next = 485;
                break;
              }

              _rec2 = _step3.value;
              _context.next = 482;
              return regeneratorRuntime.awrap(Order.findByIdAndUpdate(_rec2._id, {
                $set: {
                  TotalPriceProductCalc: _rec2.TotalPriceProduct
                }
              }));

            case 482:
              _iteratorNormalCompletion3 = true;
              _context.next = 478;
              break;

            case 485:
              _context.next = 491;
              break;

            case 487:
              _context.prev = 487;
              _context.t4 = _context["catch"](476);
              _didIteratorError3 = true;
              _iteratorError3 = _context.t4;

            case 491:
              _context.prev = 491;
              _context.prev = 492;

              if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
                _iterator3["return"]();
              }

            case 494:
              _context.prev = 494;

              if (!_didIteratorError3) {
                _context.next = 497;
                break;
              }

              throw _iteratorError3;

            case 497:
              return _context.finish(494);

            case 498:
              return _context.finish(491);

            case 499:
              _context.next = 504;
              break;

            case 501:
              _context.prev = 501;
              _context.t5 = _context["catch"](440);
              console.error("Err:", _context.t5);

            case 504:
              _context.next = 682;
              break;

            case 506:
              if (!(mydata.dbop === "dropAllCarts")) {
                _context.next = 512;
                break;
              }

              _context.next = 509;
              return regeneratorRuntime.awrap(Cart.deleteMany({
                idapp: idapp
              }));

            case 509:
              ris = _context.sent;
              _context.next = 682;
              break;

            case 512:
              if (!(mydata.dbop === "RewriteCitiesTable")) {
                _context.next = 516;
                break;
              }

              ris = populate.rewriteTable("cities");
              _context.next = 682;
              break;

            case 516:
              if (!(mydata.dbop === "RewriteLevelsTable")) {
                _context.next = 520;
                break;
              }

              ris = populate.rewriteTable("levels");
              _context.next = 682;
              break;

            case 520:
              if (!(mydata.dbop === "RewriteProvincesTable")) {
                _context.next = 524;
                break;
              }

              ris = populate.rewriteTable("provinces");
              _context.next = 682;
              break;

            case 524:
              if (!(mydata.dbop === "emptyCityProvinces")) {
                _context.next = 533;
                break;
              }

              _require32 = require("../models/city"), _City2 = _require32.City;
              _require33 = require("../models/province"), _Province2 = _require33.Province;
              _context.next = 529;
              return regeneratorRuntime.awrap(_City2.deleteMany({}));

            case 529:
              _context.next = 531;
              return regeneratorRuntime.awrap(_Province2.deleteMany({}));

            case 531:
              _context.next = 682;
              break;

            case 533:
              if (!(mydata.dbop === "ConvTablesFromIntToString")) {
                _context.next = 552;
                break;
              }

              _require34 = require("../models/myskill"), MySkill = _require34.MySkill;
              _require35 = require("../models/mybacheca"), MyBacheca = _require35.MyBacheca;
              _require36 = require("../models/myhosp"), _MyHosp = _require36.MyHosp;
              _require37 = require("../models/mygood"), MyGood = _require37.MyGood; // const { MyGroup } = require('../models/mygroup');

              console.log("INIZIO - Conversioni"); // 'myskills',
              // 'mybachecas',
              // 'myhosps',
              // 'mygoods',
              // 'mygroups'

              _context.next = 541;
              return regeneratorRuntime.awrap(ConvertiDaIntAStr(MySkill));

            case 541:
              _context.next = 543;
              return regeneratorRuntime.awrap(ConvertiDaIntAStr(MyBacheca));

            case 543:
              _context.next = 545;
              return regeneratorRuntime.awrap(ConvertiDaIntAStr(_MyHosp));

            case 545:
              _context.next = 547;
              return regeneratorRuntime.awrap(ConvertiDaIntAStr(MyGood));

            case 547:
              _context.next = 549;
              return regeneratorRuntime.awrap(ConvertiDaIntAStr(MyGroup));

            case 549:
              console.log("FINE - Conversioni");
              _context.next = 682;
              break;

            case 552:
              if (!(mydata.dbop === "Removeinteger")) {
                _context.next = 571;
                break;
              }

              _require38 = require("../models/myskill"), _MySkill = _require38.MySkill;
              _require39 = require("../models/mybacheca"), _MyBacheca = _require39.MyBacheca;
              _require40 = require("../models/myhosp"), _MyHosp2 = _require40.MyHosp;
              _require41 = require("../models/mygood"), _MyGood = _require41.MyGood; // const { MyGroup } = require('../models/mygroup');

              console.log("INIZIO - Rimozione");
              _context.next = 560;
              return regeneratorRuntime.awrap(RimuoviInteri(_MySkill));

            case 560:
              _context.next = 562;
              return regeneratorRuntime.awrap(RimuoviInteri(_MyBacheca));

            case 562:
              _context.next = 564;
              return regeneratorRuntime.awrap(RimuoviInteri(_MyHosp2));

            case 564:
              _context.next = 566;
              return regeneratorRuntime.awrap(RimuoviInteri(_MyGood));

            case 566:
              _context.next = 568;
              return regeneratorRuntime.awrap(RimuoviInteri(MyGroup));

            case 568:
              console.log("FINE - Rimozione");
              _context.next = 682;
              break;

            case 571:
              if (!(mydata.dbop === "createAllCircuits")) {
                _context.next = 604;
                break;
              }

              _require42 = require("../models/province"), _Province3 = _require42.Province;
              _context.next = 575;
              return regeneratorRuntime.awrap(_Province3.find({}));

            case 575:
              arrProv = _context.sent;
              _iteratorNormalCompletion4 = true;
              _didIteratorError4 = false;
              _iteratorError4 = undefined;
              _context.prev = 579;
              _iterator4 = arrProv[Symbol.iterator]();

            case 581:
              if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) {
                _context.next = 588;
                break;
              }

              recprov = _step4.value;
              _context.next = 585;
              return regeneratorRuntime.awrap(Circuit.createCircuitIfNotExist(req, idapp, recprov.prov));

            case 585:
              _iteratorNormalCompletion4 = true;
              _context.next = 581;
              break;

            case 588:
              _context.next = 594;
              break;

            case 590:
              _context.prev = 590;
              _context.t6 = _context["catch"](579);
              _didIteratorError4 = true;
              _iteratorError4 = _context.t6;

            case 594:
              _context.prev = 594;
              _context.prev = 595;

              if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
                _iterator4["return"]();
              }

            case 597:
              _context.prev = 597;

              if (!_didIteratorError4) {
                _context.next = 600;
                break;
              }

              throw _iteratorError4;

            case 600:
              return _context.finish(597);

            case 601:
              return _context.finish(594);

            case 602:
              _context.next = 682;
              break;

            case 604:
              if (!(mydata.dbop === "correggiProductTypes")) {
                _context.next = 609;
                break;
              }

              _context.next = 607;
              return regeneratorRuntime.awrap(ProductInfo.correggiProductTypes());

            case 607:
              _context.next = 682;
              break;

            case 609:
              if (!(mydata.dbop === "replaceProductImgToImageFile")) {
                _context.next = 614;
                break;
              }

              _context.next = 612;
              return regeneratorRuntime.awrap(ProductInfo.replaceProductImgToImageFile(true));

            case 612:
              _context.next = 682;
              break;

            case 614:
              if (!(mydata.dbop === "removeUploadProducts_Path")) {
                _context.next = 619;
                break;
              }

              _context.next = 617;
              return regeneratorRuntime.awrap(ProductInfo.replaceProductImgToImageFile(false));

            case 617:
              _context.next = 682;
              break;

            case 619:
              if (!(mydata.dbop === "correggiCircuitiANull")) {
                _context.next = 624;
                break;
              }

              _context.next = 622;
              return regeneratorRuntime.awrap(User.updateMany({}, {
                $pull: {
                  "profile.mycircuits": {
                    circuitname: null
                  }
                }
              }));

            case 622:
              _context.next = 682;
              break;

            case 624:
              if (!(mydata.dbop === "ImpostaMinMaxPersonali")) {
                _context.next = 629;
                break;
              }

              _context.next = 627;
              return regeneratorRuntime.awrap(Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax, ""));

            case 627:
              _context.next = 682;
              break;

            case 629:
              if (!(mydata.dbop === "ImpostaMinMaxPersonaliCircuito")) {
                _context.next = 634;
                break;
              }

              _context.next = 632;
              return regeneratorRuntime.awrap(Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax, mydata.circuitId));

            case 632:
              _context.next = 682;
              break;

            case 634:
              if (!(mydata.dbop === "ImpostaMinMaxComunitari")) {
                _context.next = 639;
                break;
              }

              _context.next = 637;
              return regeneratorRuntime.awrap(Account.SetMinMaxComunitari(idapp, mydata.valmin, mydata.valmax));

            case 637:
              _context.next = 682;
              break;

            case 639:
              if (!(mydata.dbop === "ImpostaMinMaxCollettivi")) {
                _context.next = 644;
                break;
              }

              _context.next = 642;
              return regeneratorRuntime.awrap(Account.SetMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax));

            case 642:
              _context.next = 682;
              break;

            case 644:
              if (!(mydata.dbop === "ImpostaDefMinMaxPersonali")) {
                _context.next = 649;
                break;
              }

              _context.next = 647;
              return regeneratorRuntime.awrap(Circuit.SetDefMinMaxPersonali(idapp, mydata.valmin, mydata.valmax, mydata.circuitId));

            case 647:
              _context.next = 682;
              break;

            case 649:
              if (!(mydata.dbop === "ImpostaDefMinMaxCollettivi")) {
                _context.next = 654;
                break;
              }

              _context.next = 652;
              return regeneratorRuntime.awrap(Circuit.SetDefMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax, mydata.circuitId));

            case 652:
              _context.next = 682;
              break;

            case 654:
              if (!(mydata.dbop === "AbilitaTuttiCircuiti")) {
                _context.next = 659;
                break;
              }

              _context.next = 657;
              return regeneratorRuntime.awrap(Circuit.AbilitaTuttiCircuiti(idapp));

            case 657:
              _context.next = 682;
              break;

            case 659:
              if (!(mydata.dbop === "AzzeraRegolamentiTuttiCircuiti")) {
                _context.next = 664;
                break;
              }

              _context.next = 662;
              return regeneratorRuntime.awrap(Circuit.AzzeraRegolamentiTuttiCircuiti(idapp));

            case 662:
              _context.next = 682;
              break;

            case 664:
              if (!(mydata.dbop === "setstrProvByIdCityCircuits")) {
                _context.next = 669;
                break;
              }

              _context.next = 667;
              return regeneratorRuntime.awrap(Circuit.setstrProvByIdCityCircuits(idapp));

            case 667:
              _context.next = 682;
              break;

            case 669:
              if (!(mydata.dbop === "updateSaldoAndTransato_AllAccounts")) {
                _context.next = 674;
                break;
              }

              _context.next = 672;
              return regeneratorRuntime.awrap(Account.updateSaldoAndTransato_AllAccounts(idapp));

            case 672:
              _context.next = 682;
              break;

            case 674:
              if (!(mydata.dbop === "generateBotMenuRecords")) {
                _context.next = 679;
                break;
              }

              _context.next = 677;
              return regeneratorRuntime.awrap(MyBot.generateBotMenuRecords(idapp));

            case 677:
              _context.next = 682;
              break;

            case 679:
              if (!(mydata.dbop === "GenerateVapiKey")) {
                _context.next = 682;
                break;
              }

              _context.next = 682;
              return regeneratorRuntime.awrap(tools.generateVapiKey());

            case 682:
              return _context.abrupt("return", ris);

            case 685:
              _context.prev = 685;
              _context.t7 = _context["catch"](8);
              console.log(_context.t7.message);

            case 688:
            case "end":
              return _context.stop();
          }
        }
      }, null, null, [[8, 685], [160, 175], [384, 397], [409, 425, 429, 437], [430,, 432, 436], [440, 501], [447, 458, 462, 470], [463,, 465, 469], [476, 487, 491, 499], [492,, 494, 498], [579, 590, 594, 602], [595,, 597, 601]]);
    }
  }]);

  return CronMod;
}();

module.exports = CronMod;