Built motion from commit (unavailable).|2.5.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 _0x30f6=['stack','name','send','index','map','Migration','fieldName','key','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','filters','where','VIRTUAL','filter','options','includeAll','findAll','rows','catch','html-pdf','rimraf','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','end'];(function(_0x2a5e73,_0x3ae6de){var _0x5f2152=function(_0x35b1f6){while(--_0x35b1f6){_0x2a5e73['push'](_0x2a5e73['shift']());}};_0x5f2152(++_0x3ae6de);}(_0x30f6,0x160));var _0x630f=function(_0x595e57,_0x476362){_0x595e57=_0x595e57-0x0;var _0xd7a8a8=_0x30f6[_0x595e57];return _0xd7a8a8;};'use strict';var pdf=require(_0x630f('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x630f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x630f('0x2'));var moment=require(_0x630f('0x3'));var BPromise=require(_0x630f('0x4'));var Mustache=require(_0x630f('0x5'));var util=require(_0x630f('0x6'));var path=require(_0x630f('0x7'));var sox=require(_0x630f('0x8'));var csv=require(_0x630f('0x9'));var ejs=require(_0x630f('0xa'));var fs=require('fs');var _=require(_0x630f('0xb'));var squel=require(_0x630f('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x630f('0xd'));var toCsv=require(_0x630f('0x9'));var querystring=require(_0x630f('0xe'));var Papa=require(_0x630f('0xf'));var Redis=require(_0x630f('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x630f('0x11'));var as=require(_0x630f('0x12'));var hardwareService=require(_0x630f('0x13'));var logger=require(_0x630f('0x14'))('api');var utils=require(_0x630f('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x630f('0x16'));var db=require(_0x630f('0x17'))['db'];function respondWithStatusCode(_0x32c16e,_0x5e02ce){_0x5e02ce=_0x5e02ce||0xcc;return function(_0xfb4066){if(_0xfb4066){return _0x32c16e[_0x630f('0x18')](_0x5e02ce);}return _0x32c16e[_0x630f('0x19')](_0x5e02ce)['end']();};}function respondWithResult(_0x210cda,_0x379a74){_0x379a74=_0x379a74||0xc8;return function(_0x274566){if(_0x274566){return _0x210cda[_0x630f('0x19')](_0x379a74)[_0x630f('0x1a')](_0x274566);}};}function respondWithFilteredResult(_0x256d00,_0x2dfff7){return function(_0x5b0d8e){if(_0x5b0d8e){var _0x4e39f1=_0x5b0d8e[_0x630f('0x1b')],_0xf771d4=_0x2dfff7[_0x630f('0x1c')],_0x2584bd=_0x2dfff7['offset']+_0x2dfff7[_0x630f('0x1d')],_0x55427b;if(_0x2584bd>=_0x4e39f1){_0x2584bd=_0x4e39f1;_0x55427b=0xc8;}else{_0x55427b=0xce;}_0x256d00[_0x630f('0x19')](_0x55427b);return _0x256d00[_0x630f('0x1e')](_0x630f('0x1f'),_0xf771d4+'-'+_0x2584bd+'/'+_0x4e39f1)[_0x630f('0x1a')](_0x5b0d8e);}return null;};}function patchUpdates(_0x1a616d){return function(_0x31c138){try{jsonpatch[_0x630f('0x20')](_0x31c138,_0x1a616d,!![]);}catch(_0x89dfae){return BPromise['reject'](_0x89dfae);}return _0x31c138[_0x630f('0x21')]();};}function saveUpdates(_0x21a9e2,_0x4fefd2){return function(_0x1542c5){if(_0x1542c5){return _0x1542c5[_0x630f('0x22')](_0x21a9e2)[_0x630f('0x23')](function(_0xc106fc){return _0xc106fc;});}return null;};}function removeEntity(_0x1ac59d,_0xd00bfc){return function(_0x1e9e56){if(_0x1e9e56){return _0x1e9e56[_0x630f('0x24')]()[_0x630f('0x23')](function(){_0x1ac59d[_0x630f('0x19')](0xcc)[_0x630f('0x25')]();});}};}function handleEntityNotFound(_0x16b159,_0x5c1de5){return function(_0x59519d){if(!_0x59519d){_0x16b159[_0x630f('0x18')](0x194);}return _0x59519d;};}function handleError(_0x566fd4,_0x586c22){_0x586c22=_0x586c22||0x1f4;return function(_0x347116){logger['error'](_0x347116[_0x630f('0x26')]);if(_0x347116['name']){delete _0x347116[_0x630f('0x27')];}_0x566fd4[_0x630f('0x19')](_0x586c22)[_0x630f('0x28')](_0x347116);};}exports[_0x630f('0x29')]=function(_0x33c550,_0x487073){var _0x4ae8e8={},_0x13d4c1={},_0x144d63={'count':0x0,'rows':[]};var _0x185560=_[_0x630f('0x2a')](db[_0x630f('0x2b')]['rawAttributes'],function(_0x482dfa){return{'name':_0x482dfa[_0x630f('0x2c')],'type':_0x482dfa['type'][_0x630f('0x2d')]};});_0x13d4c1[_0x630f('0x2e')]=_['map'](_0x185560,'name');_0x13d4c1[_0x630f('0x2f')]=_[_0x630f('0x30')](_0x33c550[_0x630f('0x2f')]);_0x13d4c1['filters']=_['intersection'](_0x13d4c1[_0x630f('0x2e')],_0x13d4c1['query']);_0x4ae8e8[_0x630f('0x31')]=_[_0x630f('0x32')](_0x13d4c1[_0x630f('0x2e')],qs[_0x630f('0x33')](_0x33c550[_0x630f('0x2f')][_0x630f('0x33')]));_0x4ae8e8['attributes']=_0x4ae8e8[_0x630f('0x31')][_0x630f('0x34')]?_0x4ae8e8['attributes']:_0x13d4c1[_0x630f('0x2e')];if(!_0x33c550[_0x630f('0x2f')][_0x630f('0x35')](_0x630f('0x36'))){_0x4ae8e8[_0x630f('0x1d')]=qs[_0x630f('0x1d')](_0x33c550['query'][_0x630f('0x1d')]);_0x4ae8e8[_0x630f('0x1c')]=qs[_0x630f('0x1c')](_0x33c550[_0x630f('0x2f')][_0x630f('0x1c')]);}_0x4ae8e8['order']=qs[_0x630f('0x37')](_0x33c550['query']['sort']);_0x4ae8e8['where']=qs[_0x630f('0x38')](_['pick'](_0x33c550[_0x630f('0x2f')],_0x13d4c1[_0x630f('0x38')]),_0x185560);if(_0x33c550[_0x630f('0x2f')]['filter']){_0x4ae8e8[_0x630f('0x39')]=_['merge'](_0x4ae8e8['where'],{'$or':_['map'](_0x185560,function(_0xb7c412){if(_0xb7c412['type']!==_0x630f('0x3a')){var _0x46d54d={};_0x46d54d[_0xb7c412['name']]={'$like':'%'+_0x33c550['query'][_0x630f('0x3b')]+'%'};return _0x46d54d;}})});}_0x4ae8e8=_['merge']({},_0x4ae8e8,_0x33c550[_0x630f('0x3c')]);var _0xb2f811={'where':_0x4ae8e8[_0x630f('0x39')]};return db['Migration'][_0x630f('0x1b')](_0xb2f811)[_0x630f('0x23')](function(_0x2f93a2){_0x144d63[_0x630f('0x1b')]=_0x2f93a2;if(_0x33c550['query'][_0x630f('0x3d')]){_0x4ae8e8['include']=[{'all':!![]}];}return db[_0x630f('0x2b')][_0x630f('0x3e')](_0x4ae8e8);})[_0x630f('0x23')](function(_0x2fa7d1){_0x144d63[_0x630f('0x3f')]=_0x2fa7d1;return _0x144d63;})[_0x630f('0x23')](respondWithFilteredResult(_0x487073,_0x4ae8e8))[_0x630f('0x40')](handleError(_0x487073,null));};