a6038b8aee0468624f3fb0b84d2f2e85a2e2bed7
[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 _0xf359=['offset','limit','set','reject','save','update','then','destroy','end','error','stack','name','send','index','map','SalesforceField','rawAttributes','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','count','includeAll','include','findAll','rows','catch','show','params','keys','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status'];(function(_0x2f82e7,_0x50f448){var _0x483927=function(_0x1f9d9c){while(--_0x1f9d9c){_0x2f82e7['push'](_0x2f82e7['shift']());}};_0x483927(++_0x50f448);}(_0xf359,0xc5));var _0x9f35=function(_0x9e901d,_0x126609){_0x9e901d=_0x9e901d-0x0;var _0x37e051=_0xf359[_0x9e901d];return _0x37e051;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x9f35('0x0'));var rimraf=require(_0x9f35('0x1'));var zipdir=require(_0x9f35('0x2'));var jsonpatch=require(_0x9f35('0x3'));var rp=require(_0x9f35('0x4'));var moment=require(_0x9f35('0x5'));var BPromise=require(_0x9f35('0x6'));var Mustache=require(_0x9f35('0x7'));var util=require(_0x9f35('0x8'));var path=require(_0x9f35('0x9'));var sox=require(_0x9f35('0xa'));var csv=require('to-csv');var ejs=require(_0x9f35('0xb'));var fs=require('fs');var _=require(_0x9f35('0xc'));var squel=require(_0x9f35('0xd'));var crypto=require(_0x9f35('0xe'));var jsforce=require(_0x9f35('0xf'));var deskjs=require(_0x9f35('0x10'));var toCsv=require(_0x9f35('0x11'));var querystring=require(_0x9f35('0x12'));var Papa=require(_0x9f35('0x13'));var Redis=require('ioredis');var authService=require(_0x9f35('0x14'));var qs=require('../../components/parsers/qs');var as=require(_0x9f35('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x9f35('0x16'))(_0x9f35('0x17'));var utils=require(_0x9f35('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x9f35('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5de046,_0x4fe0e8){_0x4fe0e8=_0x4fe0e8||0xcc;return function(_0x406040){if(_0x406040){return _0x5de046[_0x9f35('0x1a')](_0x4fe0e8);}return _0x5de046[_0x9f35('0x1b')](_0x4fe0e8)['end']();};}function respondWithResult(_0x44570d,_0xbe6995){_0xbe6995=_0xbe6995||0xc8;return function(_0x12c857){if(_0x12c857){return _0x44570d['status'](_0xbe6995)['json'](_0x12c857);}};}function respondWithFilteredResult(_0xb249f0,_0x4dc467){return function(_0x23975c){if(_0x23975c){var _0x10cb89=_0x23975c['count'],_0x27ca58=_0x4dc467['offset'],_0x58be6a=_0x4dc467[_0x9f35('0x1c')]+_0x4dc467[_0x9f35('0x1d')],_0x497a02;if(_0x58be6a>=_0x10cb89){_0x58be6a=_0x10cb89;_0x497a02=0xc8;}else{_0x497a02=0xce;}_0xb249f0['status'](_0x497a02);return _0xb249f0[_0x9f35('0x1e')]('Content-Range',_0x27ca58+'-'+_0x58be6a+'/'+_0x10cb89)['json'](_0x23975c);}return null;};}function patchUpdates(_0x42c211){return function(_0x35c950){try{jsonpatch['apply'](_0x35c950,_0x42c211,!![]);}catch(_0x4bfbe9){return BPromise[_0x9f35('0x1f')](_0x4bfbe9);}return _0x35c950[_0x9f35('0x20')]();};}function saveUpdates(_0x1350c2,_0x20fe64){return function(_0x25e86d){if(_0x25e86d){return _0x25e86d[_0x9f35('0x21')](_0x1350c2)[_0x9f35('0x22')](function(_0x1b8ddc){return _0x1b8ddc;});}return null;};}function removeEntity(_0x4d7c9c,_0x169cf7){return function(_0x413b98){if(_0x413b98){return _0x413b98[_0x9f35('0x23')]()[_0x9f35('0x22')](function(){_0x4d7c9c['status'](0xcc)[_0x9f35('0x24')]();});}};}function handleEntityNotFound(_0x5de305,_0x213e65){return function(_0x19d248){if(!_0x19d248){_0x5de305[_0x9f35('0x1a')](0x194);}return _0x19d248;};}function handleError(_0x25ba25,_0x528e25){_0x528e25=_0x528e25||0x1f4;return function(_0x2e0f08){logger[_0x9f35('0x25')](_0x2e0f08[_0x9f35('0x26')]);if(_0x2e0f08[_0x9f35('0x27')]){delete _0x2e0f08['name'];}_0x25ba25['status'](_0x528e25)[_0x9f35('0x28')](_0x2e0f08);};}exports[_0x9f35('0x29')]=function(_0x75bda,_0x233a6a){var _0x30fd86={},_0x4b1872={},_0x15460d={'count':0x0,'rows':[]};var _0x3511b7=_[_0x9f35('0x2a')](db[_0x9f35('0x2b')][_0x9f35('0x2c')],function(_0x584f02){return{'name':_0x584f02['fieldName'],'type':_0x584f02[_0x9f35('0x2d')][_0x9f35('0x2e')]};});_0x4b1872[_0x9f35('0x2f')]=_[_0x9f35('0x2a')](_0x3511b7,_0x9f35('0x27'));_0x4b1872[_0x9f35('0x30')]=_['keys'](_0x75bda['query']);_0x4b1872[_0x9f35('0x31')]=_[_0x9f35('0x32')](_0x4b1872[_0x9f35('0x2f')],_0x4b1872[_0x9f35('0x30')]);_0x30fd86['attributes']=_[_0x9f35('0x32')](_0x4b1872[_0x9f35('0x2f')],qs[_0x9f35('0x33')](_0x75bda['query'][_0x9f35('0x33')]));_0x30fd86[_0x9f35('0x34')]=_0x30fd86['attributes'][_0x9f35('0x35')]?_0x30fd86[_0x9f35('0x34')]:_0x4b1872['model'];if(!_0x75bda[_0x9f35('0x30')][_0x9f35('0x36')](_0x9f35('0x37'))){_0x30fd86[_0x9f35('0x1d')]=qs[_0x9f35('0x1d')](_0x75bda['query'][_0x9f35('0x1d')]);_0x30fd86[_0x9f35('0x1c')]=qs[_0x9f35('0x1c')](_0x75bda[_0x9f35('0x30')][_0x9f35('0x1c')]);}_0x30fd86[_0x9f35('0x38')]=qs[_0x9f35('0x39')](_0x75bda[_0x9f35('0x30')]['sort']);_0x30fd86[_0x9f35('0x3a')]=qs['filters'](_[_0x9f35('0x3b')](_0x75bda[_0x9f35('0x30')],_0x4b1872[_0x9f35('0x31')]),_0x3511b7);if(_0x75bda[_0x9f35('0x30')][_0x9f35('0x3c')]){_0x30fd86[_0x9f35('0x3a')]=_['merge'](_0x30fd86[_0x9f35('0x3a')],{'$or':_[_0x9f35('0x2a')](_0x3511b7,function(_0x31b7bf){if(_0x31b7bf[_0x9f35('0x2d')]!=='VIRTUAL'){var _0x5640d2={};_0x5640d2[_0x31b7bf['name']]={'$like':'%'+_0x75bda['query'][_0x9f35('0x3c')]+'%'};return _0x5640d2;}})});}_0x30fd86=_[_0x9f35('0x3d')]({},_0x30fd86,_0x75bda[_0x9f35('0x3e')]);var _0x550084={'where':_0x30fd86['where']};return db[_0x9f35('0x2b')][_0x9f35('0x3f')](_0x550084)[_0x9f35('0x22')](function(_0x514133){_0x15460d['count']=_0x514133;if(_0x75bda[_0x9f35('0x30')][_0x9f35('0x40')]){_0x30fd86[_0x9f35('0x41')]=[{'all':!![]}];}return db['SalesforceField'][_0x9f35('0x42')](_0x30fd86);})[_0x9f35('0x22')](function(_0x213c1f){_0x15460d[_0x9f35('0x43')]=_0x213c1f;return _0x15460d;})['then'](respondWithFilteredResult(_0x233a6a,_0x30fd86))[_0x9f35('0x44')](handleError(_0x233a6a,null));};exports[_0x9f35('0x45')]=function(_0x1c8713,_0x11092d){var _0x9cfe41={'raw':!![],'where':{'id':_0x1c8713[_0x9f35('0x46')]['id']}},_0x95de65={};_0x95de65['model']=_[_0x9f35('0x47')](db[_0x9f35('0x2b')][_0x9f35('0x2c')]);_0x95de65[_0x9f35('0x30')]=_[_0x9f35('0x47')](_0x1c8713[_0x9f35('0x30')]);_0x95de65[_0x9f35('0x31')]=_[_0x9f35('0x32')](_0x95de65[_0x9f35('0x2f')],_0x95de65[_0x9f35('0x30')]);_0x9cfe41[_0x9f35('0x34')]=_['intersection'](_0x95de65[_0x9f35('0x2f')],qs[_0x9f35('0x33')](_0x1c8713[_0x9f35('0x30')]['fields']));_0x9cfe41[_0x9f35('0x34')]=_0x9cfe41[_0x9f35('0x34')]['length']?_0x9cfe41[_0x9f35('0x34')]:_0x95de65[_0x9f35('0x2f')];if(_0x1c8713['query'][_0x9f35('0x40')]){_0x9cfe41[_0x9f35('0x41')]=[{'all':!![]}];}_0x9cfe41=_[_0x9f35('0x3d')]({},_0x9cfe41,_0x1c8713['options']);return db[_0x9f35('0x2b')][_0x9f35('0x48')](_0x9cfe41)[_0x9f35('0x22')](handleEntityNotFound(_0x11092d,null))['then'](respondWithResult(_0x11092d,null))[_0x9f35('0x44')](handleError(_0x11092d,null));};exports[_0x9f35('0x49')]=function(_0x18dfef,_0x4e2adb){return db[_0x9f35('0x2b')][_0x9f35('0x49')](_0x18dfef[_0x9f35('0x4a')],{})['then'](respondWithResult(_0x4e2adb,0xc9))['catch'](handleError(_0x4e2adb,null));};exports[_0x9f35('0x21')]=function(_0x112822,_0x4d81b7){if(_0x112822[_0x9f35('0x4a')]['id']){delete _0x112822[_0x9f35('0x4a')]['id'];}return db[_0x9f35('0x2b')][_0x9f35('0x48')]({'where':{'id':_0x112822['params']['id']}})['then'](handleEntityNotFound(_0x4d81b7,null))[_0x9f35('0x22')](saveUpdates(_0x112822[_0x9f35('0x4a')],null))['then'](respondWithResult(_0x4d81b7,null))[_0x9f35('0x44')](handleError(_0x4d81b7,null));};exports[_0x9f35('0x23')]=function(_0x3e20cb,_0x476076){return db[_0x9f35('0x2b')]['find']({'where':{'id':_0x3e20cb[_0x9f35('0x46')]['id']}})[_0x9f35('0x22')](handleEntityNotFound(_0x476076,null))[_0x9f35('0x22')](removeEntity(_0x476076,null))['catch'](handleError(_0x476076,null));};