Built motion from commit (unavailable).|2.5.29
[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 _0xeef2=['../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','rawAttributes','key','query','keys','intersection','attributes','fields','length','model','hasOwnProperty','nolimit','order','sort','filters','where','merge','VIRTUAL','filter','SalesforceField','includeAll','catch','show','include','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service'];(function(_0x46b0ba,_0x5a767c){var _0x2e53e0=function(_0x124fb2){while(--_0x124fb2){_0x46b0ba['push'](_0x46b0ba['shift']());}};_0x2e53e0(++_0x5a767c);}(_0xeef2,0x162));var _0x2eef=function(_0x2c91e9,_0x2fb965){_0x2c91e9=_0x2c91e9-0x0;var _0x13f0ff=_0xeef2[_0x2c91e9];return _0x13f0ff;};'use strict';var emlformat=require(_0x2eef('0x0'));var rimraf=require(_0x2eef('0x1'));var zipdir=require(_0x2eef('0x2'));var jsonpatch=require(_0x2eef('0x3'));var rp=require(_0x2eef('0x4'));var moment=require(_0x2eef('0x5'));var BPromise=require(_0x2eef('0x6'));var Mustache=require('mustache');var util=require(_0x2eef('0x7'));var path=require(_0x2eef('0x8'));var sox=require(_0x2eef('0x9'));var csv=require(_0x2eef('0xa'));var ejs=require(_0x2eef('0xb'));var fs=require('fs');var fs_extra=require(_0x2eef('0xc'));var _=require(_0x2eef('0xd'));var squel=require(_0x2eef('0xe'));var crypto=require(_0x2eef('0xf'));var jsforce=require(_0x2eef('0x10'));var deskjs=require(_0x2eef('0x11'));var toCsv=require('to-csv');var querystring=require(_0x2eef('0x12'));var Papa=require(_0x2eef('0x13'));var Redis=require('ioredis');var authService=require(_0x2eef('0x14'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x2eef('0x15'))(_0x2eef('0x16'));var utils=require(_0x2eef('0x17'));var config=require(_0x2eef('0x18'));var licenseUtil=require(_0x2eef('0x19'));var db=require(_0x2eef('0x1a'))['db'];function respondWithStatusCode(_0x162933,_0x5d88c5){_0x5d88c5=_0x5d88c5||0xcc;return function(_0x1317e9){if(_0x1317e9){return _0x162933[_0x2eef('0x1b')](_0x5d88c5);}return _0x162933[_0x2eef('0x1c')](_0x5d88c5)[_0x2eef('0x1d')]();};}function respondWithResult(_0x44647e,_0x19ac6c){_0x19ac6c=_0x19ac6c||0xc8;return function(_0x2cbf79){if(_0x2cbf79){return _0x44647e[_0x2eef('0x1c')](_0x19ac6c)[_0x2eef('0x1e')](_0x2cbf79);}};}function respondWithFilteredResult(_0x48c935,_0x9e40c5){return function(_0x2a2951){if(_0x2a2951){var _0x4e9acb=typeof _0x9e40c5[_0x2eef('0x1f')]==='undefined'&&typeof _0x9e40c5[_0x2eef('0x20')]===_0x2eef('0x21');var _0x438e35=_0x2a2951[_0x2eef('0x22')];var _0xd0d80=_0x4e9acb?0x0:_0x9e40c5[_0x2eef('0x1f')];var _0x379d74=_0x4e9acb?_0x2a2951['count']:_0x9e40c5['offset']+_0x9e40c5[_0x2eef('0x20')];var _0x198517;if(_0x379d74>=_0x438e35){_0x379d74=_0x438e35;_0x198517=0xc8;}else{_0x198517=0xce;}_0x48c935[_0x2eef('0x1c')](_0x198517);return _0x48c935['set'](_0x2eef('0x23'),_0xd0d80+'-'+_0x379d74+'/'+_0x438e35)[_0x2eef('0x1e')](_0x2a2951);}return null;};}function patchUpdates(_0x7c5430){return function(_0x10f4e2){try{jsonpatch[_0x2eef('0x24')](_0x10f4e2,_0x7c5430,!![]);}catch(_0x1c546e){return BPromise[_0x2eef('0x25')](_0x1c546e);}return _0x10f4e2[_0x2eef('0x26')]();};}function saveUpdates(_0x1fa4bc,_0x563cef){return function(_0x4c8bc5){if(_0x4c8bc5){return _0x4c8bc5[_0x2eef('0x27')](_0x1fa4bc)[_0x2eef('0x28')](function(_0x5277a7){return _0x5277a7;});}return null;};}function removeEntity(_0x14ec33,_0x453431){return function(_0x2c5ed8){if(_0x2c5ed8){return _0x2c5ed8[_0x2eef('0x29')]()[_0x2eef('0x28')](function(){_0x14ec33[_0x2eef('0x1c')](0xcc)[_0x2eef('0x1d')]();});}};}function handleEntityNotFound(_0x5a7685,_0x122d12){return function(_0x13efb5){if(!_0x13efb5){_0x5a7685['sendStatus'](0x194);}return _0x13efb5;};}function handleError(_0x397896,_0xd5eb1a){_0xd5eb1a=_0xd5eb1a||0x1f4;return function(_0x7ec6c0){logger[_0x2eef('0x2a')](_0x7ec6c0[_0x2eef('0x2b')]);if(_0x7ec6c0[_0x2eef('0x2c')]){delete _0x7ec6c0[_0x2eef('0x2c')];}_0x397896['status'](_0xd5eb1a)[_0x2eef('0x2d')](_0x7ec6c0);};}exports[_0x2eef('0x2e')]=function(_0x1f55d6,_0x1c7e7a){var _0x267f46={},_0x4e5dc4={},_0x452b1b={'count':0x0,'rows':[]};var _0xcdfe21=_[_0x2eef('0x2f')](db['SalesforceField'][_0x2eef('0x30')],function(_0x50b48f){return{'name':_0x50b48f['fieldName'],'type':_0x50b48f['type'][_0x2eef('0x31')]};});_0x4e5dc4['model']=_['map'](_0xcdfe21,'name');_0x4e5dc4[_0x2eef('0x32')]=_[_0x2eef('0x33')](_0x1f55d6[_0x2eef('0x32')]);_0x4e5dc4['filters']=_[_0x2eef('0x34')](_0x4e5dc4['model'],_0x4e5dc4[_0x2eef('0x32')]);_0x267f46[_0x2eef('0x35')]=_[_0x2eef('0x34')](_0x4e5dc4['model'],qs[_0x2eef('0x36')](_0x1f55d6['query'][_0x2eef('0x36')]));_0x267f46['attributes']=_0x267f46['attributes'][_0x2eef('0x37')]?_0x267f46[_0x2eef('0x35')]:_0x4e5dc4[_0x2eef('0x38')];if(!_0x1f55d6[_0x2eef('0x32')][_0x2eef('0x39')](_0x2eef('0x3a'))){_0x267f46[_0x2eef('0x20')]=qs[_0x2eef('0x20')](_0x1f55d6[_0x2eef('0x32')][_0x2eef('0x20')]);_0x267f46[_0x2eef('0x1f')]=qs[_0x2eef('0x1f')](_0x1f55d6['query'][_0x2eef('0x1f')]);}_0x267f46[_0x2eef('0x3b')]=qs[_0x2eef('0x3c')](_0x1f55d6[_0x2eef('0x32')][_0x2eef('0x3c')]);_0x267f46['where']=qs[_0x2eef('0x3d')](_['pick'](_0x1f55d6[_0x2eef('0x32')],_0x4e5dc4[_0x2eef('0x3d')]),_0xcdfe21);if(_0x1f55d6['query']['filter']){_0x267f46[_0x2eef('0x3e')]=_[_0x2eef('0x3f')](_0x267f46['where'],{'$or':_['map'](_0xcdfe21,function(_0x4d3dc6){if(_0x4d3dc6['type']!==_0x2eef('0x40')){var _0x59b8f8={};_0x59b8f8[_0x4d3dc6[_0x2eef('0x2c')]]={'$like':'%'+_0x1f55d6[_0x2eef('0x32')][_0x2eef('0x41')]+'%'};return _0x59b8f8;}})});}_0x267f46=_[_0x2eef('0x3f')]({},_0x267f46,_0x1f55d6['options']);var _0xecf9a0={'where':_0x267f46[_0x2eef('0x3e')]};return db[_0x2eef('0x42')][_0x2eef('0x22')](_0xecf9a0)[_0x2eef('0x28')](function(_0x20a59c){_0x452b1b[_0x2eef('0x22')]=_0x20a59c;if(_0x1f55d6['query'][_0x2eef('0x43')]){_0x267f46['include']=[{'all':!![]}];}return db[_0x2eef('0x42')]['findAll'](_0x267f46);})[_0x2eef('0x28')](function(_0x1aa377){_0x452b1b['rows']=_0x1aa377;return _0x452b1b;})[_0x2eef('0x28')](respondWithFilteredResult(_0x1c7e7a,_0x267f46))[_0x2eef('0x44')](handleError(_0x1c7e7a,null));};exports[_0x2eef('0x45')]=function(_0xacfd81,_0x426803){var _0x236ad3={'raw':!![],'where':{'id':_0xacfd81['params']['id']}},_0x363028={};_0x363028[_0x2eef('0x38')]=_[_0x2eef('0x33')](db[_0x2eef('0x42')][_0x2eef('0x30')]);_0x363028[_0x2eef('0x32')]=_[_0x2eef('0x33')](_0xacfd81[_0x2eef('0x32')]);_0x363028[_0x2eef('0x3d')]=_['intersection'](_0x363028['model'],_0x363028['query']);_0x236ad3[_0x2eef('0x35')]=_[_0x2eef('0x34')](_0x363028['model'],qs[_0x2eef('0x36')](_0xacfd81[_0x2eef('0x32')][_0x2eef('0x36')]));_0x236ad3[_0x2eef('0x35')]=_0x236ad3[_0x2eef('0x35')][_0x2eef('0x37')]?_0x236ad3[_0x2eef('0x35')]:_0x363028[_0x2eef('0x38')];if(_0xacfd81[_0x2eef('0x32')]['includeAll']){_0x236ad3[_0x2eef('0x46')]=[{'all':!![]}];}_0x236ad3=_['merge']({},_0x236ad3,_0xacfd81['options']);return db[_0x2eef('0x42')][_0x2eef('0x47')](_0x236ad3)['then'](handleEntityNotFound(_0x426803,null))[_0x2eef('0x28')](respondWithResult(_0x426803,null))['catch'](handleError(_0x426803,null));};exports[_0x2eef('0x48')]=function(_0x122319,_0x60c9d){return db[_0x2eef('0x42')][_0x2eef('0x48')](_0x122319[_0x2eef('0x49')],{})[_0x2eef('0x28')](respondWithResult(_0x60c9d,0xc9))['catch'](handleError(_0x60c9d,null));};exports[_0x2eef('0x27')]=function(_0x424c05,_0x39d23f){if(_0x424c05[_0x2eef('0x49')]['id']){delete _0x424c05[_0x2eef('0x49')]['id'];}return db['SalesforceField'][_0x2eef('0x47')]({'where':{'id':_0x424c05['params']['id']}})['then'](handleEntityNotFound(_0x39d23f,null))[_0x2eef('0x28')](saveUpdates(_0x424c05[_0x2eef('0x49')],null))['then'](respondWithResult(_0x39d23f,null))[_0x2eef('0x44')](handleError(_0x39d23f,null));};exports['destroy']=function(_0x455d50,_0x398b7c){return db['SalesforceField'][_0x2eef('0x47')]({'where':{'id':_0x455d50[_0x2eef('0x4a')]['id']}})[_0x2eef('0x28')](handleEntityNotFound(_0x398b7c,null))['then'](removeEntity(_0x398b7c,null))[_0x2eef('0x44')](handleError(_0x398b7c,null));};