Built motion from commit e02f907f.|2.6.14
[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 _0x8494=['merge','VIRTUAL','options','includeAll','include','Migration','rows','catch','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','to-csv','fs-extra','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','save','update','then','destroy','sendStatus','error','name','send','fieldName','type','model','map','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter'];(function(_0x3889ae,_0x4770c3){var _0x6533dd=function(_0x4275f7){while(--_0x4275f7){_0x3889ae['push'](_0x3889ae['shift']());}};_0x6533dd(++_0x4770c3);}(_0x8494,0xce));var _0x4849=function(_0x4e3b2d,_0x11ab46){_0x4e3b2d=_0x4e3b2d-0x0;var _0x24d3bc=_0x8494[_0x4e3b2d];return _0x24d3bc;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4849('0x0'));var zipdir=require(_0x4849('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x4849('0x2'));var moment=require(_0x4849('0x3'));var BPromise=require(_0x4849('0x4'));var Mustache=require(_0x4849('0x5'));var util=require(_0x4849('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x4849('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x4849('0x8'));var _=require(_0x4849('0x9'));var squel=require(_0x4849('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x4849('0xb'));var toCsv=require(_0x4849('0x7'));var querystring=require(_0x4849('0xc'));var Papa=require(_0x4849('0xd'));var Redis=require(_0x4849('0xe'));var authService=require(_0x4849('0xf'));var qs=require(_0x4849('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4849('0x11'));var logger=require(_0x4849('0x12'))(_0x4849('0x13'));var utils=require(_0x4849('0x14'));var config=require(_0x4849('0x15'));var licenseUtil=require(_0x4849('0x16'));var db=require(_0x4849('0x17'))['db'];function respondWithStatusCode(_0x4bdbbd,_0x154c97){_0x154c97=_0x154c97||0xcc;return function(_0x1b0e01){if(_0x1b0e01){return _0x4bdbbd['sendStatus'](_0x154c97);}return _0x4bdbbd[_0x4849('0x18')](_0x154c97)[_0x4849('0x19')]();};}function respondWithResult(_0x65550d,_0x446875){_0x446875=_0x446875||0xc8;return function(_0x263149){if(_0x263149){return _0x65550d[_0x4849('0x18')](_0x446875)[_0x4849('0x1a')](_0x263149);}};}function respondWithFilteredResult(_0x1eb8f7,_0x4fedbb){return function(_0x4c17e8){if(_0x4c17e8){var _0x37a1c1=typeof _0x4fedbb[_0x4849('0x1b')]==='undefined'&&typeof _0x4fedbb[_0x4849('0x1c')]===_0x4849('0x1d');var _0x2378f8=_0x4c17e8['count'];var _0x52764a=_0x37a1c1?0x0:_0x4fedbb['offset'];var _0x378230=_0x37a1c1?_0x4c17e8[_0x4849('0x1e')]:_0x4fedbb[_0x4849('0x1b')]+_0x4fedbb[_0x4849('0x1c')];var _0x5757e6;if(_0x378230>=_0x2378f8){_0x378230=_0x2378f8;_0x5757e6=0xc8;}else{_0x5757e6=0xce;}_0x1eb8f7[_0x4849('0x18')](_0x5757e6);return _0x1eb8f7[_0x4849('0x1f')](_0x4849('0x20'),_0x52764a+'-'+_0x378230+'/'+_0x2378f8)[_0x4849('0x1a')](_0x4c17e8);}return null;};}function patchUpdates(_0x27c55d){return function(_0x24e7df){try{jsonpatch[_0x4849('0x21')](_0x24e7df,_0x27c55d,!![]);}catch(_0x49c4e2){return BPromise['reject'](_0x49c4e2);}return _0x24e7df[_0x4849('0x22')]();};}function saveUpdates(_0x2e4699,_0x1849d1){return function(_0xe5c68e){if(_0xe5c68e){return _0xe5c68e[_0x4849('0x23')](_0x2e4699)[_0x4849('0x24')](function(_0x4acb63){return _0x4acb63;});}return null;};}function removeEntity(_0x5602bd,_0x1b7f3b){return function(_0x1e4048){if(_0x1e4048){return _0x1e4048[_0x4849('0x25')]()[_0x4849('0x24')](function(){_0x5602bd[_0x4849('0x18')](0xcc)[_0x4849('0x19')]();});}};}function handleEntityNotFound(_0x1018b6,_0xbd37ef){return function(_0x4f12fe){if(!_0x4f12fe){_0x1018b6[_0x4849('0x26')](0x194);}return _0x4f12fe;};}function handleError(_0x4db96e,_0x2e5f77){_0x2e5f77=_0x2e5f77||0x1f4;return function(_0x192bfc){logger[_0x4849('0x27')](_0x192bfc['stack']);if(_0x192bfc[_0x4849('0x28')]){delete _0x192bfc[_0x4849('0x28')];}_0x4db96e[_0x4849('0x18')](_0x2e5f77)[_0x4849('0x29')](_0x192bfc);};}exports['index']=function(_0x2eae0e,_0x3c8746){var _0x50eedc={},_0x35dd7c={},_0x21ce9c={'count':0x0,'rows':[]};var _0x1c103c=_['map'](db['Migration']['rawAttributes'],function(_0x201ea4){return{'name':_0x201ea4[_0x4849('0x2a')],'type':_0x201ea4[_0x4849('0x2b')]['key']};});_0x35dd7c[_0x4849('0x2c')]=_[_0x4849('0x2d')](_0x1c103c,_0x4849('0x28'));_0x35dd7c[_0x4849('0x2e')]=_['keys'](_0x2eae0e[_0x4849('0x2e')]);_0x35dd7c[_0x4849('0x2f')]=_['intersection'](_0x35dd7c[_0x4849('0x2c')],_0x35dd7c[_0x4849('0x2e')]);_0x50eedc['attributes']=_[_0x4849('0x30')](_0x35dd7c[_0x4849('0x2c')],qs[_0x4849('0x31')](_0x2eae0e[_0x4849('0x2e')][_0x4849('0x31')]));_0x50eedc[_0x4849('0x32')]=_0x50eedc['attributes'][_0x4849('0x33')]?_0x50eedc[_0x4849('0x32')]:_0x35dd7c['model'];if(!_0x2eae0e[_0x4849('0x2e')][_0x4849('0x34')](_0x4849('0x35'))){_0x50eedc[_0x4849('0x1c')]=qs['limit'](_0x2eae0e[_0x4849('0x2e')][_0x4849('0x1c')]);_0x50eedc[_0x4849('0x1b')]=qs[_0x4849('0x1b')](_0x2eae0e[_0x4849('0x2e')][_0x4849('0x1b')]);}_0x50eedc[_0x4849('0x36')]=qs[_0x4849('0x37')](_0x2eae0e[_0x4849('0x2e')][_0x4849('0x37')]);_0x50eedc[_0x4849('0x38')]=qs[_0x4849('0x2f')](_['pick'](_0x2eae0e[_0x4849('0x2e')],_0x35dd7c[_0x4849('0x2f')]),_0x1c103c);if(_0x2eae0e[_0x4849('0x2e')][_0x4849('0x39')]){_0x50eedc[_0x4849('0x38')]=_[_0x4849('0x3a')](_0x50eedc[_0x4849('0x38')],{'$or':_[_0x4849('0x2d')](_0x1c103c,function(_0x434b7f){if(_0x434b7f['type']!==_0x4849('0x3b')){var _0x1b82a2={};_0x1b82a2[_0x434b7f['name']]={'$like':'%'+_0x2eae0e[_0x4849('0x2e')][_0x4849('0x39')]+'%'};return _0x1b82a2;}})});}_0x50eedc=_[_0x4849('0x3a')]({},_0x50eedc,_0x2eae0e[_0x4849('0x3c')]);var _0x33dc6b={'where':_0x50eedc[_0x4849('0x38')]};return db['Migration'][_0x4849('0x1e')](_0x33dc6b)[_0x4849('0x24')](function(_0x2a0243){_0x21ce9c[_0x4849('0x1e')]=_0x2a0243;if(_0x2eae0e['query'][_0x4849('0x3d')]){_0x50eedc[_0x4849('0x3e')]=[{'all':!![]}];}return db[_0x4849('0x3f')]['findAll'](_0x50eedc);})[_0x4849('0x24')](function(_0x1519bb){_0x21ce9c[_0x4849('0x40')]=_0x1519bb;return _0x21ce9c;})[_0x4849('0x24')](respondWithFilteredResult(_0x3c8746,_0x50eedc))[_0x4849('0x41')](handleError(_0x3c8746,null));};