dcb6948299c4437c9293023254d1d6cd4a77f1e7
[motion2.git] / server / api / migration / migration.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x5393=['../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','apply','reject','update','then','Migration','rawAttributes','fieldName','type','name','query','keys','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','map','VIRTUAL','options','includeAll','include','catch','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment'];(function(_0x52ece1,_0x425dc5){var _0x329205=function(_0xf76c47){while(--_0xf76c47){_0x52ece1['push'](_0x52ece1['shift']());}};_0x329205(++_0x425dc5);}(_0x5393,0x1ea));var _0x3539=function(_0x545800,_0x92f75){_0x545800=_0x545800-0x0;var _0x2e1b8b=_0x5393[_0x545800];return _0x2e1b8b;};'use strict';var emlformat=require(_0x3539('0x0'));var rimraf=require(_0x3539('0x1'));var zipdir=require(_0x3539('0x2'));var jsonpatch=require(_0x3539('0x3'));var rp=require(_0x3539('0x4'));var moment=require(_0x3539('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x3539('0x6'));var util=require(_0x3539('0x7'));var path=require(_0x3539('0x8'));var sox=require(_0x3539('0x9'));var csv=require(_0x3539('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3539('0xb'));var _=require(_0x3539('0xc'));var squel=require(_0x3539('0xd'));var crypto=require(_0x3539('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x3539('0xf'));var toCsv=require(_0x3539('0xa'));var querystring=require('querystring');var Papa=require(_0x3539('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x3539('0x11'));var as=require(_0x3539('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3539('0x13'));var utils=require(_0x3539('0x14'));var config=require(_0x3539('0x15'));var licenseUtil=require(_0x3539('0x16'));var db=require(_0x3539('0x17'))['db'];function respondWithStatusCode(_0x371bb1,_0x51eac7){_0x51eac7=_0x51eac7||0xcc;return function(_0x291702){if(_0x291702){return _0x371bb1[_0x3539('0x18')](_0x51eac7);}return _0x371bb1[_0x3539('0x19')](_0x51eac7)[_0x3539('0x1a')]();};}function respondWithResult(_0x55369e,_0x529a6c){_0x529a6c=_0x529a6c||0xc8;return function(_0x114819){if(_0x114819){return _0x55369e[_0x3539('0x19')](_0x529a6c)[_0x3539('0x1b')](_0x114819);}};}function respondWithFilteredResult(_0xed207c,_0x3079bd){return function(_0x1f7f25){if(_0x1f7f25){var _0x13dbe0=typeof _0x3079bd[_0x3539('0x1c')]==='undefined'&&typeof _0x3079bd[_0x3539('0x1d')]===_0x3539('0x1e');var _0x29078f=_0x1f7f25[_0x3539('0x1f')];var _0x2f96e9=_0x13dbe0?0x0:_0x3079bd['offset'];var _0x5c38ba=_0x13dbe0?_0x1f7f25[_0x3539('0x1f')]:_0x3079bd['offset']+_0x3079bd[_0x3539('0x1d')];var _0x4c4cf2;if(_0x5c38ba>=_0x29078f){_0x5c38ba=_0x29078f;_0x4c4cf2=0xc8;}else{_0x4c4cf2=0xce;}_0xed207c[_0x3539('0x19')](_0x4c4cf2);return _0xed207c[_0x3539('0x20')]('Content-Range',_0x2f96e9+'-'+_0x5c38ba+'/'+_0x29078f)[_0x3539('0x1b')](_0x1f7f25);}return null;};}function patchUpdates(_0x24f3f8){return function(_0x314d90){try{jsonpatch[_0x3539('0x21')](_0x314d90,_0x24f3f8,!![]);}catch(_0x5e5e7d){return BPromise[_0x3539('0x22')](_0x5e5e7d);}return _0x314d90['save']();};}function saveUpdates(_0x480d5b,_0x29ba56){return function(_0x1b33c2){if(_0x1b33c2){return _0x1b33c2[_0x3539('0x23')](_0x480d5b)[_0x3539('0x24')](function(_0x429fd3){return _0x429fd3;});}return null;};}function removeEntity(_0x4caa15,_0x2d5df6){return function(_0x3f65cd){if(_0x3f65cd){return _0x3f65cd['destroy']()[_0x3539('0x24')](function(){_0x4caa15[_0x3539('0x19')](0xcc)[_0x3539('0x1a')]();});}};}function handleEntityNotFound(_0x412645,_0x448ded){return function(_0x51d822){if(!_0x51d822){_0x412645[_0x3539('0x18')](0x194);}return _0x51d822;};}function handleError(_0x1f3f8b,_0x104635){_0x104635=_0x104635||0x1f4;return function(_0x298096){logger['error'](_0x298096['stack']);if(_0x298096['name']){delete _0x298096['name'];}_0x1f3f8b[_0x3539('0x19')](_0x104635)['send'](_0x298096);};}exports['index']=function(_0x278c45,_0x4ba593){var _0x563ed0={},_0x95e915={},_0x3ebd50={'count':0x0,'rows':[]};var _0x3b22e5=_['map'](db[_0x3539('0x25')][_0x3539('0x26')],function(_0x5a8497){return{'name':_0x5a8497[_0x3539('0x27')],'type':_0x5a8497[_0x3539('0x28')]['key']};});_0x95e915['model']=_['map'](_0x3b22e5,_0x3539('0x29'));_0x95e915[_0x3539('0x2a')]=_[_0x3539('0x2b')](_0x278c45[_0x3539('0x2a')]);_0x95e915[_0x3539('0x2c')]=_[_0x3539('0x2d')](_0x95e915['model'],_0x95e915[_0x3539('0x2a')]);_0x563ed0['attributes']=_[_0x3539('0x2d')](_0x95e915[_0x3539('0x2e')],qs[_0x3539('0x2f')](_0x278c45[_0x3539('0x2a')][_0x3539('0x2f')]));_0x563ed0[_0x3539('0x30')]=_0x563ed0[_0x3539('0x30')][_0x3539('0x31')]?_0x563ed0['attributes']:_0x95e915[_0x3539('0x2e')];if(!_0x278c45[_0x3539('0x2a')][_0x3539('0x32')](_0x3539('0x33'))){_0x563ed0[_0x3539('0x1d')]=qs[_0x3539('0x1d')](_0x278c45[_0x3539('0x2a')]['limit']);_0x563ed0[_0x3539('0x1c')]=qs[_0x3539('0x1c')](_0x278c45[_0x3539('0x2a')][_0x3539('0x1c')]);}_0x563ed0[_0x3539('0x34')]=qs[_0x3539('0x35')](_0x278c45['query'][_0x3539('0x35')]);_0x563ed0[_0x3539('0x36')]=qs[_0x3539('0x2c')](_[_0x3539('0x37')](_0x278c45[_0x3539('0x2a')],_0x95e915[_0x3539('0x2c')]),_0x3b22e5);if(_0x278c45['query'][_0x3539('0x38')]){_0x563ed0[_0x3539('0x36')]=_[_0x3539('0x39')](_0x563ed0[_0x3539('0x36')],{'$or':_[_0x3539('0x3a')](_0x3b22e5,function(_0x3cbd55){if(_0x3cbd55[_0x3539('0x28')]!==_0x3539('0x3b')){var _0x13c862={};_0x13c862[_0x3cbd55[_0x3539('0x29')]]={'$like':'%'+_0x278c45[_0x3539('0x2a')]['filter']+'%'};return _0x13c862;}})});}_0x563ed0=_[_0x3539('0x39')]({},_0x563ed0,_0x278c45[_0x3539('0x3c')]);var _0x179134={'where':_0x563ed0[_0x3539('0x36')]};return db[_0x3539('0x25')][_0x3539('0x1f')](_0x179134)['then'](function(_0x45932c){_0x3ebd50[_0x3539('0x1f')]=_0x45932c;if(_0x278c45[_0x3539('0x2a')][_0x3539('0x3d')]){_0x563ed0[_0x3539('0x3e')]=[{'all':!![]}];}return db[_0x3539('0x25')]['findAll'](_0x563ed0);})[_0x3539('0x24')](function(_0x55d262){_0x3ebd50['rows']=_0x55d262;return _0x3ebd50;})[_0x3539('0x24')](respondWithFilteredResult(_0x4ba593,_0x563ed0))[_0x3539('0x3f')](handleError(_0x4ba593,null));};