Built motion from commit (unavailable).|2.5.26
[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 _0x996b=['model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL','options','include','findAll','rows','show','params','keys','length','includeAll','find','create','update','body','getFields','findOne','VtigerField','getSubjects','order','getDescriptions','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','api','../../mysqldb','jayson/promise','client','http','then','info','VtigerConfiguration,\x20%s,\x20%s','request\x20sent','debug','stringify','error','message','result','catch','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','destroy','stack','name','index','map','VtigerConfiguration','rawAttributes','fieldName','type'];(function(_0x2f2a6f,_0xe63e10){var _0x14441d=function(_0x3ab031){while(--_0x3ab031){_0x2f2a6f['push'](_0x2f2a6f['shift']());}};_0x14441d(++_0xe63e10);}(_0x996b,0xd1));var _0xb996=function(_0x13bf33,_0x45e23f){_0x13bf33=_0x13bf33-0x0;var _0x55d062=_0x996b[_0x13bf33];return _0x55d062;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb996('0x0'));var zipdir=require(_0xb996('0x1'));var jsonpatch=require(_0xb996('0x2'));var rp=require(_0xb996('0x3'));var moment=require('moment');var BPromise=require(_0xb996('0x4'));var Mustache=require(_0xb996('0x5'));var util=require(_0xb996('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0xb996('0x7'));var ejs=require(_0xb996('0x8'));var fs=require('fs');var fs_extra=require(_0xb996('0x9'));var _=require(_0xb996('0xa'));var squel=require(_0xb996('0xb'));var crypto=require(_0xb996('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xb996('0xd'));var toCsv=require(_0xb996('0x7'));var querystring=require(_0xb996('0xe'));var Papa=require(_0xb996('0xf'));var Redis=require(_0xb996('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xb996('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb996('0x12'));var logger=require('../../config/logger')(_0xb996('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xb996('0x14'))['db'];var jayson=require(_0xb996('0x15'));var client=jayson[_0xb996('0x16')][_0xb996('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x3c1918,_0x3167c1,_0x18b9d9,_0x450f61){return new BPromise(function(_0x2d4f33,_0x1d30a1){var _0x46ae56=_0x450f61||client;return _0x46ae56['request'](_0x3c1918,_0x18b9d9)[_0xb996('0x18')](function(_0x3b46f1){logger[_0xb996('0x19')](_0xb996('0x1a'),_0x3167c1,_0xb996('0x1b'));logger[_0xb996('0x1c')]('VtigerConfiguration,\x20%s,\x20%s,\x20%s',_0x3167c1,_0xb996('0x1b'),JSON[_0xb996('0x1d')](_0x3b46f1));if(_0x3b46f1[_0xb996('0x1e')]){if(_0x3b46f1[_0xb996('0x1e')]['code']===0x1f4){logger[_0xb996('0x1e')](_0xb996('0x1a'),_0x3167c1,_0x3b46f1[_0xb996('0x1e')][_0xb996('0x1f')]);return _0x1d30a1(_0x3b46f1[_0xb996('0x1e')]['message']);}logger[_0xb996('0x1e')]('VtigerConfiguration,\x20%s,\x20%s',_0x3167c1,_0x3b46f1[_0xb996('0x1e')]['message']);return _0x2d4f33(_0x3b46f1[_0xb996('0x1e')]['message']);}else{logger[_0xb996('0x19')](_0xb996('0x1a'),_0x3167c1,_0xb996('0x1b'));_0x2d4f33(_0x3b46f1[_0xb996('0x20')][_0xb996('0x1f')]);}})[_0xb996('0x21')](function(_0x27bd9a){logger[_0xb996('0x1e')]('VtigerConfiguration,\x20%s,\x20%s',_0x3167c1,_0x27bd9a);_0x1d30a1(_0x27bd9a);});});}function respondWithStatusCode(_0x29e3d3,_0x1a672a){_0x1a672a=_0x1a672a||0xcc;return function(_0x180ab9){if(_0x180ab9){return _0x29e3d3[_0xb996('0x22')](_0x1a672a);}return _0x29e3d3['status'](_0x1a672a)[_0xb996('0x23')]();};}function respondWithResult(_0x535218,_0x1a059d){_0x1a059d=_0x1a059d||0xc8;return function(_0x238009){if(_0x238009){return _0x535218[_0xb996('0x24')](_0x1a059d)[_0xb996('0x25')](_0x238009);}};}function respondWithFilteredResult(_0x4c6573,_0x540a51){return function(_0x370b32){if(_0x370b32){var _0x5dd8ec=_0x370b32[_0xb996('0x26')],_0x4bc1f4=_0x540a51['offset'],_0x1859e7=_0x540a51[_0xb996('0x27')]+_0x540a51[_0xb996('0x28')],_0x26ecb7;if(_0x1859e7>=_0x5dd8ec){_0x1859e7=_0x5dd8ec;_0x26ecb7=0xc8;}else{_0x26ecb7=0xce;}_0x4c6573['status'](_0x26ecb7);return _0x4c6573[_0xb996('0x29')](_0xb996('0x2a'),_0x4bc1f4+'-'+_0x1859e7+'/'+_0x5dd8ec)[_0xb996('0x25')](_0x370b32);}return null;};}function patchUpdates(_0x78cc03){return function(_0x1876c2){try{jsonpatch[_0xb996('0x2b')](_0x1876c2,_0x78cc03,!![]);}catch(_0x457e19){return BPromise[_0xb996('0x2c')](_0x457e19);}return _0x1876c2[_0xb996('0x2d')]();};}function saveUpdates(_0xe4b7a6,_0xd8ccac){return function(_0x46cce8){if(_0x46cce8){return _0x46cce8['update'](_0xe4b7a6)[_0xb996('0x18')](function(_0x144472){return _0x144472;});}return null;};}function removeEntity(_0x1ce1ed,_0x9d1fde){return function(_0x573594){if(_0x573594){return _0x573594[_0xb996('0x2e')]()[_0xb996('0x18')](function(){_0x1ce1ed[_0xb996('0x24')](0xcc)['end']();});}};}function handleEntityNotFound(_0x234a40,_0x4ac440){return function(_0x217563){if(!_0x217563){_0x234a40[_0xb996('0x22')](0x194);}return _0x217563;};}function handleError(_0x16a63e,_0x5aee64){_0x5aee64=_0x5aee64||0x1f4;return function(_0x305a55){logger[_0xb996('0x1e')](_0x305a55[_0xb996('0x2f')]);if(_0x305a55[_0xb996('0x30')]){delete _0x305a55[_0xb996('0x30')];}_0x16a63e[_0xb996('0x24')](_0x5aee64)['send'](_0x305a55);};}exports[_0xb996('0x31')]=function(_0x220617,_0x4ef6d6){var _0x294953={},_0x4d059a={},_0x9e73c2={'count':0x0,'rows':[]};var _0x57ca54=_[_0xb996('0x32')](db[_0xb996('0x33')][_0xb996('0x34')],function(_0x29fca5){return{'name':_0x29fca5[_0xb996('0x35')],'type':_0x29fca5[_0xb996('0x36')]['key']};});_0x4d059a[_0xb996('0x37')]=_[_0xb996('0x32')](_0x57ca54,_0xb996('0x30'));_0x4d059a[_0xb996('0x38')]=_['keys'](_0x220617[_0xb996('0x38')]);_0x4d059a[_0xb996('0x39')]=_[_0xb996('0x3a')](_0x4d059a[_0xb996('0x37')],_0x4d059a[_0xb996('0x38')]);_0x294953[_0xb996('0x3b')]=_[_0xb996('0x3a')](_0x4d059a[_0xb996('0x37')],qs[_0xb996('0x3c')](_0x220617['query'][_0xb996('0x3c')]));_0x294953[_0xb996('0x3b')]=_0x294953[_0xb996('0x3b')]['length']?_0x294953[_0xb996('0x3b')]:_0x4d059a[_0xb996('0x37')];if(!_0x220617[_0xb996('0x38')][_0xb996('0x3d')](_0xb996('0x3e'))){_0x294953['limit']=qs[_0xb996('0x28')](_0x220617[_0xb996('0x38')][_0xb996('0x28')]);_0x294953['offset']=qs[_0xb996('0x27')](_0x220617[_0xb996('0x38')]['offset']);}_0x294953['order']=qs['sort'](_0x220617[_0xb996('0x38')][_0xb996('0x3f')]);_0x294953['where']=qs[_0xb996('0x39')](_[_0xb996('0x40')](_0x220617[_0xb996('0x38')],_0x4d059a[_0xb996('0x39')]),_0x57ca54);if(_0x220617[_0xb996('0x38')][_0xb996('0x41')]){_0x294953[_0xb996('0x42')]=_[_0xb996('0x43')](_0x294953[_0xb996('0x42')],{'$or':_[_0xb996('0x32')](_0x57ca54,function(_0x1e88be){if(_0x1e88be[_0xb996('0x36')]!==_0xb996('0x44')){var _0x523c78={};_0x523c78[_0x1e88be[_0xb996('0x30')]]={'$like':'%'+_0x220617[_0xb996('0x38')]['filter']+'%'};return _0x523c78;}})});}_0x294953=_[_0xb996('0x43')]({},_0x294953,_0x220617[_0xb996('0x45')]);var _0x2278fc={'where':_0x294953['where']};return db[_0xb996('0x33')][_0xb996('0x26')](_0x2278fc)[_0xb996('0x18')](function(_0x4b586f){_0x9e73c2[_0xb996('0x26')]=_0x4b586f;if(_0x220617[_0xb996('0x38')]['includeAll']){_0x294953[_0xb996('0x46')]=[{'all':!![]}];}return db[_0xb996('0x33')][_0xb996('0x47')](_0x294953);})[_0xb996('0x18')](function(_0x3d13a1){_0x9e73c2[_0xb996('0x48')]=_0x3d13a1;return _0x9e73c2;})['then'](respondWithFilteredResult(_0x4ef6d6,_0x294953))['catch'](handleError(_0x4ef6d6,null));};exports[_0xb996('0x49')]=function(_0x295a6f,_0x4bbd91){var _0x2e1149={'raw':![],'where':{'id':_0x295a6f[_0xb996('0x4a')]['id']}},_0x4ea054={};_0x4ea054['model']=_['keys'](db[_0xb996('0x33')][_0xb996('0x34')]);_0x4ea054[_0xb996('0x38')]=_[_0xb996('0x4b')](_0x295a6f[_0xb996('0x38')]);_0x4ea054[_0xb996('0x39')]=_['intersection'](_0x4ea054[_0xb996('0x37')],_0x4ea054[_0xb996('0x38')]);_0x2e1149[_0xb996('0x3b')]=_[_0xb996('0x3a')](_0x4ea054[_0xb996('0x37')],qs[_0xb996('0x3c')](_0x295a6f[_0xb996('0x38')][_0xb996('0x3c')]));_0x2e1149['attributes']=_0x2e1149[_0xb996('0x3b')][_0xb996('0x4c')]?_0x2e1149['attributes']:_0x4ea054[_0xb996('0x37')];if(_0x295a6f[_0xb996('0x38')][_0xb996('0x4d')]){_0x2e1149[_0xb996('0x46')]=[{'all':!![]}];}_0x2e1149=_[_0xb996('0x43')]({},_0x2e1149,_0x295a6f[_0xb996('0x45')]);return db[_0xb996('0x33')][_0xb996('0x4e')](_0x2e1149)[_0xb996('0x18')](handleEntityNotFound(_0x4bbd91,null))[_0xb996('0x18')](respondWithResult(_0x4bbd91,null))[_0xb996('0x21')](handleError(_0x4bbd91,null));};exports['create']=function(_0x48f2c6,_0x343360){return db[_0xb996('0x33')][_0xb996('0x4f')](_0x48f2c6['body'],{})[_0xb996('0x18')](respondWithResult(_0x343360,0xc9))['catch'](handleError(_0x343360,null));};exports[_0xb996('0x50')]=function(_0x2d8886,_0x7650e3){if(_0x2d8886['body']['id']){delete _0x2d8886[_0xb996('0x51')]['id'];}return db['VtigerConfiguration'][_0xb996('0x4e')]({'where':{'id':_0x2d8886['params']['id']}})[_0xb996('0x18')](handleEntityNotFound(_0x7650e3,null))['then'](saveUpdates(_0x2d8886[_0xb996('0x51')],null))[_0xb996('0x18')](respondWithResult(_0x7650e3,null))[_0xb996('0x21')](handleError(_0x7650e3,null));};exports['destroy']=function(_0x25bec7,_0x2f724c){return db[_0xb996('0x33')][_0xb996('0x4e')]({'where':{'id':_0x25bec7[_0xb996('0x4a')]['id']}})['then'](handleEntityNotFound(_0x2f724c,null))['then'](removeEntity(_0x2f724c,null))[_0xb996('0x21')](handleError(_0x2f724c,null));};exports[_0xb996('0x52')]=function(_0x4710e0,_0x4cf036,_0x24d558){var _0x2aa551={};var _0x34421b={};var _0x259288;var _0x38dbd4;return db[_0xb996('0x33')][_0xb996('0x53')]({'where':{'id':_0x4710e0[_0xb996('0x4a')]['id']}})[_0xb996('0x18')](handleEntityNotFound(_0x4cf036,null))[_0xb996('0x18')](function(_0x4f9abe){if(_0x4f9abe){_0x259288=_0x4f9abe;_0x34421b[_0xb996('0x37')]=_['keys'](db[_0xb996('0x54')][_0xb996('0x34')]);_0x34421b['query']=_[_0xb996('0x4b')](_0x4710e0['query']);_0x34421b[_0xb996('0x39')]=_['intersection'](_0x34421b[_0xb996('0x37')],_0x34421b[_0xb996('0x38')]);_0x2aa551['attributes']=_['intersection'](_0x34421b[_0xb996('0x37')],qs['fields'](_0x4710e0['query'][_0xb996('0x3c')]));_0x2aa551[_0xb996('0x3b')]=_0x2aa551[_0xb996('0x3b')][_0xb996('0x4c')]?_0x2aa551[_0xb996('0x3b')]:_0x34421b[_0xb996('0x37')];_0x2aa551['order']=qs[_0xb996('0x3f')](_0x4710e0[_0xb996('0x38')][_0xb996('0x3f')]);_0x2aa551[_0xb996('0x42')]=qs[_0xb996('0x39')](_[_0xb996('0x40')](_0x4710e0[_0xb996('0x38')],_0x34421b[_0xb996('0x39')]));if(_0x4710e0[_0xb996('0x38')][_0xb996('0x41')]){_0x2aa551[_0xb996('0x42')]=_[_0xb996('0x43')](_0x2aa551[_0xb996('0x42')],{'$or':_['map'](_0x2aa551[_0xb996('0x3b')],function(_0x5d3416){var _0x54b476={};_0x54b476[_0x5d3416]={'$like':'%'+_0x4710e0[_0xb996('0x38')]['filter']+'%'};return _0x54b476;})});}_0x2aa551=_[_0xb996('0x43')]({},_0x2aa551,_0x4710e0['options']);return _0x259288[_0xb996('0x52')](_0x2aa551);}})[_0xb996('0x18')](function(_0x308f18){if(_0x308f18){_0x38dbd4=_0x308f18[_0xb996('0x4c')];if(!_0x4710e0[_0xb996('0x38')][_0xb996('0x3d')](_0xb996('0x3e'))){_0x2aa551[_0xb996('0x28')]=qs[_0xb996('0x28')](_0x4710e0[_0xb996('0x38')][_0xb996('0x28')]);_0x2aa551[_0xb996('0x27')]=qs[_0xb996('0x27')](_0x4710e0[_0xb996('0x38')]['offset']);}return _0x259288[_0xb996('0x52')](_0x2aa551);}})[_0xb996('0x18')](function(_0x16bc8b){if(_0x16bc8b){return _0x16bc8b?{'count':_0x38dbd4,'rows':_0x16bc8b}:null;}})[_0xb996('0x18')](respondWithResult(_0x4cf036,null))[_0xb996('0x21')](handleError(_0x4cf036,null));};exports[_0xb996('0x55')]=function(_0x5039ce,_0x28cc07,_0x6bd5b4){var _0x4cf9bc={};var _0x235dfe={};var _0x445657;var _0x274bfb;return db[_0xb996('0x33')]['findOne']({'where':{'id':_0x5039ce[_0xb996('0x4a')]['id']}})[_0xb996('0x18')](handleEntityNotFound(_0x28cc07,null))[_0xb996('0x18')](function(_0x2853ed){if(_0x2853ed){_0x445657=_0x2853ed;_0x235dfe['model']=_[_0xb996('0x4b')](db['VtigerField'][_0xb996('0x34')]);_0x235dfe['query']=_['keys'](_0x5039ce[_0xb996('0x38')]);_0x235dfe[_0xb996('0x39')]=_['intersection'](_0x235dfe['model'],_0x235dfe[_0xb996('0x38')]);_0x4cf9bc[_0xb996('0x3b')]=_[_0xb996('0x3a')](_0x235dfe[_0xb996('0x37')],qs[_0xb996('0x3c')](_0x5039ce[_0xb996('0x38')][_0xb996('0x3c')]));_0x4cf9bc['attributes']=_0x4cf9bc[_0xb996('0x3b')][_0xb996('0x4c')]?_0x4cf9bc['attributes']:_0x235dfe[_0xb996('0x37')];_0x4cf9bc['order']=qs[_0xb996('0x3f')](_0x5039ce['query']['sort']);_0x4cf9bc['where']=qs[_0xb996('0x39')](_['pick'](_0x5039ce[_0xb996('0x38')],_0x235dfe[_0xb996('0x39')]));if(_0x5039ce[_0xb996('0x38')]['filter']){_0x4cf9bc[_0xb996('0x42')]=_['merge'](_0x4cf9bc['where'],{'$or':_[_0xb996('0x32')](_0x4cf9bc[_0xb996('0x3b')],function(_0x29b0d9){var _0x4d02da={};_0x4d02da[_0x29b0d9]={'$like':'%'+_0x5039ce[_0xb996('0x38')]['filter']+'%'};return _0x4d02da;})});}_0x4cf9bc=_['merge']({},_0x4cf9bc,_0x5039ce[_0xb996('0x45')]);return _0x445657[_0xb996('0x55')](_0x4cf9bc);}})[_0xb996('0x18')](function(_0x2faca5){if(_0x2faca5){_0x274bfb=_0x2faca5[_0xb996('0x4c')];if(!_0x5039ce[_0xb996('0x38')]['hasOwnProperty']('nolimit')){_0x4cf9bc[_0xb996('0x28')]=qs[_0xb996('0x28')](_0x5039ce[_0xb996('0x38')][_0xb996('0x28')]);_0x4cf9bc[_0xb996('0x27')]=qs[_0xb996('0x27')](_0x5039ce[_0xb996('0x38')][_0xb996('0x27')]);}return _0x445657[_0xb996('0x55')](_0x4cf9bc);}})[_0xb996('0x18')](function(_0x2c18e2){if(_0x2c18e2){return _0x2c18e2?{'count':_0x274bfb,'rows':_0x2c18e2}:null;}})[_0xb996('0x18')](respondWithResult(_0x28cc07,null))[_0xb996('0x21')](handleError(_0x28cc07,null));};exports['getDescriptions']=function(_0x5a6f17,_0xed9e3c,_0x25a178){var _0x3cf93b={};var _0x98bc87={};var _0xbeb841;var _0x2e8fa7;return db[_0xb996('0x33')][_0xb996('0x53')]({'where':{'id':_0x5a6f17[_0xb996('0x4a')]['id']}})[_0xb996('0x18')](handleEntityNotFound(_0xed9e3c,null))[_0xb996('0x18')](function(_0x57516b){if(_0x57516b){_0xbeb841=_0x57516b;_0x98bc87[_0xb996('0x37')]=_[_0xb996('0x4b')](db[_0xb996('0x54')][_0xb996('0x34')]);_0x98bc87[_0xb996('0x38')]=_[_0xb996('0x4b')](_0x5a6f17[_0xb996('0x38')]);_0x98bc87[_0xb996('0x39')]=_['intersection'](_0x98bc87[_0xb996('0x37')],_0x98bc87['query']);_0x3cf93b[_0xb996('0x3b')]=_[_0xb996('0x3a')](_0x98bc87[_0xb996('0x37')],qs[_0xb996('0x3c')](_0x5a6f17[_0xb996('0x38')][_0xb996('0x3c')]));_0x3cf93b[_0xb996('0x3b')]=_0x3cf93b[_0xb996('0x3b')][_0xb996('0x4c')]?_0x3cf93b[_0xb996('0x3b')]:_0x98bc87['model'];_0x3cf93b[_0xb996('0x56')]=qs[_0xb996('0x3f')](_0x5a6f17[_0xb996('0x38')][_0xb996('0x3f')]);_0x3cf93b[_0xb996('0x42')]=qs[_0xb996('0x39')](_[_0xb996('0x40')](_0x5a6f17[_0xb996('0x38')],_0x98bc87[_0xb996('0x39')]));if(_0x5a6f17[_0xb996('0x38')][_0xb996('0x41')]){_0x3cf93b['where']=_[_0xb996('0x43')](_0x3cf93b[_0xb996('0x42')],{'$or':_[_0xb996('0x32')](_0x3cf93b[_0xb996('0x3b')],function(_0x5e89ab){var _0x968620={};_0x968620[_0x5e89ab]={'$like':'%'+_0x5a6f17[_0xb996('0x38')][_0xb996('0x41')]+'%'};return _0x968620;})});}_0x3cf93b=_['merge']({},_0x3cf93b,_0x5a6f17[_0xb996('0x45')]);return _0xbeb841[_0xb996('0x57')](_0x3cf93b);}})[_0xb996('0x18')](function(_0x2ac54){if(_0x2ac54){_0x2e8fa7=_0x2ac54['length'];if(!_0x5a6f17[_0xb996('0x38')][_0xb996('0x3d')](_0xb996('0x3e'))){_0x3cf93b[_0xb996('0x28')]=qs[_0xb996('0x28')](_0x5a6f17[_0xb996('0x38')]['limit']);_0x3cf93b[_0xb996('0x27')]=qs['offset'](_0x5a6f17[_0xb996('0x38')][_0xb996('0x27')]);}return _0xbeb841[_0xb996('0x57')](_0x3cf93b);}})[_0xb996('0x18')](function(_0x1ebc92){if(_0x1ebc92){return _0x1ebc92?{'count':_0x2e8fa7,'rows':_0x1ebc92}:null;}})['then'](respondWithResult(_0xed9e3c,null))[_0xb996('0x21')](handleError(_0xed9e3c,null));};