b45c439c72fd559ce6807f48d1949f4a3f5db878
[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 _0xb543=['limit','count','set','Content-Range','reject','save','update','then','destroy','stack','name','send','index','map','Migration','rawAttributes','fieldName','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','order','sort','filter','where','merge','VIRTUAL','options','includeAll','rows','catch','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined'];(function(_0xdcd688,_0x46dfae){var _0x37731c=function(_0x46970d){while(--_0x46970d){_0xdcd688['push'](_0xdcd688['shift']());}};_0x37731c(++_0x46dfae);}(_0xb543,0x17e));var _0x3b54=function(_0x3bb3d5,_0x1057c1){_0x3bb3d5=_0x3bb3d5-0x0;var _0x581265=_0xb543[_0x3bb3d5];return _0x581265;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3b54('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x3b54('0x1'));var rp=require(_0x3b54('0x2'));var moment=require(_0x3b54('0x3'));var BPromise=require(_0x3b54('0x4'));var Mustache=require(_0x3b54('0x5'));var util=require(_0x3b54('0x6'));var path=require(_0x3b54('0x7'));var sox=require(_0x3b54('0x8'));var csv=require(_0x3b54('0x9'));var ejs=require(_0x3b54('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x3b54('0xb'));var squel=require(_0x3b54('0xc'));var crypto=require(_0x3b54('0xd'));var jsforce=require(_0x3b54('0xe'));var deskjs=require(_0x3b54('0xf'));var toCsv=require(_0x3b54('0x9'));var querystring=require(_0x3b54('0x10'));var Papa=require(_0x3b54('0x11'));var Redis=require('ioredis');var authService=require(_0x3b54('0x12'));var qs=require(_0x3b54('0x13'));var as=require(_0x3b54('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3b54('0x15'));var utils=require(_0x3b54('0x16'));var config=require(_0x3b54('0x17'));var licenseUtil=require(_0x3b54('0x18'));var db=require(_0x3b54('0x19'))['db'];function respondWithStatusCode(_0xe33683,_0x2c50cc){_0x2c50cc=_0x2c50cc||0xcc;return function(_0x292067){if(_0x292067){return _0xe33683[_0x3b54('0x1a')](_0x2c50cc);}return _0xe33683[_0x3b54('0x1b')](_0x2c50cc)[_0x3b54('0x1c')]();};}function respondWithResult(_0x2c1628,_0x42abc5){_0x42abc5=_0x42abc5||0xc8;return function(_0x226dcd){if(_0x226dcd){return _0x2c1628['status'](_0x42abc5)[_0x3b54('0x1d')](_0x226dcd);}};}function respondWithFilteredResult(_0x1fee8b,_0x35a8e0){return function(_0x3ed7f6){if(_0x3ed7f6){var _0x534425=typeof _0x35a8e0[_0x3b54('0x1e')]===_0x3b54('0x1f')&&typeof _0x35a8e0[_0x3b54('0x20')]==='undefined';var _0x8ad978=_0x3ed7f6[_0x3b54('0x21')];var _0x210189=_0x534425?0x0:_0x35a8e0[_0x3b54('0x1e')];var _0x6d8bf2=_0x534425?_0x3ed7f6[_0x3b54('0x21')]:_0x35a8e0[_0x3b54('0x1e')]+_0x35a8e0[_0x3b54('0x20')];var _0x5131eb;if(_0x6d8bf2>=_0x8ad978){_0x6d8bf2=_0x8ad978;_0x5131eb=0xc8;}else{_0x5131eb=0xce;}_0x1fee8b[_0x3b54('0x1b')](_0x5131eb);return _0x1fee8b[_0x3b54('0x22')](_0x3b54('0x23'),_0x210189+'-'+_0x6d8bf2+'/'+_0x8ad978)[_0x3b54('0x1d')](_0x3ed7f6);}return null;};}function patchUpdates(_0x25da27){return function(_0x2ba910){try{jsonpatch['apply'](_0x2ba910,_0x25da27,!![]);}catch(_0x2833d7){return BPromise[_0x3b54('0x24')](_0x2833d7);}return _0x2ba910[_0x3b54('0x25')]();};}function saveUpdates(_0x2aa931,_0x48c5d6){return function(_0x15f595){if(_0x15f595){return _0x15f595[_0x3b54('0x26')](_0x2aa931)[_0x3b54('0x27')](function(_0x1ef3a7){return _0x1ef3a7;});}return null;};}function removeEntity(_0x3bcfe5,_0x454803){return function(_0x747f60){if(_0x747f60){return _0x747f60[_0x3b54('0x28')]()[_0x3b54('0x27')](function(){_0x3bcfe5['status'](0xcc)[_0x3b54('0x1c')]();});}};}function handleEntityNotFound(_0x443d4a,_0x5e73dd){return function(_0x528f39){if(!_0x528f39){_0x443d4a[_0x3b54('0x1a')](0x194);}return _0x528f39;};}function handleError(_0x34460c,_0x4583d3){_0x4583d3=_0x4583d3||0x1f4;return function(_0x33594d){logger['error'](_0x33594d[_0x3b54('0x29')]);if(_0x33594d[_0x3b54('0x2a')]){delete _0x33594d[_0x3b54('0x2a')];}_0x34460c[_0x3b54('0x1b')](_0x4583d3)[_0x3b54('0x2b')](_0x33594d);};}exports[_0x3b54('0x2c')]=function(_0x3fa287,_0x3e4e1e){var _0x201849={},_0x47d1eb={},_0xf52c35={'count':0x0,'rows':[]};var _0x94526f=_[_0x3b54('0x2d')](db[_0x3b54('0x2e')][_0x3b54('0x2f')],function(_0x192592){return{'name':_0x192592[_0x3b54('0x30')],'type':_0x192592['type'][_0x3b54('0x31')]};});_0x47d1eb[_0x3b54('0x32')]=_['map'](_0x94526f,_0x3b54('0x2a'));_0x47d1eb[_0x3b54('0x33')]=_[_0x3b54('0x34')](_0x3fa287[_0x3b54('0x33')]);_0x47d1eb[_0x3b54('0x35')]=_['intersection'](_0x47d1eb[_0x3b54('0x32')],_0x47d1eb[_0x3b54('0x33')]);_0x201849[_0x3b54('0x36')]=_[_0x3b54('0x37')](_0x47d1eb[_0x3b54('0x32')],qs[_0x3b54('0x38')](_0x3fa287[_0x3b54('0x33')][_0x3b54('0x38')]));_0x201849[_0x3b54('0x36')]=_0x201849['attributes'][_0x3b54('0x39')]?_0x201849[_0x3b54('0x36')]:_0x47d1eb[_0x3b54('0x32')];if(!_0x3fa287[_0x3b54('0x33')][_0x3b54('0x3a')]('nolimit')){_0x201849[_0x3b54('0x20')]=qs[_0x3b54('0x20')](_0x3fa287['query'][_0x3b54('0x20')]);_0x201849['offset']=qs[_0x3b54('0x1e')](_0x3fa287[_0x3b54('0x33')][_0x3b54('0x1e')]);}_0x201849[_0x3b54('0x3b')]=qs[_0x3b54('0x3c')](_0x3fa287['query'][_0x3b54('0x3c')]);_0x201849['where']=qs[_0x3b54('0x35')](_['pick'](_0x3fa287[_0x3b54('0x33')],_0x47d1eb['filters']),_0x94526f);if(_0x3fa287[_0x3b54('0x33')][_0x3b54('0x3d')]){_0x201849[_0x3b54('0x3e')]=_[_0x3b54('0x3f')](_0x201849['where'],{'$or':_[_0x3b54('0x2d')](_0x94526f,function(_0x4c7262){if(_0x4c7262['type']!==_0x3b54('0x40')){var _0x381513={};_0x381513[_0x4c7262[_0x3b54('0x2a')]]={'$like':'%'+_0x3fa287[_0x3b54('0x33')][_0x3b54('0x3d')]+'%'};return _0x381513;}})});}_0x201849=_[_0x3b54('0x3f')]({},_0x201849,_0x3fa287[_0x3b54('0x41')]);var _0x18b246={'where':_0x201849[_0x3b54('0x3e')]};return db['Migration'][_0x3b54('0x21')](_0x18b246)['then'](function(_0x56751d){_0xf52c35[_0x3b54('0x21')]=_0x56751d;if(_0x3fa287[_0x3b54('0x33')][_0x3b54('0x42')]){_0x201849['include']=[{'all':!![]}];}return db[_0x3b54('0x2e')]['findAll'](_0x201849);})[_0x3b54('0x27')](function(_0x53f0d4){_0xf52c35[_0x3b54('0x43')]=_0x53f0d4;return _0xf52c35;})['then'](respondWithFilteredResult(_0x3e4e1e,_0x201849))[_0x3b54('0x44')](handleError(_0x3e4e1e,null));};