Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / intSalesforceField / intSalesforceField.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 _0x4f07=['status','end','json','offset','undefined','limit','count','Content-Range','reject','save','update','then','destroy','stack','name','send','index','map','SalesforceField','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','include','findAll','show','params','rawAttributes','find','catch','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus'];(function(_0x1ad901,_0x852d9e){var _0x3c0249=function(_0x319eda){while(--_0x319eda){_0x1ad901['push'](_0x1ad901['shift']());}};_0x3c0249(++_0x852d9e);}(_0x4f07,0xca));var _0x74f0=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0x4f07[_0x2641f9];return _0x585741;};'use strict';var emlformat=require(_0x74f0('0x0'));var rimraf=require(_0x74f0('0x1'));var zipdir=require(_0x74f0('0x2'));var jsonpatch=require(_0x74f0('0x3'));var rp=require(_0x74f0('0x4'));var moment=require(_0x74f0('0x5'));var BPromise=require(_0x74f0('0x6'));var Mustache=require(_0x74f0('0x7'));var util=require(_0x74f0('0x8'));var path=require(_0x74f0('0x9'));var sox=require(_0x74f0('0xa'));var csv=require(_0x74f0('0xb'));var ejs=require(_0x74f0('0xc'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x74f0('0xd'));var squel=require(_0x74f0('0xe'));var crypto=require(_0x74f0('0xf'));var jsforce=require(_0x74f0('0x10'));var deskjs=require(_0x74f0('0x11'));var toCsv=require(_0x74f0('0xb'));var querystring=require(_0x74f0('0x12'));var Papa=require(_0x74f0('0x13'));var Redis=require('ioredis');var authService=require(_0x74f0('0x14'));var qs=require(_0x74f0('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x74f0('0x16'));var logger=require(_0x74f0('0x17'))(_0x74f0('0x18'));var utils=require('../../config/utils');var config=require(_0x74f0('0x19'));var licenseUtil=require(_0x74f0('0x1a'));var db=require(_0x74f0('0x1b'))['db'];function respondWithStatusCode(_0x1c3d10,_0x245bf8){_0x245bf8=_0x245bf8||0xcc;return function(_0x1947ac){if(_0x1947ac){return _0x1c3d10[_0x74f0('0x1c')](_0x245bf8);}return _0x1c3d10[_0x74f0('0x1d')](_0x245bf8)[_0x74f0('0x1e')]();};}function respondWithResult(_0x46a0d0,_0xaeef11){_0xaeef11=_0xaeef11||0xc8;return function(_0x4e81a9){if(_0x4e81a9){return _0x46a0d0[_0x74f0('0x1d')](_0xaeef11)[_0x74f0('0x1f')](_0x4e81a9);}};}function respondWithFilteredResult(_0x434f32,_0x250ffb){return function(_0x348d2c){if(_0x348d2c){var _0x2ef7e3=typeof _0x250ffb[_0x74f0('0x20')]===_0x74f0('0x21')&&typeof _0x250ffb[_0x74f0('0x22')]===_0x74f0('0x21');var _0x16329f=_0x348d2c[_0x74f0('0x23')];var _0x53f4c6=_0x2ef7e3?0x0:_0x250ffb[_0x74f0('0x20')];var _0x5bf21e=_0x2ef7e3?_0x348d2c[_0x74f0('0x23')]:_0x250ffb[_0x74f0('0x20')]+_0x250ffb[_0x74f0('0x22')];var _0x4684e6;if(_0x5bf21e>=_0x16329f){_0x5bf21e=_0x16329f;_0x4684e6=0xc8;}else{_0x4684e6=0xce;}_0x434f32[_0x74f0('0x1d')](_0x4684e6);return _0x434f32['set'](_0x74f0('0x24'),_0x53f4c6+'-'+_0x5bf21e+'/'+_0x16329f)[_0x74f0('0x1f')](_0x348d2c);}return null;};}function patchUpdates(_0x5a4b3b){return function(_0x5db755){try{jsonpatch['apply'](_0x5db755,_0x5a4b3b,!![]);}catch(_0xf69ccd){return BPromise[_0x74f0('0x25')](_0xf69ccd);}return _0x5db755[_0x74f0('0x26')]();};}function saveUpdates(_0x1b0696,_0x2d442e){return function(_0x4f1d87){if(_0x4f1d87){return _0x4f1d87[_0x74f0('0x27')](_0x1b0696)[_0x74f0('0x28')](function(_0x305d19){return _0x305d19;});}return null;};}function removeEntity(_0x30a768,_0x515d83){return function(_0x3c98f3){if(_0x3c98f3){return _0x3c98f3[_0x74f0('0x29')]()[_0x74f0('0x28')](function(){_0x30a768[_0x74f0('0x1d')](0xcc)[_0x74f0('0x1e')]();});}};}function handleEntityNotFound(_0x256d79,_0x323430){return function(_0x1e8c8a){if(!_0x1e8c8a){_0x256d79[_0x74f0('0x1c')](0x194);}return _0x1e8c8a;};}function handleError(_0x39acf7,_0x23a313){_0x23a313=_0x23a313||0x1f4;return function(_0x438188){logger['error'](_0x438188[_0x74f0('0x2a')]);if(_0x438188[_0x74f0('0x2b')]){delete _0x438188[_0x74f0('0x2b')];}_0x39acf7[_0x74f0('0x1d')](_0x23a313)[_0x74f0('0x2c')](_0x438188);};}exports[_0x74f0('0x2d')]=function(_0x23d9ee,_0x39bcf7){var _0xd6735b={},_0x1775c8={},_0x32e4f0={'count':0x0,'rows':[]};var _0x1d20ae=_[_0x74f0('0x2e')](db[_0x74f0('0x2f')]['rawAttributes'],function(_0xd97ae4){return{'name':_0xd97ae4['fieldName'],'type':_0xd97ae4[_0x74f0('0x30')][_0x74f0('0x31')]};});_0x1775c8[_0x74f0('0x32')]=_[_0x74f0('0x2e')](_0x1d20ae,_0x74f0('0x2b'));_0x1775c8[_0x74f0('0x33')]=_[_0x74f0('0x34')](_0x23d9ee[_0x74f0('0x33')]);_0x1775c8[_0x74f0('0x35')]=_[_0x74f0('0x36')](_0x1775c8[_0x74f0('0x32')],_0x1775c8[_0x74f0('0x33')]);_0xd6735b['attributes']=_['intersection'](_0x1775c8[_0x74f0('0x32')],qs['fields'](_0x23d9ee[_0x74f0('0x33')][_0x74f0('0x37')]));_0xd6735b[_0x74f0('0x38')]=_0xd6735b[_0x74f0('0x38')][_0x74f0('0x39')]?_0xd6735b[_0x74f0('0x38')]:_0x1775c8[_0x74f0('0x32')];if(!_0x23d9ee[_0x74f0('0x33')][_0x74f0('0x3a')](_0x74f0('0x3b'))){_0xd6735b[_0x74f0('0x22')]=qs[_0x74f0('0x22')](_0x23d9ee[_0x74f0('0x33')][_0x74f0('0x22')]);_0xd6735b[_0x74f0('0x20')]=qs['offset'](_0x23d9ee[_0x74f0('0x33')][_0x74f0('0x20')]);}_0xd6735b[_0x74f0('0x3c')]=qs[_0x74f0('0x3d')](_0x23d9ee[_0x74f0('0x33')][_0x74f0('0x3d')]);_0xd6735b[_0x74f0('0x3e')]=qs['filters'](_[_0x74f0('0x3f')](_0x23d9ee[_0x74f0('0x33')],_0x1775c8[_0x74f0('0x35')]),_0x1d20ae);if(_0x23d9ee['query']['filter']){_0xd6735b[_0x74f0('0x3e')]=_[_0x74f0('0x40')](_0xd6735b['where'],{'$or':_[_0x74f0('0x2e')](_0x1d20ae,function(_0x401d6c){if(_0x401d6c[_0x74f0('0x30')]!==_0x74f0('0x41')){var _0x30a247={};_0x30a247[_0x401d6c[_0x74f0('0x2b')]]={'$like':'%'+_0x23d9ee[_0x74f0('0x33')][_0x74f0('0x42')]+'%'};return _0x30a247;}})});}_0xd6735b=_[_0x74f0('0x40')]({},_0xd6735b,_0x23d9ee[_0x74f0('0x43')]);var _0x55e8ea={'where':_0xd6735b['where']};return db[_0x74f0('0x2f')][_0x74f0('0x23')](_0x55e8ea)[_0x74f0('0x28')](function(_0x1376b2){_0x32e4f0[_0x74f0('0x23')]=_0x1376b2;if(_0x23d9ee[_0x74f0('0x33')]['includeAll']){_0xd6735b[_0x74f0('0x44')]=[{'all':!![]}];}return db[_0x74f0('0x2f')][_0x74f0('0x45')](_0xd6735b);})['then'](function(_0x20e776){_0x32e4f0['rows']=_0x20e776;return _0x32e4f0;})['then'](respondWithFilteredResult(_0x39bcf7,_0xd6735b))['catch'](handleError(_0x39bcf7,null));};exports[_0x74f0('0x46')]=function(_0x4acd13,_0x45e77b){var _0x2b9353={'raw':!![],'where':{'id':_0x4acd13[_0x74f0('0x47')]['id']}},_0x397c0a={};_0x397c0a[_0x74f0('0x32')]=_[_0x74f0('0x34')](db['SalesforceField'][_0x74f0('0x48')]);_0x397c0a[_0x74f0('0x33')]=_[_0x74f0('0x34')](_0x4acd13[_0x74f0('0x33')]);_0x397c0a[_0x74f0('0x35')]=_[_0x74f0('0x36')](_0x397c0a[_0x74f0('0x32')],_0x397c0a[_0x74f0('0x33')]);_0x2b9353[_0x74f0('0x38')]=_[_0x74f0('0x36')](_0x397c0a[_0x74f0('0x32')],qs[_0x74f0('0x37')](_0x4acd13[_0x74f0('0x33')]['fields']));_0x2b9353['attributes']=_0x2b9353[_0x74f0('0x38')][_0x74f0('0x39')]?_0x2b9353['attributes']:_0x397c0a['model'];if(_0x4acd13[_0x74f0('0x33')]['includeAll']){_0x2b9353[_0x74f0('0x44')]=[{'all':!![]}];}_0x2b9353=_[_0x74f0('0x40')]({},_0x2b9353,_0x4acd13['options']);return db[_0x74f0('0x2f')][_0x74f0('0x49')](_0x2b9353)['then'](handleEntityNotFound(_0x45e77b,null))['then'](respondWithResult(_0x45e77b,null))[_0x74f0('0x4a')](handleError(_0x45e77b,null));};exports['create']=function(_0x105812,_0x14f661){return db['SalesforceField'][_0x74f0('0x4b')](_0x105812['body'],{})[_0x74f0('0x28')](respondWithResult(_0x14f661,0xc9))['catch'](handleError(_0x14f661,null));};exports[_0x74f0('0x27')]=function(_0x2af1c0,_0x217c8d){if(_0x2af1c0['body']['id']){delete _0x2af1c0[_0x74f0('0x4c')]['id'];}return db[_0x74f0('0x2f')][_0x74f0('0x49')]({'where':{'id':_0x2af1c0[_0x74f0('0x47')]['id']}})[_0x74f0('0x28')](handleEntityNotFound(_0x217c8d,null))[_0x74f0('0x28')](saveUpdates(_0x2af1c0['body'],null))[_0x74f0('0x28')](respondWithResult(_0x217c8d,null))[_0x74f0('0x4a')](handleError(_0x217c8d,null));};exports[_0x74f0('0x29')]=function(_0x4f1213,_0x2fc116){return db[_0x74f0('0x2f')][_0x74f0('0x49')]({'where':{'id':_0x4f1213[_0x74f0('0x47')]['id']}})[_0x74f0('0x28')](handleEntityNotFound(_0x2fc116,null))[_0x74f0('0x28')](removeEntity(_0x2fc116,null))['catch'](handleError(_0x2fc116,null));};