Built motion from commit 9d1906d1.|2.5.40
[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 _0x79bb=['nolimit','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','find','create','body','params','eml-format','rimraf','request-promise','moment','bluebird','path','ejs','fs-extra','lodash','squel','crypto','desk.js','to-csv','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','status','end','json','offset','limit','count','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','SalesforceField','rawAttributes','fieldName','type','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty'];(function(_0x3ad737,_0x300131){var _0x16c1e2=function(_0x4c64fe){while(--_0x4c64fe){_0x3ad737['push'](_0x3ad737['shift']());}};_0x16c1e2(++_0x300131);}(_0x79bb,0x9b));var _0xb79b=function(_0x17c79a,_0xdbfd12){_0x17c79a=_0x17c79a-0x0;var _0x396d69=_0x79bb[_0x17c79a];return _0x396d69;};'use strict';var emlformat=require(_0xb79b('0x0'));var rimraf=require(_0xb79b('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xb79b('0x2'));var moment=require(_0xb79b('0x3'));var BPromise=require(_0xb79b('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0xb79b('0x5'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xb79b('0x6'));var fs=require('fs');var fs_extra=require(_0xb79b('0x7'));var _=require(_0xb79b('0x8'));var squel=require(_0xb79b('0x9'));var crypto=require(_0xb79b('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xb79b('0xb'));var toCsv=require(_0xb79b('0xc'));var querystring=require('querystring');var Papa=require(_0xb79b('0xd'));var Redis=require('ioredis');var authService=require(_0xb79b('0xe'));var qs=require(_0xb79b('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb79b('0x10'));var logger=require(_0xb79b('0x11'))('api');var utils=require('../../config/utils');var config=require(_0xb79b('0x12'));var licenseUtil=require('../../config/license/util');var db=require(_0xb79b('0x13'))['db'];function respondWithStatusCode(_0x120842,_0x50cc04){_0x50cc04=_0x50cc04||0xcc;return function(_0x550a47){if(_0x550a47){return _0x120842['sendStatus'](_0x50cc04);}return _0x120842[_0xb79b('0x14')](_0x50cc04)[_0xb79b('0x15')]();};}function respondWithResult(_0x57096d,_0x2abe35){_0x2abe35=_0x2abe35||0xc8;return function(_0x441e56){if(_0x441e56){return _0x57096d[_0xb79b('0x14')](_0x2abe35)[_0xb79b('0x16')](_0x441e56);}};}function respondWithFilteredResult(_0x4617fb,_0x2f160b){return function(_0xfeb1af){if(_0xfeb1af){var _0x346e87=typeof _0x2f160b[_0xb79b('0x17')]==='undefined'&&typeof _0x2f160b[_0xb79b('0x18')]==='undefined';var _0x35a2ae=_0xfeb1af['count'];var _0x575917=_0x346e87?0x0:_0x2f160b[_0xb79b('0x17')];var _0x50aa01=_0x346e87?_0xfeb1af[_0xb79b('0x19')]:_0x2f160b[_0xb79b('0x17')]+_0x2f160b['limit'];var _0x4ad336;if(_0x50aa01>=_0x35a2ae){_0x50aa01=_0x35a2ae;_0x4ad336=0xc8;}else{_0x4ad336=0xce;}_0x4617fb[_0xb79b('0x14')](_0x4ad336);return _0x4617fb['set']('Content-Range',_0x575917+'-'+_0x50aa01+'/'+_0x35a2ae)[_0xb79b('0x16')](_0xfeb1af);}return null;};}function patchUpdates(_0x146d50){return function(_0x16429c){try{jsonpatch[_0xb79b('0x1a')](_0x16429c,_0x146d50,!![]);}catch(_0x5baa72){return BPromise[_0xb79b('0x1b')](_0x5baa72);}return _0x16429c[_0xb79b('0x1c')]();};}function saveUpdates(_0x1be03c,_0xea073d){return function(_0x4a40ed){if(_0x4a40ed){return _0x4a40ed[_0xb79b('0x1d')](_0x1be03c)[_0xb79b('0x1e')](function(_0x4c97f7){return _0x4c97f7;});}return null;};}function removeEntity(_0x227330,_0xe8a890){return function(_0x305c74){if(_0x305c74){return _0x305c74[_0xb79b('0x1f')]()['then'](function(){_0x227330[_0xb79b('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0x492074,_0xd50f50){return function(_0x562e66){if(!_0x562e66){_0x492074[_0xb79b('0x20')](0x194);}return _0x562e66;};}function handleError(_0x40c0ae,_0x311a5c){_0x311a5c=_0x311a5c||0x1f4;return function(_0x18df57){logger[_0xb79b('0x21')](_0x18df57[_0xb79b('0x22')]);if(_0x18df57[_0xb79b('0x23')]){delete _0x18df57[_0xb79b('0x23')];}_0x40c0ae[_0xb79b('0x14')](_0x311a5c)[_0xb79b('0x24')](_0x18df57);};}exports[_0xb79b('0x25')]=function(_0x5d5c3c,_0x41fa15){var _0x88bf74={},_0x11dbe8={},_0x3b82ee={'count':0x0,'rows':[]};var _0x494ef2=_[_0xb79b('0x26')](db[_0xb79b('0x27')][_0xb79b('0x28')],function(_0x40300d){return{'name':_0x40300d[_0xb79b('0x29')],'type':_0x40300d[_0xb79b('0x2a')]['key']};});_0x11dbe8['model']=_[_0xb79b('0x26')](_0x494ef2,_0xb79b('0x23'));_0x11dbe8['query']=_[_0xb79b('0x2b')](_0x5d5c3c[_0xb79b('0x2c')]);_0x11dbe8[_0xb79b('0x2d')]=_[_0xb79b('0x2e')](_0x11dbe8[_0xb79b('0x2f')],_0x11dbe8['query']);_0x88bf74[_0xb79b('0x30')]=_[_0xb79b('0x2e')](_0x11dbe8[_0xb79b('0x2f')],qs[_0xb79b('0x31')](_0x5d5c3c['query'][_0xb79b('0x31')]));_0x88bf74['attributes']=_0x88bf74['attributes'][_0xb79b('0x32')]?_0x88bf74[_0xb79b('0x30')]:_0x11dbe8['model'];if(!_0x5d5c3c[_0xb79b('0x2c')][_0xb79b('0x33')](_0xb79b('0x34'))){_0x88bf74[_0xb79b('0x18')]=qs['limit'](_0x5d5c3c[_0xb79b('0x2c')][_0xb79b('0x18')]);_0x88bf74[_0xb79b('0x17')]=qs[_0xb79b('0x17')](_0x5d5c3c['query'][_0xb79b('0x17')]);}_0x88bf74['order']=qs[_0xb79b('0x35')](_0x5d5c3c[_0xb79b('0x2c')][_0xb79b('0x35')]);_0x88bf74[_0xb79b('0x36')]=qs[_0xb79b('0x2d')](_['pick'](_0x5d5c3c[_0xb79b('0x2c')],_0x11dbe8[_0xb79b('0x2d')]),_0x494ef2);if(_0x5d5c3c[_0xb79b('0x2c')][_0xb79b('0x37')]){_0x88bf74['where']=_[_0xb79b('0x38')](_0x88bf74['where'],{'$or':_['map'](_0x494ef2,function(_0x2aa4f9){if(_0x2aa4f9['type']!==_0xb79b('0x39')){var _0x418951={};_0x418951[_0x2aa4f9[_0xb79b('0x23')]]={'$like':'%'+_0x5d5c3c[_0xb79b('0x2c')]['filter']+'%'};return _0x418951;}})});}_0x88bf74=_[_0xb79b('0x38')]({},_0x88bf74,_0x5d5c3c[_0xb79b('0x3a')]);var _0x4c4e0f={'where':_0x88bf74['where']};return db[_0xb79b('0x27')]['count'](_0x4c4e0f)['then'](function(_0x64f09e){_0x3b82ee[_0xb79b('0x19')]=_0x64f09e;if(_0x5d5c3c[_0xb79b('0x2c')][_0xb79b('0x3b')]){_0x88bf74[_0xb79b('0x3c')]=[{'all':!![]}];}return db[_0xb79b('0x27')][_0xb79b('0x3d')](_0x88bf74);})[_0xb79b('0x1e')](function(_0x29f722){_0x3b82ee[_0xb79b('0x3e')]=_0x29f722;return _0x3b82ee;})[_0xb79b('0x1e')](respondWithFilteredResult(_0x41fa15,_0x88bf74))[_0xb79b('0x3f')](handleError(_0x41fa15,null));};exports[_0xb79b('0x40')]=function(_0x43c252,_0x21b7be){var _0x552e2c={'raw':!![],'where':{'id':_0x43c252['params']['id']}},_0x2a89c2={};_0x2a89c2[_0xb79b('0x2f')]=_['keys'](db[_0xb79b('0x27')]['rawAttributes']);_0x2a89c2[_0xb79b('0x2c')]=_[_0xb79b('0x2b')](_0x43c252[_0xb79b('0x2c')]);_0x2a89c2[_0xb79b('0x2d')]=_['intersection'](_0x2a89c2[_0xb79b('0x2f')],_0x2a89c2[_0xb79b('0x2c')]);_0x552e2c[_0xb79b('0x30')]=_['intersection'](_0x2a89c2[_0xb79b('0x2f')],qs[_0xb79b('0x31')](_0x43c252[_0xb79b('0x2c')][_0xb79b('0x31')]));_0x552e2c['attributes']=_0x552e2c['attributes']['length']?_0x552e2c[_0xb79b('0x30')]:_0x2a89c2[_0xb79b('0x2f')];if(_0x43c252[_0xb79b('0x2c')][_0xb79b('0x3b')]){_0x552e2c[_0xb79b('0x3c')]=[{'all':!![]}];}_0x552e2c=_[_0xb79b('0x38')]({},_0x552e2c,_0x43c252[_0xb79b('0x3a')]);return db[_0xb79b('0x27')][_0xb79b('0x41')](_0x552e2c)[_0xb79b('0x1e')](handleEntityNotFound(_0x21b7be,null))[_0xb79b('0x1e')](respondWithResult(_0x21b7be,null))[_0xb79b('0x3f')](handleError(_0x21b7be,null));};exports[_0xb79b('0x42')]=function(_0x79456f,_0x40a6bc){return db[_0xb79b('0x27')][_0xb79b('0x42')](_0x79456f[_0xb79b('0x43')],{})[_0xb79b('0x1e')](respondWithResult(_0x40a6bc,0xc9))[_0xb79b('0x3f')](handleError(_0x40a6bc,null));};exports[_0xb79b('0x1d')]=function(_0x2c9470,_0x32ccd7){if(_0x2c9470[_0xb79b('0x43')]['id']){delete _0x2c9470['body']['id'];}return db[_0xb79b('0x27')]['find']({'where':{'id':_0x2c9470[_0xb79b('0x44')]['id']}})['then'](handleEntityNotFound(_0x32ccd7,null))['then'](saveUpdates(_0x2c9470[_0xb79b('0x43')],null))[_0xb79b('0x1e')](respondWithResult(_0x32ccd7,null))['catch'](handleError(_0x32ccd7,null));};exports['destroy']=function(_0x49db64,_0x4885e2){return db['SalesforceField']['find']({'where':{'id':_0x49db64[_0xb79b('0x44')]['id']}})['then'](handleEntityNotFound(_0x4885e2,null))[_0xb79b('0x1e')](removeEntity(_0x4885e2,null))[_0xb79b('0x3f')](handleError(_0x4885e2,null));};