Built motion from commit c116dc8b.|2.6.30
[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 _0x534f=['options','includeAll','rows','catch','show','params','rawAttributes','include','find','create','body','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','reject','update','then','stack','name','send','index','map','SalesforceField','fieldName','key','query','keys','filters','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL'];(function(_0x5dc4fb,_0x4793fb){var _0x113af4=function(_0x454b48){while(--_0x454b48){_0x5dc4fb['push'](_0x5dc4fb['shift']());}};_0x113af4(++_0x4793fb);}(_0x534f,0x127));var _0xf534=function(_0x381942,_0x5ca64b){_0x381942=_0x381942-0x0;var _0x5e8d3b=_0x534f[_0x381942];return _0x5e8d3b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf534('0x0'));var zipdir=require(_0xf534('0x1'));var jsonpatch=require(_0xf534('0x2'));var rp=require('request-promise');var moment=require(_0xf534('0x3'));var BPromise=require(_0xf534('0x4'));var Mustache=require(_0xf534('0x5'));var util=require('util');var path=require(_0xf534('0x6'));var sox=require('sox');var csv=require(_0xf534('0x7'));var ejs=require(_0xf534('0x8'));var fs=require('fs');var fs_extra=require(_0xf534('0x9'));var _=require(_0xf534('0xa'));var squel=require('squel');var crypto=require(_0xf534('0xb'));var jsforce=require(_0xf534('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xf534('0x7'));var querystring=require(_0xf534('0xd'));var Papa=require(_0xf534('0xe'));var Redis=require(_0xf534('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xf534('0x10'));var as=require(_0xf534('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xf534('0x12'));var config=require(_0xf534('0x13'));var licenseUtil=require(_0xf534('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x930efe,_0x124beb){_0x124beb=_0x124beb||0xcc;return function(_0x32cad7){if(_0x32cad7){return _0x930efe[_0xf534('0x15')](_0x124beb);}return _0x930efe[_0xf534('0x16')](_0x124beb)[_0xf534('0x17')]();};}function respondWithResult(_0x3b5f1b,_0x375b51){_0x375b51=_0x375b51||0xc8;return function(_0x1ac513){if(_0x1ac513){return _0x3b5f1b['status'](_0x375b51)[_0xf534('0x18')](_0x1ac513);}};}function respondWithFilteredResult(_0x56bdee,_0x254865){return function(_0x5ad3e8){if(_0x5ad3e8){var _0x3d42bb=typeof _0x254865[_0xf534('0x19')]===_0xf534('0x1a')&&typeof _0x254865['limit']===_0xf534('0x1a');var _0xebc09d=_0x5ad3e8['count'];var _0x16128e=_0x3d42bb?0x0:_0x254865['offset'];var _0x16659d=_0x3d42bb?_0x5ad3e8[_0xf534('0x1b')]:_0x254865['offset']+_0x254865[_0xf534('0x1c')];var _0x3820ca;if(_0x16659d>=_0xebc09d){_0x16659d=_0xebc09d;_0x3820ca=0xc8;}else{_0x3820ca=0xce;}_0x56bdee[_0xf534('0x16')](_0x3820ca);return _0x56bdee[_0xf534('0x1d')](_0xf534('0x1e'),_0x16128e+'-'+_0x16659d+'/'+_0xebc09d)[_0xf534('0x18')](_0x5ad3e8);}return null;};}function patchUpdates(_0x1e4f46){return function(_0x39e094){try{jsonpatch['apply'](_0x39e094,_0x1e4f46,!![]);}catch(_0x3c9cfc){return BPromise[_0xf534('0x1f')](_0x3c9cfc);}return _0x39e094['save']();};}function saveUpdates(_0x533b33,_0x4edd7f){return function(_0x5bcfd6){if(_0x5bcfd6){return _0x5bcfd6[_0xf534('0x20')](_0x533b33)[_0xf534('0x21')](function(_0x527632){return _0x527632;});}return null;};}function removeEntity(_0x87f75f,_0x2effb3){return function(_0x15db7d){if(_0x15db7d){return _0x15db7d['destroy']()['then'](function(){_0x87f75f['status'](0xcc)[_0xf534('0x17')]();});}};}function handleEntityNotFound(_0x509d4d,_0x2dd8f8){return function(_0xfc9448){if(!_0xfc9448){_0x509d4d[_0xf534('0x15')](0x194);}return _0xfc9448;};}function handleError(_0x433463,_0x255c06){_0x255c06=_0x255c06||0x1f4;return function(_0x1d542c){logger['error'](_0x1d542c[_0xf534('0x22')]);if(_0x1d542c[_0xf534('0x23')]){delete _0x1d542c[_0xf534('0x23')];}_0x433463['status'](_0x255c06)[_0xf534('0x24')](_0x1d542c);};}exports[_0xf534('0x25')]=function(_0x4c233d,_0x2ee2d6){var _0xa00f37={},_0x689586={},_0xb08797={'count':0x0,'rows':[]};var _0x3f1eea=_[_0xf534('0x26')](db[_0xf534('0x27')]['rawAttributes'],function(_0x1dc24b){return{'name':_0x1dc24b[_0xf534('0x28')],'type':_0x1dc24b['type'][_0xf534('0x29')]};});_0x689586['model']=_[_0xf534('0x26')](_0x3f1eea,_0xf534('0x23'));_0x689586[_0xf534('0x2a')]=_[_0xf534('0x2b')](_0x4c233d[_0xf534('0x2a')]);_0x689586[_0xf534('0x2c')]=_[_0xf534('0x2d')](_0x689586['model'],_0x689586[_0xf534('0x2a')]);_0xa00f37[_0xf534('0x2e')]=_[_0xf534('0x2d')](_0x689586[_0xf534('0x2f')],qs[_0xf534('0x30')](_0x4c233d[_0xf534('0x2a')][_0xf534('0x30')]));_0xa00f37[_0xf534('0x2e')]=_0xa00f37['attributes'][_0xf534('0x31')]?_0xa00f37[_0xf534('0x2e')]:_0x689586[_0xf534('0x2f')];if(!_0x4c233d[_0xf534('0x2a')][_0xf534('0x32')](_0xf534('0x33'))){_0xa00f37[_0xf534('0x1c')]=qs[_0xf534('0x1c')](_0x4c233d[_0xf534('0x2a')][_0xf534('0x1c')]);_0xa00f37[_0xf534('0x19')]=qs[_0xf534('0x19')](_0x4c233d[_0xf534('0x2a')][_0xf534('0x19')]);}_0xa00f37[_0xf534('0x34')]=qs[_0xf534('0x35')](_0x4c233d['query'][_0xf534('0x35')]);_0xa00f37[_0xf534('0x36')]=qs['filters'](_[_0xf534('0x37')](_0x4c233d[_0xf534('0x2a')],_0x689586['filters']),_0x3f1eea);if(_0x4c233d[_0xf534('0x2a')][_0xf534('0x38')]){_0xa00f37['where']=_[_0xf534('0x39')](_0xa00f37[_0xf534('0x36')],{'$or':_[_0xf534('0x26')](_0x3f1eea,function(_0x10b03e){if(_0x10b03e[_0xf534('0x3a')]!==_0xf534('0x3b')){var _0x3e3a6f={};_0x3e3a6f[_0x10b03e[_0xf534('0x23')]]={'$like':'%'+_0x4c233d[_0xf534('0x2a')][_0xf534('0x38')]+'%'};return _0x3e3a6f;}})});}_0xa00f37=_['merge']({},_0xa00f37,_0x4c233d[_0xf534('0x3c')]);var _0x55582d={'where':_0xa00f37[_0xf534('0x36')]};return db[_0xf534('0x27')][_0xf534('0x1b')](_0x55582d)[_0xf534('0x21')](function(_0x3636a6){_0xb08797['count']=_0x3636a6;if(_0x4c233d[_0xf534('0x2a')][_0xf534('0x3d')]){_0xa00f37['include']=[{'all':!![]}];}return db[_0xf534('0x27')]['findAll'](_0xa00f37);})[_0xf534('0x21')](function(_0x450247){_0xb08797[_0xf534('0x3e')]=_0x450247;return _0xb08797;})[_0xf534('0x21')](respondWithFilteredResult(_0x2ee2d6,_0xa00f37))[_0xf534('0x3f')](handleError(_0x2ee2d6,null));};exports[_0xf534('0x40')]=function(_0x529f1e,_0x16d634){var _0x3a622b={'raw':!![],'where':{'id':_0x529f1e[_0xf534('0x41')]['id']}},_0x1f412f={};_0x1f412f[_0xf534('0x2f')]=_[_0xf534('0x2b')](db[_0xf534('0x27')][_0xf534('0x42')]);_0x1f412f[_0xf534('0x2a')]=_[_0xf534('0x2b')](_0x529f1e['query']);_0x1f412f[_0xf534('0x2c')]=_[_0xf534('0x2d')](_0x1f412f['model'],_0x1f412f[_0xf534('0x2a')]);_0x3a622b[_0xf534('0x2e')]=_['intersection'](_0x1f412f[_0xf534('0x2f')],qs['fields'](_0x529f1e[_0xf534('0x2a')][_0xf534('0x30')]));_0x3a622b[_0xf534('0x2e')]=_0x3a622b[_0xf534('0x2e')][_0xf534('0x31')]?_0x3a622b[_0xf534('0x2e')]:_0x1f412f[_0xf534('0x2f')];if(_0x529f1e[_0xf534('0x2a')][_0xf534('0x3d')]){_0x3a622b[_0xf534('0x43')]=[{'all':!![]}];}_0x3a622b=_[_0xf534('0x39')]({},_0x3a622b,_0x529f1e[_0xf534('0x3c')]);return db['SalesforceField'][_0xf534('0x44')](_0x3a622b)['then'](handleEntityNotFound(_0x16d634,null))['then'](respondWithResult(_0x16d634,null))['catch'](handleError(_0x16d634,null));};exports[_0xf534('0x45')]=function(_0x2af886,_0xa871fb){return db[_0xf534('0x27')]['create'](_0x2af886[_0xf534('0x46')],{})['then'](respondWithResult(_0xa871fb,0xc9))[_0xf534('0x3f')](handleError(_0xa871fb,null));};exports[_0xf534('0x20')]=function(_0x56bcf1,_0x49f24a){if(_0x56bcf1[_0xf534('0x46')]['id']){delete _0x56bcf1['body']['id'];}return db[_0xf534('0x27')][_0xf534('0x44')]({'where':{'id':_0x56bcf1[_0xf534('0x41')]['id']}})[_0xf534('0x21')](handleEntityNotFound(_0x49f24a,null))[_0xf534('0x21')](saveUpdates(_0x56bcf1[_0xf534('0x46')],null))[_0xf534('0x21')](respondWithResult(_0x49f24a,null))[_0xf534('0x3f')](handleError(_0x49f24a,null));};exports['destroy']=function(_0xefd2f7,_0x71c5bc){return db[_0xf534('0x27')][_0xf534('0x44')]({'where':{'id':_0xefd2f7[_0xf534('0x41')]['id']}})[_0xf534('0x21')](handleEntityNotFound(_0x71c5bc,null))['then'](removeEntity(_0x71c5bc,null))[_0xf534('0x3f')](handleError(_0x71c5bc,null));};