Built motion from commit bab6f49e.|2.6.17
[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 _0x85f6=['query','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','include','findAll','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','status','json','offset','undefined','count','set','Content-Range','apply','save','update','then','destroy','sendStatus','error','stack','name','send','index','Migration','fieldName','type','model','map','keys'];(function(_0x413feb,_0x10477f){var _0x40ee88=function(_0x32a3f6){while(--_0x32a3f6){_0x413feb['push'](_0x413feb['shift']());}};_0x40ee88(++_0x10477f);}(_0x85f6,0xdf));var _0x685f=function(_0x5397c6,_0x9c8dc6){_0x5397c6=_0x5397c6-0x0;var _0x1c6425=_0x85f6[_0x5397c6];return _0x1c6425;};'use strict';var emlformat=require(_0x685f('0x0'));var rimraf=require(_0x685f('0x1'));var zipdir=require(_0x685f('0x2'));var jsonpatch=require(_0x685f('0x3'));var rp=require(_0x685f('0x4'));var moment=require(_0x685f('0x5'));var BPromise=require(_0x685f('0x6'));var Mustache=require(_0x685f('0x7'));var util=require('util');var path=require('path');var sox=require(_0x685f('0x8'));var csv=require('to-csv');var ejs=require(_0x685f('0x9'));var fs=require('fs');var fs_extra=require(_0x685f('0xa'));var _=require(_0x685f('0xb'));var squel=require(_0x685f('0xc'));var crypto=require(_0x685f('0xd'));var jsforce=require(_0x685f('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x685f('0xf'));var querystring=require(_0x685f('0x10'));var Papa=require(_0x685f('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x685f('0x12'));var as=require(_0x685f('0x13'));var hardwareService=require(_0x685f('0x14'));var logger=require(_0x685f('0x15'))(_0x685f('0x16'));var utils=require('../../config/utils');var config=require(_0x685f('0x17'));var licenseUtil=require(_0x685f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2e567d,_0x348b4d){_0x348b4d=_0x348b4d||0xcc;return function(_0x47b47a){if(_0x47b47a){return _0x2e567d['sendStatus'](_0x348b4d);}return _0x2e567d[_0x685f('0x19')](_0x348b4d)['end']();};}function respondWithResult(_0xad155a,_0x3853d5){_0x3853d5=_0x3853d5||0xc8;return function(_0x2510d9){if(_0x2510d9){return _0xad155a[_0x685f('0x19')](_0x3853d5)[_0x685f('0x1a')](_0x2510d9);}};}function respondWithFilteredResult(_0x5a8a02,_0x54427d){return function(_0x39e0f4){if(_0x39e0f4){var _0x72f849=typeof _0x54427d[_0x685f('0x1b')]===_0x685f('0x1c')&&typeof _0x54427d['limit']===_0x685f('0x1c');var _0x5ce288=_0x39e0f4['count'];var _0x46122e=_0x72f849?0x0:_0x54427d[_0x685f('0x1b')];var _0x5d5046=_0x72f849?_0x39e0f4[_0x685f('0x1d')]:_0x54427d['offset']+_0x54427d['limit'];var _0x4140f9;if(_0x5d5046>=_0x5ce288){_0x5d5046=_0x5ce288;_0x4140f9=0xc8;}else{_0x4140f9=0xce;}_0x5a8a02[_0x685f('0x19')](_0x4140f9);return _0x5a8a02[_0x685f('0x1e')](_0x685f('0x1f'),_0x46122e+'-'+_0x5d5046+'/'+_0x5ce288)[_0x685f('0x1a')](_0x39e0f4);}return null;};}function patchUpdates(_0x4d0ff0){return function(_0x374651){try{jsonpatch[_0x685f('0x20')](_0x374651,_0x4d0ff0,!![]);}catch(_0x36a383){return BPromise['reject'](_0x36a383);}return _0x374651[_0x685f('0x21')]();};}function saveUpdates(_0x2df8b1,_0x3ea42e){return function(_0x43395d){if(_0x43395d){return _0x43395d[_0x685f('0x22')](_0x2df8b1)[_0x685f('0x23')](function(_0x5f2c5a){return _0x5f2c5a;});}return null;};}function removeEntity(_0x2b9e36,_0x4ebc28){return function(_0x58617d){if(_0x58617d){return _0x58617d[_0x685f('0x24')]()[_0x685f('0x23')](function(){_0x2b9e36[_0x685f('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x59cba1,_0x33189e){return function(_0x133a9b){if(!_0x133a9b){_0x59cba1[_0x685f('0x25')](0x194);}return _0x133a9b;};}function handleError(_0x5707fd,_0x5ffa0e){_0x5ffa0e=_0x5ffa0e||0x1f4;return function(_0x9e9f16){logger[_0x685f('0x26')](_0x9e9f16[_0x685f('0x27')]);if(_0x9e9f16[_0x685f('0x28')]){delete _0x9e9f16['name'];}_0x5707fd[_0x685f('0x19')](_0x5ffa0e)[_0x685f('0x29')](_0x9e9f16);};}exports[_0x685f('0x2a')]=function(_0x5a77c9,_0x7bf1a4){var _0x40232f={},_0x34ac21={},_0x5f4f2f={'count':0x0,'rows':[]};var _0x159a6d=_['map'](db[_0x685f('0x2b')]['rawAttributes'],function(_0x1c8960){return{'name':_0x1c8960[_0x685f('0x2c')],'type':_0x1c8960[_0x685f('0x2d')]['key']};});_0x34ac21[_0x685f('0x2e')]=_[_0x685f('0x2f')](_0x159a6d,_0x685f('0x28'));_0x34ac21['query']=_[_0x685f('0x30')](_0x5a77c9[_0x685f('0x31')]);_0x34ac21['filters']=_[_0x685f('0x32')](_0x34ac21[_0x685f('0x2e')],_0x34ac21['query']);_0x40232f[_0x685f('0x33')]=_['intersection'](_0x34ac21['model'],qs[_0x685f('0x34')](_0x5a77c9['query'][_0x685f('0x34')]));_0x40232f[_0x685f('0x33')]=_0x40232f[_0x685f('0x33')][_0x685f('0x35')]?_0x40232f[_0x685f('0x33')]:_0x34ac21['model'];if(!_0x5a77c9['query'][_0x685f('0x36')](_0x685f('0x37'))){_0x40232f['limit']=qs[_0x685f('0x38')](_0x5a77c9['query']['limit']);_0x40232f['offset']=qs[_0x685f('0x1b')](_0x5a77c9[_0x685f('0x31')][_0x685f('0x1b')]);}_0x40232f[_0x685f('0x39')]=qs[_0x685f('0x3a')](_0x5a77c9[_0x685f('0x31')][_0x685f('0x3a')]);_0x40232f[_0x685f('0x3b')]=qs[_0x685f('0x3c')](_[_0x685f('0x3d')](_0x5a77c9[_0x685f('0x31')],_0x34ac21[_0x685f('0x3c')]),_0x159a6d);if(_0x5a77c9[_0x685f('0x31')][_0x685f('0x3e')]){_0x40232f[_0x685f('0x3b')]=_[_0x685f('0x3f')](_0x40232f[_0x685f('0x3b')],{'$or':_[_0x685f('0x2f')](_0x159a6d,function(_0x55e6b7){if(_0x55e6b7[_0x685f('0x2d')]!==_0x685f('0x40')){var _0x54970b={};_0x54970b[_0x55e6b7['name']]={'$like':'%'+_0x5a77c9[_0x685f('0x31')][_0x685f('0x3e')]+'%'};return _0x54970b;}})});}_0x40232f=_[_0x685f('0x3f')]({},_0x40232f,_0x5a77c9[_0x685f('0x41')]);var _0x354636={'where':_0x40232f[_0x685f('0x3b')]};return db[_0x685f('0x2b')][_0x685f('0x1d')](_0x354636)[_0x685f('0x23')](function(_0x165368){_0x5f4f2f[_0x685f('0x1d')]=_0x165368;if(_0x5a77c9[_0x685f('0x31')]['includeAll']){_0x40232f[_0x685f('0x42')]=[{'all':!![]}];}return db[_0x685f('0x2b')][_0x685f('0x43')](_0x40232f);})[_0x685f('0x23')](function(_0x556557){_0x5f4f2f['rows']=_0x556557;return _0x5f4f2f;})['then'](respondWithFilteredResult(_0x7bf1a4,_0x40232f))['catch'](handleError(_0x7bf1a4,null));};