Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / intVtigerConfiguration / intVtigerConfiguration.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 _0x6719=['findOne','hasOwnProperty','getSubjects','VtigerField','getDescriptions','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','limit','undefined','count','offset','set','Content-Range','apply','reject','then','destroy','name','send','index','map','VtigerConfiguration','type','query','keys','intersection','attributes','model','fields','nolimit','order','sort','where','filters','pick','filter','VIRTUAL','merge','options','include','show','rawAttributes','length','includeAll','find','catch','create','body','params','getFields'];(function(_0x1621d8,_0x4756bf){var _0x6883c7=function(_0x3ed06c){while(--_0x3ed06c){_0x1621d8['push'](_0x1621d8['shift']());}};_0x6883c7(++_0x4756bf);}(_0x6719,0x139));var _0x9671=function(_0xb0c152,_0x1d37a9){_0xb0c152=_0xb0c152-0x0;var _0x2fc458=_0x6719[_0xb0c152];return _0x2fc458;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9671('0x0'));var zipdir=require(_0x9671('0x1'));var jsonpatch=require(_0x9671('0x2'));var rp=require(_0x9671('0x3'));var moment=require(_0x9671('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x9671('0x5'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x9671('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x9671('0x7'));var _=require(_0x9671('0x8'));var squel=require(_0x9671('0x9'));var crypto=require(_0x9671('0xa'));var jsforce=require(_0x9671('0xb'));var deskjs=require(_0x9671('0xc'));var toCsv=require(_0x9671('0x6'));var querystring=require(_0x9671('0xd'));var Papa=require(_0x9671('0xe'));var Redis=require(_0x9671('0xf'));var authService=require(_0x9671('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x9671('0x11'));var hardwareService=require(_0x9671('0x12'));var logger=require(_0x9671('0x13'))(_0x9671('0x14'));var utils=require(_0x9671('0x15'));var config=require(_0x9671('0x16'));var licenseUtil=require(_0x9671('0x17'));var db=require(_0x9671('0x18'))['db'];function respondWithStatusCode(_0x4fd91b,_0xd91700){_0xd91700=_0xd91700||0xcc;return function(_0x5ed7f3){if(_0x5ed7f3){return _0x4fd91b[_0x9671('0x19')](_0xd91700);}return _0x4fd91b[_0x9671('0x1a')](_0xd91700)[_0x9671('0x1b')]();};}function respondWithResult(_0x35a86b,_0x285dc0){_0x285dc0=_0x285dc0||0xc8;return function(_0x10fd9d){if(_0x10fd9d){return _0x35a86b[_0x9671('0x1a')](_0x285dc0)[_0x9671('0x1c')](_0x10fd9d);}};}function respondWithFilteredResult(_0x843045,_0xcd2b35){return function(_0x2c5da7){if(_0x2c5da7){var _0x3c552c=typeof _0xcd2b35['offset']==='undefined'&&typeof _0xcd2b35[_0x9671('0x1d')]===_0x9671('0x1e');var _0x20a4d0=_0x2c5da7[_0x9671('0x1f')];var _0x2e94b8=_0x3c552c?0x0:_0xcd2b35[_0x9671('0x20')];var _0x51c1c2=_0x3c552c?_0x2c5da7[_0x9671('0x1f')]:_0xcd2b35[_0x9671('0x20')]+_0xcd2b35['limit'];var _0xc78244;if(_0x51c1c2>=_0x20a4d0){_0x51c1c2=_0x20a4d0;_0xc78244=0xc8;}else{_0xc78244=0xce;}_0x843045['status'](_0xc78244);return _0x843045[_0x9671('0x21')](_0x9671('0x22'),_0x2e94b8+'-'+_0x51c1c2+'/'+_0x20a4d0)[_0x9671('0x1c')](_0x2c5da7);}return null;};}function patchUpdates(_0x1c57ac){return function(_0x9196d9){try{jsonpatch[_0x9671('0x23')](_0x9196d9,_0x1c57ac,!![]);}catch(_0x4864c3){return BPromise[_0x9671('0x24')](_0x4864c3);}return _0x9196d9['save']();};}function saveUpdates(_0x20af1f,_0x59c964){return function(_0x8a17f2){if(_0x8a17f2){return _0x8a17f2['update'](_0x20af1f)[_0x9671('0x25')](function(_0x58d389){return _0x58d389;});}return null;};}function removeEntity(_0x1a4c0a,_0x4bfce2){return function(_0x15bf58){if(_0x15bf58){return _0x15bf58[_0x9671('0x26')]()[_0x9671('0x25')](function(){_0x1a4c0a['status'](0xcc)[_0x9671('0x1b')]();});}};}function handleEntityNotFound(_0x598e42,_0x4024b5){return function(_0x515c62){if(!_0x515c62){_0x598e42[_0x9671('0x19')](0x194);}return _0x515c62;};}function handleError(_0x45633a,_0x146127){_0x146127=_0x146127||0x1f4;return function(_0x3d10fb){logger['error'](_0x3d10fb['stack']);if(_0x3d10fb[_0x9671('0x27')]){delete _0x3d10fb[_0x9671('0x27')];}_0x45633a[_0x9671('0x1a')](_0x146127)[_0x9671('0x28')](_0x3d10fb);};}exports[_0x9671('0x29')]=function(_0x40c82c,_0x56a5f2){var _0x341f94={},_0x19f30d={},_0x27eb0c={'count':0x0,'rows':[]};var _0x5d7957=_[_0x9671('0x2a')](db[_0x9671('0x2b')]['rawAttributes'],function(_0x3395c4){return{'name':_0x3395c4['fieldName'],'type':_0x3395c4[_0x9671('0x2c')]['key']};});_0x19f30d['model']=_['map'](_0x5d7957,_0x9671('0x27'));_0x19f30d[_0x9671('0x2d')]=_[_0x9671('0x2e')](_0x40c82c[_0x9671('0x2d')]);_0x19f30d['filters']=_[_0x9671('0x2f')](_0x19f30d['model'],_0x19f30d[_0x9671('0x2d')]);_0x341f94[_0x9671('0x30')]=_[_0x9671('0x2f')](_0x19f30d[_0x9671('0x31')],qs['fields'](_0x40c82c[_0x9671('0x2d')][_0x9671('0x32')]));_0x341f94[_0x9671('0x30')]=_0x341f94[_0x9671('0x30')]['length']?_0x341f94[_0x9671('0x30')]:_0x19f30d[_0x9671('0x31')];if(!_0x40c82c[_0x9671('0x2d')]['hasOwnProperty'](_0x9671('0x33'))){_0x341f94[_0x9671('0x1d')]=qs[_0x9671('0x1d')](_0x40c82c[_0x9671('0x2d')][_0x9671('0x1d')]);_0x341f94[_0x9671('0x20')]=qs[_0x9671('0x20')](_0x40c82c[_0x9671('0x2d')][_0x9671('0x20')]);}_0x341f94[_0x9671('0x34')]=qs[_0x9671('0x35')](_0x40c82c[_0x9671('0x2d')][_0x9671('0x35')]);_0x341f94[_0x9671('0x36')]=qs[_0x9671('0x37')](_[_0x9671('0x38')](_0x40c82c['query'],_0x19f30d[_0x9671('0x37')]),_0x5d7957);if(_0x40c82c['query'][_0x9671('0x39')]){_0x341f94['where']=_['merge'](_0x341f94[_0x9671('0x36')],{'$or':_[_0x9671('0x2a')](_0x5d7957,function(_0x2c752f){if(_0x2c752f[_0x9671('0x2c')]!==_0x9671('0x3a')){var _0xa5ed54={};_0xa5ed54[_0x2c752f[_0x9671('0x27')]]={'$like':'%'+_0x40c82c[_0x9671('0x2d')][_0x9671('0x39')]+'%'};return _0xa5ed54;}})});}_0x341f94=_[_0x9671('0x3b')]({},_0x341f94,_0x40c82c[_0x9671('0x3c')]);var _0x79b82a={'where':_0x341f94[_0x9671('0x36')]};return db[_0x9671('0x2b')][_0x9671('0x1f')](_0x79b82a)[_0x9671('0x25')](function(_0x161fc9){_0x27eb0c[_0x9671('0x1f')]=_0x161fc9;if(_0x40c82c[_0x9671('0x2d')]['includeAll']){_0x341f94[_0x9671('0x3d')]=[{'all':!![]}];}return db[_0x9671('0x2b')]['findAll'](_0x341f94);})[_0x9671('0x25')](function(_0x5b1901){_0x27eb0c['rows']=_0x5b1901;return _0x27eb0c;})[_0x9671('0x25')](respondWithFilteredResult(_0x56a5f2,_0x341f94))['catch'](handleError(_0x56a5f2,null));};exports[_0x9671('0x3e')]=function(_0x1782c7,_0x1c0399){var _0x1fadaf={'raw':![],'where':{'id':_0x1782c7['params']['id']}},_0x34078e={};_0x34078e[_0x9671('0x31')]=_[_0x9671('0x2e')](db[_0x9671('0x2b')][_0x9671('0x3f')]);_0x34078e[_0x9671('0x2d')]=_['keys'](_0x1782c7[_0x9671('0x2d')]);_0x34078e[_0x9671('0x37')]=_['intersection'](_0x34078e[_0x9671('0x31')],_0x34078e[_0x9671('0x2d')]);_0x1fadaf['attributes']=_['intersection'](_0x34078e[_0x9671('0x31')],qs[_0x9671('0x32')](_0x1782c7[_0x9671('0x2d')]['fields']));_0x1fadaf[_0x9671('0x30')]=_0x1fadaf[_0x9671('0x30')][_0x9671('0x40')]?_0x1fadaf[_0x9671('0x30')]:_0x34078e['model'];if(_0x1782c7['query'][_0x9671('0x41')]){_0x1fadaf['include']=[{'all':!![]}];}_0x1fadaf=_[_0x9671('0x3b')]({},_0x1fadaf,_0x1782c7[_0x9671('0x3c')]);return db[_0x9671('0x2b')][_0x9671('0x42')](_0x1fadaf)[_0x9671('0x25')](handleEntityNotFound(_0x1c0399,null))[_0x9671('0x25')](respondWithResult(_0x1c0399,null))[_0x9671('0x43')](handleError(_0x1c0399,null));};exports[_0x9671('0x44')]=function(_0xec2656,_0x46c285){return db[_0x9671('0x2b')]['create'](_0xec2656[_0x9671('0x45')],{})[_0x9671('0x25')](respondWithResult(_0x46c285,0xc9))[_0x9671('0x43')](handleError(_0x46c285,null));};exports['update']=function(_0x194241,_0x585dc9){if(_0x194241[_0x9671('0x45')]['id']){delete _0x194241[_0x9671('0x45')]['id'];}return db['VtigerConfiguration'][_0x9671('0x42')]({'where':{'id':_0x194241[_0x9671('0x46')]['id']}})[_0x9671('0x25')](handleEntityNotFound(_0x585dc9,null))[_0x9671('0x25')](saveUpdates(_0x194241[_0x9671('0x45')],null))['then'](respondWithResult(_0x585dc9,null))[_0x9671('0x43')](handleError(_0x585dc9,null));};exports['destroy']=function(_0xfcd491,_0xb8f9ea){return db[_0x9671('0x2b')][_0x9671('0x42')]({'where':{'id':_0xfcd491[_0x9671('0x46')]['id']}})[_0x9671('0x25')](handleEntityNotFound(_0xb8f9ea,null))[_0x9671('0x25')](removeEntity(_0xb8f9ea,null))[_0x9671('0x43')](handleError(_0xb8f9ea,null));};exports[_0x9671('0x47')]=function(_0x3a8e7a,_0x40f359,_0x1c9ae9){var _0x5e763a={};var _0x2e9fb2={};var _0x3b4759;var _0x5a90a0;return db['VtigerConfiguration'][_0x9671('0x48')]({'where':{'id':_0x3a8e7a[_0x9671('0x46')]['id']}})[_0x9671('0x25')](handleEntityNotFound(_0x40f359,null))['then'](function(_0x5e581a){if(_0x5e581a){_0x3b4759=_0x5e581a;_0x2e9fb2[_0x9671('0x31')]=_[_0x9671('0x2e')](db['VtigerField']['rawAttributes']);_0x2e9fb2[_0x9671('0x2d')]=_['keys'](_0x3a8e7a['query']);_0x2e9fb2['filters']=_['intersection'](_0x2e9fb2['model'],_0x2e9fb2[_0x9671('0x2d')]);_0x5e763a[_0x9671('0x30')]=_['intersection'](_0x2e9fb2[_0x9671('0x31')],qs['fields'](_0x3a8e7a[_0x9671('0x2d')][_0x9671('0x32')]));_0x5e763a['attributes']=_0x5e763a[_0x9671('0x30')][_0x9671('0x40')]?_0x5e763a[_0x9671('0x30')]:_0x2e9fb2[_0x9671('0x31')];_0x5e763a[_0x9671('0x34')]=qs[_0x9671('0x35')](_0x3a8e7a[_0x9671('0x2d')][_0x9671('0x35')]);_0x5e763a['where']=qs[_0x9671('0x37')](_[_0x9671('0x38')](_0x3a8e7a[_0x9671('0x2d')],_0x2e9fb2[_0x9671('0x37')]));if(_0x3a8e7a[_0x9671('0x2d')]['filter']){_0x5e763a[_0x9671('0x36')]=_['merge'](_0x5e763a[_0x9671('0x36')],{'$or':_[_0x9671('0x2a')](_0x5e763a[_0x9671('0x30')],function(_0x4bf3a5){var _0x1f294c={};_0x1f294c[_0x4bf3a5]={'$like':'%'+_0x3a8e7a[_0x9671('0x2d')]['filter']+'%'};return _0x1f294c;})});}_0x5e763a=_['merge']({},_0x5e763a,_0x3a8e7a[_0x9671('0x3c')]);return _0x3b4759[_0x9671('0x47')](_0x5e763a);}})[_0x9671('0x25')](function(_0xd21bf8){if(_0xd21bf8){_0x5a90a0=_0xd21bf8[_0x9671('0x40')];if(!_0x3a8e7a[_0x9671('0x2d')][_0x9671('0x49')]('nolimit')){_0x5e763a['limit']=qs[_0x9671('0x1d')](_0x3a8e7a[_0x9671('0x2d')][_0x9671('0x1d')]);_0x5e763a['offset']=qs[_0x9671('0x20')](_0x3a8e7a[_0x9671('0x2d')]['offset']);}return _0x3b4759[_0x9671('0x47')](_0x5e763a);}})[_0x9671('0x25')](function(_0x643895){if(_0x643895){return _0x643895?{'count':_0x5a90a0,'rows':_0x643895}:null;}})['then'](respondWithResult(_0x40f359,null))[_0x9671('0x43')](handleError(_0x40f359,null));};exports[_0x9671('0x4a')]=function(_0x29d515,_0x32ed10,_0x52c760){var _0x5bfe7c={};var _0x53c8a7={};var _0x23fc46;var _0x552759;return db['VtigerConfiguration'][_0x9671('0x48')]({'where':{'id':_0x29d515['params']['id']}})[_0x9671('0x25')](handleEntityNotFound(_0x32ed10,null))[_0x9671('0x25')](function(_0x367a57){if(_0x367a57){_0x23fc46=_0x367a57;_0x53c8a7[_0x9671('0x31')]=_[_0x9671('0x2e')](db[_0x9671('0x4b')]['rawAttributes']);_0x53c8a7['query']=_[_0x9671('0x2e')](_0x29d515['query']);_0x53c8a7['filters']=_['intersection'](_0x53c8a7[_0x9671('0x31')],_0x53c8a7[_0x9671('0x2d')]);_0x5bfe7c['attributes']=_[_0x9671('0x2f')](_0x53c8a7[_0x9671('0x31')],qs[_0x9671('0x32')](_0x29d515[_0x9671('0x2d')][_0x9671('0x32')]));_0x5bfe7c['attributes']=_0x5bfe7c[_0x9671('0x30')][_0x9671('0x40')]?_0x5bfe7c[_0x9671('0x30')]:_0x53c8a7[_0x9671('0x31')];_0x5bfe7c['order']=qs[_0x9671('0x35')](_0x29d515['query'][_0x9671('0x35')]);_0x5bfe7c['where']=qs[_0x9671('0x37')](_[_0x9671('0x38')](_0x29d515['query'],_0x53c8a7[_0x9671('0x37')]));if(_0x29d515[_0x9671('0x2d')][_0x9671('0x39')]){_0x5bfe7c[_0x9671('0x36')]=_[_0x9671('0x3b')](_0x5bfe7c[_0x9671('0x36')],{'$or':_[_0x9671('0x2a')](_0x5bfe7c[_0x9671('0x30')],function(_0x5d8868){var _0x3e0bc8={};_0x3e0bc8[_0x5d8868]={'$like':'%'+_0x29d515[_0x9671('0x2d')][_0x9671('0x39')]+'%'};return _0x3e0bc8;})});}_0x5bfe7c=_[_0x9671('0x3b')]({},_0x5bfe7c,_0x29d515[_0x9671('0x3c')]);return _0x23fc46[_0x9671('0x4a')](_0x5bfe7c);}})[_0x9671('0x25')](function(_0x1ef0e8){if(_0x1ef0e8){_0x552759=_0x1ef0e8[_0x9671('0x40')];if(!_0x29d515[_0x9671('0x2d')][_0x9671('0x49')](_0x9671('0x33'))){_0x5bfe7c['limit']=qs['limit'](_0x29d515['query'][_0x9671('0x1d')]);_0x5bfe7c[_0x9671('0x20')]=qs[_0x9671('0x20')](_0x29d515[_0x9671('0x2d')][_0x9671('0x20')]);}return _0x23fc46[_0x9671('0x4a')](_0x5bfe7c);}})[_0x9671('0x25')](function(_0x157c88){if(_0x157c88){return _0x157c88?{'count':_0x552759,'rows':_0x157c88}:null;}})[_0x9671('0x25')](respondWithResult(_0x32ed10,null))[_0x9671('0x43')](handleError(_0x32ed10,null));};exports['getDescriptions']=function(_0x22b021,_0x4c8be6,_0x417f63){var _0xff29e3={};var _0x1f5bc9={};var _0x2cd1b3;var _0x4c58c3;return db[_0x9671('0x2b')]['findOne']({'where':{'id':_0x22b021[_0x9671('0x46')]['id']}})[_0x9671('0x25')](handleEntityNotFound(_0x4c8be6,null))[_0x9671('0x25')](function(_0x3bc763){if(_0x3bc763){_0x2cd1b3=_0x3bc763;_0x1f5bc9[_0x9671('0x31')]=_[_0x9671('0x2e')](db[_0x9671('0x4b')][_0x9671('0x3f')]);_0x1f5bc9[_0x9671('0x2d')]=_['keys'](_0x22b021['query']);_0x1f5bc9[_0x9671('0x37')]=_[_0x9671('0x2f')](_0x1f5bc9[_0x9671('0x31')],_0x1f5bc9[_0x9671('0x2d')]);_0xff29e3[_0x9671('0x30')]=_['intersection'](_0x1f5bc9[_0x9671('0x31')],qs[_0x9671('0x32')](_0x22b021[_0x9671('0x2d')][_0x9671('0x32')]));_0xff29e3[_0x9671('0x30')]=_0xff29e3[_0x9671('0x30')][_0x9671('0x40')]?_0xff29e3['attributes']:_0x1f5bc9['model'];_0xff29e3[_0x9671('0x34')]=qs[_0x9671('0x35')](_0x22b021[_0x9671('0x2d')][_0x9671('0x35')]);_0xff29e3[_0x9671('0x36')]=qs[_0x9671('0x37')](_[_0x9671('0x38')](_0x22b021[_0x9671('0x2d')],_0x1f5bc9[_0x9671('0x37')]));if(_0x22b021[_0x9671('0x2d')][_0x9671('0x39')]){_0xff29e3['where']=_['merge'](_0xff29e3[_0x9671('0x36')],{'$or':_[_0x9671('0x2a')](_0xff29e3[_0x9671('0x30')],function(_0xe6275c){var _0x5232e5={};_0x5232e5[_0xe6275c]={'$like':'%'+_0x22b021[_0x9671('0x2d')][_0x9671('0x39')]+'%'};return _0x5232e5;})});}_0xff29e3=_[_0x9671('0x3b')]({},_0xff29e3,_0x22b021[_0x9671('0x3c')]);return _0x2cd1b3['getDescriptions'](_0xff29e3);}})[_0x9671('0x25')](function(_0x2c1725){if(_0x2c1725){_0x4c58c3=_0x2c1725['length'];if(!_0x22b021[_0x9671('0x2d')]['hasOwnProperty'](_0x9671('0x33'))){_0xff29e3[_0x9671('0x1d')]=qs['limit'](_0x22b021[_0x9671('0x2d')][_0x9671('0x1d')]);_0xff29e3[_0x9671('0x20')]=qs[_0x9671('0x20')](_0x22b021[_0x9671('0x2d')][_0x9671('0x20')]);}return _0x2cd1b3[_0x9671('0x4c')](_0xff29e3);}})['then'](function(_0x39644a){if(_0x39644a){return _0x39644a?{'count':_0x4c58c3,'rows':_0x39644a}:null;}})[_0x9671('0x25')](respondWithResult(_0x4c8be6,null))[_0x9671('0x43')](handleError(_0x4c8be6,null));};