Built motion from commit (unavailable).|2.5.26
[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 _0xb4f8=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../mysqldb','sendStatus','status','end','count','offset','limit','json','apply','update','then','error','stack','name','send','index','Migration','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xb4f8,0x6e));var _0x8b4f=function(_0x3f4891,_0x4e6f62){_0x3f4891=_0x3f4891-0x0;var _0x54f2d8=_0xb4f8[_0x3f4891];return _0x54f2d8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8b4f('0x0'));var zipdir=require(_0x8b4f('0x1'));var jsonpatch=require(_0x8b4f('0x2'));var rp=require(_0x8b4f('0x3'));var moment=require(_0x8b4f('0x4'));var BPromise=require(_0x8b4f('0x5'));var Mustache=require(_0x8b4f('0x6'));var util=require(_0x8b4f('0x7'));var path=require(_0x8b4f('0x8'));var sox=require(_0x8b4f('0x9'));var csv=require(_0x8b4f('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x8b4f('0xb'));var _=require(_0x8b4f('0xc'));var squel=require(_0x8b4f('0xd'));var crypto=require('crypto');var jsforce=require(_0x8b4f('0xe'));var deskjs=require(_0x8b4f('0xf'));var toCsv=require('to-csv');var querystring=require(_0x8b4f('0x10'));var Papa=require(_0x8b4f('0x11'));var Redis=require(_0x8b4f('0x12'));var authService=require(_0x8b4f('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x8b4f('0x14'));var hardwareService=require(_0x8b4f('0x15'));var logger=require(_0x8b4f('0x16'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x8b4f('0x17'))['db'];function respondWithStatusCode(_0x402d05,_0x9e6ea7){_0x9e6ea7=_0x9e6ea7||0xcc;return function(_0x3a8027){if(_0x3a8027){return _0x402d05[_0x8b4f('0x18')](_0x9e6ea7);}return _0x402d05[_0x8b4f('0x19')](_0x9e6ea7)[_0x8b4f('0x1a')]();};}function respondWithResult(_0x1e0412,_0x19f81f){_0x19f81f=_0x19f81f||0xc8;return function(_0x20adf3){if(_0x20adf3){return _0x1e0412['status'](_0x19f81f)['json'](_0x20adf3);}};}function respondWithFilteredResult(_0x47e25e,_0x1154c4){return function(_0x121d6b){if(_0x121d6b){var _0x3b105b=_0x121d6b[_0x8b4f('0x1b')],_0x46da40=_0x1154c4['offset'],_0x59a823=_0x1154c4[_0x8b4f('0x1c')]+_0x1154c4[_0x8b4f('0x1d')],_0x1d5980;if(_0x59a823>=_0x3b105b){_0x59a823=_0x3b105b;_0x1d5980=0xc8;}else{_0x1d5980=0xce;}_0x47e25e['status'](_0x1d5980);return _0x47e25e['set']('Content-Range',_0x46da40+'-'+_0x59a823+'/'+_0x3b105b)[_0x8b4f('0x1e')](_0x121d6b);}return null;};}function patchUpdates(_0x11da21){return function(_0x5b9216){try{jsonpatch[_0x8b4f('0x1f')](_0x5b9216,_0x11da21,!![]);}catch(_0x38f31b){return BPromise['reject'](_0x38f31b);}return _0x5b9216['save']();};}function saveUpdates(_0x47ae69,_0x531423){return function(_0x35235a){if(_0x35235a){return _0x35235a[_0x8b4f('0x20')](_0x47ae69)[_0x8b4f('0x21')](function(_0x5cd053){return _0x5cd053;});}return null;};}function removeEntity(_0x27bd2d,_0x59b130){return function(_0x147e99){if(_0x147e99){return _0x147e99['destroy']()[_0x8b4f('0x21')](function(){_0x27bd2d[_0x8b4f('0x19')](0xcc)[_0x8b4f('0x1a')]();});}};}function handleEntityNotFound(_0x2161e9,_0x519f68){return function(_0x430084){if(!_0x430084){_0x2161e9[_0x8b4f('0x18')](0x194);}return _0x430084;};}function handleError(_0x2ac81a,_0x28900a){_0x28900a=_0x28900a||0x1f4;return function(_0xec14aa){logger[_0x8b4f('0x22')](_0xec14aa[_0x8b4f('0x23')]);if(_0xec14aa[_0x8b4f('0x24')]){delete _0xec14aa[_0x8b4f('0x24')];}_0x2ac81a[_0x8b4f('0x19')](_0x28900a)[_0x8b4f('0x25')](_0xec14aa);};}exports[_0x8b4f('0x26')]=function(_0x55e03b,_0x52a506){var _0x596f76={},_0xee17a5={},_0x254d93={'count':0x0,'rows':[]};var _0x56574e=_['map'](db[_0x8b4f('0x27')][_0x8b4f('0x28')],function(_0x150b49){return{'name':_0x150b49[_0x8b4f('0x29')],'type':_0x150b49[_0x8b4f('0x2a')][_0x8b4f('0x2b')]};});_0xee17a5[_0x8b4f('0x2c')]=_['map'](_0x56574e,_0x8b4f('0x24'));_0xee17a5[_0x8b4f('0x2d')]=_[_0x8b4f('0x2e')](_0x55e03b[_0x8b4f('0x2d')]);_0xee17a5[_0x8b4f('0x2f')]=_[_0x8b4f('0x30')](_0xee17a5[_0x8b4f('0x2c')],_0xee17a5[_0x8b4f('0x2d')]);_0x596f76[_0x8b4f('0x31')]=_[_0x8b4f('0x30')](_0xee17a5[_0x8b4f('0x2c')],qs['fields'](_0x55e03b[_0x8b4f('0x2d')][_0x8b4f('0x32')]));_0x596f76[_0x8b4f('0x31')]=_0x596f76[_0x8b4f('0x31')][_0x8b4f('0x33')]?_0x596f76[_0x8b4f('0x31')]:_0xee17a5[_0x8b4f('0x2c')];if(!_0x55e03b['query'][_0x8b4f('0x34')]('nolimit')){_0x596f76['limit']=qs[_0x8b4f('0x1d')](_0x55e03b['query'][_0x8b4f('0x1d')]);_0x596f76[_0x8b4f('0x1c')]=qs[_0x8b4f('0x1c')](_0x55e03b[_0x8b4f('0x2d')][_0x8b4f('0x1c')]);}_0x596f76[_0x8b4f('0x35')]=qs[_0x8b4f('0x36')](_0x55e03b['query'][_0x8b4f('0x36')]);_0x596f76[_0x8b4f('0x37')]=qs[_0x8b4f('0x2f')](_[_0x8b4f('0x38')](_0x55e03b['query'],_0xee17a5[_0x8b4f('0x2f')]),_0x56574e);if(_0x55e03b[_0x8b4f('0x2d')][_0x8b4f('0x39')]){_0x596f76[_0x8b4f('0x37')]=_[_0x8b4f('0x3a')](_0x596f76['where'],{'$or':_['map'](_0x56574e,function(_0x9f2d71){if(_0x9f2d71[_0x8b4f('0x2a')]!==_0x8b4f('0x3b')){var _0x283bcc={};_0x283bcc[_0x9f2d71[_0x8b4f('0x24')]]={'$like':'%'+_0x55e03b[_0x8b4f('0x2d')][_0x8b4f('0x39')]+'%'};return _0x283bcc;}})});}_0x596f76=_[_0x8b4f('0x3a')]({},_0x596f76,_0x55e03b[_0x8b4f('0x3c')]);var _0x21a16b={'where':_0x596f76[_0x8b4f('0x37')]};return db[_0x8b4f('0x27')][_0x8b4f('0x1b')](_0x21a16b)[_0x8b4f('0x21')](function(_0x2e5b09){_0x254d93['count']=_0x2e5b09;if(_0x55e03b[_0x8b4f('0x2d')][_0x8b4f('0x3d')]){_0x596f76[_0x8b4f('0x3e')]=[{'all':!![]}];}return db[_0x8b4f('0x27')][_0x8b4f('0x3f')](_0x596f76);})[_0x8b4f('0x21')](function(_0x260d98){_0x254d93['rows']=_0x260d98;return _0x254d93;})['then'](respondWithFilteredResult(_0x52a506,_0x596f76))['catch'](handleError(_0x52a506,null));};