Built motion from commit 911eb874.|2.6.31
[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 _0xb965=['stack','name','send','index','map','Migration','rawAttributes','fieldName','type','key','query','keys','filters','intersection','fields','attributes','model','nolimit','limit','order','sort','where','pick','merge','VIRTUAL','options','include','rows','catch','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','set','Content-Range','save','update','then','error'];(function(_0xea91e,_0x45045d){var _0x99d246=function(_0x29a18d){while(--_0x29a18d){_0xea91e['push'](_0xea91e['shift']());}};_0x99d246(++_0x45045d);}(_0xb965,0x1eb));var _0x5b96=function(_0x353471,_0x19f123){_0x353471=_0x353471-0x0;var _0x584806=_0xb965[_0x353471];return _0x584806;};'use strict';var emlformat=require(_0x5b96('0x0'));var rimraf=require(_0x5b96('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5b96('0x2'));var rp=require(_0x5b96('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x5b96('0x4'));var util=require(_0x5b96('0x5'));var path=require(_0x5b96('0x6'));var sox=require(_0x5b96('0x7'));var csv=require(_0x5b96('0x8'));var ejs=require(_0x5b96('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5b96('0xa'));var squel=require(_0x5b96('0xb'));var crypto=require(_0x5b96('0xc'));var jsforce=require(_0x5b96('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x5b96('0x8'));var querystring=require(_0x5b96('0xe'));var Papa=require(_0x5b96('0xf'));var Redis=require(_0x5b96('0x10'));var authService=require(_0x5b96('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x5b96('0x12'));var hardwareService=require(_0x5b96('0x13'));var logger=require(_0x5b96('0x14'))(_0x5b96('0x15'));var utils=require(_0x5b96('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x5b96('0x17'))['db'];function respondWithStatusCode(_0xd35eb8,_0x1ddba9){_0x1ddba9=_0x1ddba9||0xcc;return function(_0x11a29c){if(_0x11a29c){return _0xd35eb8[_0x5b96('0x18')](_0x1ddba9);}return _0xd35eb8[_0x5b96('0x19')](_0x1ddba9)[_0x5b96('0x1a')]();};}function respondWithResult(_0x3a5142,_0x2e69f9){_0x2e69f9=_0x2e69f9||0xc8;return function(_0x27d5af){if(_0x27d5af){return _0x3a5142['status'](_0x2e69f9)[_0x5b96('0x1b')](_0x27d5af);}};}function respondWithFilteredResult(_0x19ca00,_0x45ff73){return function(_0x27b930){if(_0x27b930){var _0x2b0202=typeof _0x45ff73[_0x5b96('0x1c')]===_0x5b96('0x1d')&&typeof _0x45ff73['limit']==='undefined';var _0x194dd9=_0x27b930[_0x5b96('0x1e')];var _0x5c68aa=_0x2b0202?0x0:_0x45ff73[_0x5b96('0x1c')];var _0x4f62dd=_0x2b0202?_0x27b930[_0x5b96('0x1e')]:_0x45ff73[_0x5b96('0x1c')]+_0x45ff73['limit'];var _0x4e1b17;if(_0x4f62dd>=_0x194dd9){_0x4f62dd=_0x194dd9;_0x4e1b17=0xc8;}else{_0x4e1b17=0xce;}_0x19ca00[_0x5b96('0x19')](_0x4e1b17);return _0x19ca00[_0x5b96('0x1f')](_0x5b96('0x20'),_0x5c68aa+'-'+_0x4f62dd+'/'+_0x194dd9)[_0x5b96('0x1b')](_0x27b930);}return null;};}function patchUpdates(_0x1dc30a){return function(_0xf2b23b){try{jsonpatch['apply'](_0xf2b23b,_0x1dc30a,!![]);}catch(_0x54f694){return BPromise['reject'](_0x54f694);}return _0xf2b23b[_0x5b96('0x21')]();};}function saveUpdates(_0xd9fcfc,_0x3a06c0){return function(_0x20bab6){if(_0x20bab6){return _0x20bab6[_0x5b96('0x22')](_0xd9fcfc)[_0x5b96('0x23')](function(_0x10dfbb){return _0x10dfbb;});}return null;};}function removeEntity(_0x417c70,_0x57f0ce){return function(_0x4c72b2){if(_0x4c72b2){return _0x4c72b2['destroy']()['then'](function(){_0x417c70[_0x5b96('0x19')](0xcc)[_0x5b96('0x1a')]();});}};}function handleEntityNotFound(_0x55d242,_0x50a22a){return function(_0x5e02f4){if(!_0x5e02f4){_0x55d242[_0x5b96('0x18')](0x194);}return _0x5e02f4;};}function handleError(_0xe511d9,_0x4bd7e1){_0x4bd7e1=_0x4bd7e1||0x1f4;return function(_0xbb30a){logger[_0x5b96('0x24')](_0xbb30a[_0x5b96('0x25')]);if(_0xbb30a['name']){delete _0xbb30a[_0x5b96('0x26')];}_0xe511d9[_0x5b96('0x19')](_0x4bd7e1)[_0x5b96('0x27')](_0xbb30a);};}exports[_0x5b96('0x28')]=function(_0x324670,_0x52ff10){var _0x7b1151={},_0x214f10={},_0x5aff03={'count':0x0,'rows':[]};var _0x309668=_[_0x5b96('0x29')](db[_0x5b96('0x2a')][_0x5b96('0x2b')],function(_0x42c511){return{'name':_0x42c511[_0x5b96('0x2c')],'type':_0x42c511[_0x5b96('0x2d')][_0x5b96('0x2e')]};});_0x214f10['model']=_[_0x5b96('0x29')](_0x309668,_0x5b96('0x26'));_0x214f10[_0x5b96('0x2f')]=_[_0x5b96('0x30')](_0x324670[_0x5b96('0x2f')]);_0x214f10[_0x5b96('0x31')]=_[_0x5b96('0x32')](_0x214f10['model'],_0x214f10['query']);_0x7b1151['attributes']=_[_0x5b96('0x32')](_0x214f10['model'],qs[_0x5b96('0x33')](_0x324670['query'][_0x5b96('0x33')]));_0x7b1151[_0x5b96('0x34')]=_0x7b1151[_0x5b96('0x34')]['length']?_0x7b1151[_0x5b96('0x34')]:_0x214f10[_0x5b96('0x35')];if(!_0x324670['query']['hasOwnProperty'](_0x5b96('0x36'))){_0x7b1151[_0x5b96('0x37')]=qs[_0x5b96('0x37')](_0x324670[_0x5b96('0x2f')][_0x5b96('0x37')]);_0x7b1151[_0x5b96('0x1c')]=qs[_0x5b96('0x1c')](_0x324670[_0x5b96('0x2f')][_0x5b96('0x1c')]);}_0x7b1151[_0x5b96('0x38')]=qs['sort'](_0x324670[_0x5b96('0x2f')][_0x5b96('0x39')]);_0x7b1151[_0x5b96('0x3a')]=qs[_0x5b96('0x31')](_[_0x5b96('0x3b')](_0x324670[_0x5b96('0x2f')],_0x214f10[_0x5b96('0x31')]),_0x309668);if(_0x324670[_0x5b96('0x2f')]['filter']){_0x7b1151[_0x5b96('0x3a')]=_[_0x5b96('0x3c')](_0x7b1151['where'],{'$or':_[_0x5b96('0x29')](_0x309668,function(_0x1ee93a){if(_0x1ee93a[_0x5b96('0x2d')]!==_0x5b96('0x3d')){var _0x2fe56b={};_0x2fe56b[_0x1ee93a['name']]={'$like':'%'+_0x324670[_0x5b96('0x2f')]['filter']+'%'};return _0x2fe56b;}})});}_0x7b1151=_[_0x5b96('0x3c')]({},_0x7b1151,_0x324670[_0x5b96('0x3e')]);var _0x7ddf58={'where':_0x7b1151[_0x5b96('0x3a')]};return db[_0x5b96('0x2a')][_0x5b96('0x1e')](_0x7ddf58)['then'](function(_0x564c9c){_0x5aff03[_0x5b96('0x1e')]=_0x564c9c;if(_0x324670[_0x5b96('0x2f')]['includeAll']){_0x7b1151[_0x5b96('0x3f')]=[{'all':!![]}];}return db['Migration']['findAll'](_0x7b1151);})[_0x5b96('0x23')](function(_0x79c250){_0x5aff03[_0x5b96('0x40')]=_0x79c250;return _0x5aff03;})[_0x5b96('0x23')](respondWithFilteredResult(_0x52ff10,_0x7b1151))[_0x5b96('0x41')](handleError(_0x52ff10,null));};