Built motion from commit (unavailable).|2.5.11
[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 _0xb684=['Content-Range','apply','reject','save','update','then','destroy','end','error','send','index','map','Migration','rawAttributes','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filter','merge','type','VIRTUAL','name','options','includeAll','rows','catch','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','set'];(function(_0x3932eb,_0x43b210){var _0x5316e5=function(_0x1744e8){while(--_0x1744e8){_0x3932eb['push'](_0x3932eb['shift']());}};_0x5316e5(++_0x43b210);}(_0xb684,0xa8));var _0x4b68=function(_0x695180,_0x2f5ed3){_0x695180=_0x695180-0x0;var _0x2ccec3=_0xb684[_0x695180];return _0x2ccec3;};'use strict';var pdf=require(_0x4b68('0x0'));var emlformat=require(_0x4b68('0x1'));var rimraf=require(_0x4b68('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x4b68('0x3'));var rp=require(_0x4b68('0x4'));var moment=require(_0x4b68('0x5'));var BPromise=require(_0x4b68('0x6'));var Mustache=require(_0x4b68('0x7'));var util=require('util');var path=require(_0x4b68('0x8'));var sox=require(_0x4b68('0x9'));var csv=require(_0x4b68('0xa'));var ejs=require(_0x4b68('0xb'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x4b68('0xc'));var deskjs=require(_0x4b68('0xd'));var toCsv=require(_0x4b68('0xa'));var querystring=require('querystring');var Papa=require(_0x4b68('0xe'));var Redis=require(_0x4b68('0xf'));var authService=require(_0x4b68('0x10'));var qs=require(_0x4b68('0x11'));var as=require(_0x4b68('0x12'));var hardwareService=require(_0x4b68('0x13'));var logger=require(_0x4b68('0x14'))('api');var utils=require(_0x4b68('0x15'));var config=require(_0x4b68('0x16'));var licenseUtil=require(_0x4b68('0x17'));var db=require(_0x4b68('0x18'))['db'];function respondWithStatusCode(_0x376563,_0x22aad2){_0x22aad2=_0x22aad2||0xcc;return function(_0xd86c2f){if(_0xd86c2f){return _0x376563[_0x4b68('0x19')](_0x22aad2);}return _0x376563[_0x4b68('0x1a')](_0x22aad2)['end']();};}function respondWithResult(_0x1cc395,_0x254152){_0x254152=_0x254152||0xc8;return function(_0x4596e3){if(_0x4596e3){return _0x1cc395[_0x4b68('0x1a')](_0x254152)[_0x4b68('0x1b')](_0x4596e3);}};}function respondWithFilteredResult(_0x5cf7da,_0xe66424){return function(_0x4b87bf){if(_0x4b87bf){var _0x86ac04=_0x4b87bf['count'],_0x1d6f75=_0xe66424['offset'],_0x4f4d77=_0xe66424[_0x4b68('0x1c')]+_0xe66424['limit'],_0x33db82;if(_0x4f4d77>=_0x86ac04){_0x4f4d77=_0x86ac04;_0x33db82=0xc8;}else{_0x33db82=0xce;}_0x5cf7da[_0x4b68('0x1a')](_0x33db82);return _0x5cf7da[_0x4b68('0x1d')](_0x4b68('0x1e'),_0x1d6f75+'-'+_0x4f4d77+'/'+_0x86ac04)['json'](_0x4b87bf);}return null;};}function patchUpdates(_0x4b0538){return function(_0x47809b){try{jsonpatch[_0x4b68('0x1f')](_0x47809b,_0x4b0538,!![]);}catch(_0x270940){return BPromise[_0x4b68('0x20')](_0x270940);}return _0x47809b[_0x4b68('0x21')]();};}function saveUpdates(_0x38b7ad,_0x19c3c6){return function(_0xfb9f46){if(_0xfb9f46){return _0xfb9f46[_0x4b68('0x22')](_0x38b7ad)[_0x4b68('0x23')](function(_0x6a3bc9){return _0x6a3bc9;});}return null;};}function removeEntity(_0x133762,_0x40f30c){return function(_0x5e6f02){if(_0x5e6f02){return _0x5e6f02[_0x4b68('0x24')]()[_0x4b68('0x23')](function(){_0x133762[_0x4b68('0x1a')](0xcc)[_0x4b68('0x25')]();});}};}function handleEntityNotFound(_0x428d79,_0x5155d5){return function(_0x2a4354){if(!_0x2a4354){_0x428d79[_0x4b68('0x19')](0x194);}return _0x2a4354;};}function handleError(_0xf727d0,_0x4f26ed){_0x4f26ed=_0x4f26ed||0x1f4;return function(_0x43d070){logger[_0x4b68('0x26')](_0x43d070['stack']);if(_0x43d070['name']){delete _0x43d070['name'];}_0xf727d0[_0x4b68('0x1a')](_0x4f26ed)[_0x4b68('0x27')](_0x43d070);};}exports[_0x4b68('0x28')]=function(_0x1502bd,_0x2a2c6a){var _0x4e9297={},_0x1e3dc4={},_0x50d551={'count':0x0,'rows':[]};var _0x550fd6=_[_0x4b68('0x29')](db[_0x4b68('0x2a')][_0x4b68('0x2b')],function(_0x54e0d3){return{'name':_0x54e0d3['fieldName'],'type':_0x54e0d3['type']['key']};});_0x1e3dc4[_0x4b68('0x2c')]=_[_0x4b68('0x29')](_0x550fd6,'name');_0x1e3dc4[_0x4b68('0x2d')]=_['keys'](_0x1502bd['query']);_0x1e3dc4[_0x4b68('0x2e')]=_[_0x4b68('0x2f')](_0x1e3dc4[_0x4b68('0x2c')],_0x1e3dc4[_0x4b68('0x2d')]);_0x4e9297[_0x4b68('0x30')]=_[_0x4b68('0x2f')](_0x1e3dc4[_0x4b68('0x2c')],qs[_0x4b68('0x31')](_0x1502bd[_0x4b68('0x2d')]['fields']));_0x4e9297[_0x4b68('0x30')]=_0x4e9297[_0x4b68('0x30')][_0x4b68('0x32')]?_0x4e9297[_0x4b68('0x30')]:_0x1e3dc4[_0x4b68('0x2c')];if(!_0x1502bd[_0x4b68('0x2d')][_0x4b68('0x33')](_0x4b68('0x34'))){_0x4e9297[_0x4b68('0x35')]=qs['limit'](_0x1502bd[_0x4b68('0x2d')][_0x4b68('0x35')]);_0x4e9297['offset']=qs[_0x4b68('0x1c')](_0x1502bd[_0x4b68('0x2d')]['offset']);}_0x4e9297[_0x4b68('0x36')]=qs[_0x4b68('0x37')](_0x1502bd[_0x4b68('0x2d')][_0x4b68('0x37')]);_0x4e9297[_0x4b68('0x38')]=qs[_0x4b68('0x2e')](_['pick'](_0x1502bd[_0x4b68('0x2d')],_0x1e3dc4[_0x4b68('0x2e')]),_0x550fd6);if(_0x1502bd[_0x4b68('0x2d')][_0x4b68('0x39')]){_0x4e9297['where']=_[_0x4b68('0x3a')](_0x4e9297[_0x4b68('0x38')],{'$or':_['map'](_0x550fd6,function(_0x5ba145){if(_0x5ba145[_0x4b68('0x3b')]!==_0x4b68('0x3c')){var _0x5c3831={};_0x5c3831[_0x5ba145[_0x4b68('0x3d')]]={'$like':'%'+_0x1502bd[_0x4b68('0x2d')][_0x4b68('0x39')]+'%'};return _0x5c3831;}})});}_0x4e9297=_[_0x4b68('0x3a')]({},_0x4e9297,_0x1502bd[_0x4b68('0x3e')]);var _0x1ae592={'where':_0x4e9297['where']};return db[_0x4b68('0x2a')]['count'](_0x1ae592)['then'](function(_0x48f39f){_0x50d551['count']=_0x48f39f;if(_0x1502bd[_0x4b68('0x2d')][_0x4b68('0x3f')]){_0x4e9297['include']=[{'all':!![]}];}return db['Migration']['findAll'](_0x4e9297);})['then'](function(_0x282a3c){_0x50d551[_0x4b68('0x40')]=_0x282a3c;return _0x50d551;})[_0x4b68('0x23')](respondWithFilteredResult(_0x2a2c6a,_0x4e9297))[_0x4b68('0x41')](handleError(_0x2a2c6a,null));};