Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / intSugarcrmField / intSugarcrmField.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 _0xeec0=['name','send','map','SugarcrmField','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','length','order','sort','pick','where','VIRTUAL','filter','merge','includeAll','include','findAll','rows','catch','show','params','options','find','body','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','apply','reject','update','then','destroy','end','error','stack'];(function(_0x306da5,_0x21c2ff){var _0x54bc07=function(_0x113ed8){while(--_0x113ed8){_0x306da5['push'](_0x306da5['shift']());}};_0x54bc07(++_0x21c2ff);}(_0xeec0,0x155));var _0x0eec=function(_0x157a2a,_0x503fe9){_0x157a2a=_0x157a2a-0x0;var _0x428b6e=_0xeec0[_0x157a2a];return _0x428b6e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x0eec('0x0'));var zipdir=require(_0x0eec('0x1'));var jsonpatch=require(_0x0eec('0x2'));var rp=require(_0x0eec('0x3'));var moment=require(_0x0eec('0x4'));var BPromise=require(_0x0eec('0x5'));var Mustache=require(_0x0eec('0x6'));var util=require(_0x0eec('0x7'));var path=require(_0x0eec('0x8'));var sox=require(_0x0eec('0x9'));var csv=require(_0x0eec('0xa'));var ejs=require(_0x0eec('0xb'));var fs=require('fs');var fs_extra=require(_0x0eec('0xc'));var _=require(_0x0eec('0xd'));var squel=require('squel');var crypto=require(_0x0eec('0xe'));var jsforce=require(_0x0eec('0xf'));var deskjs=require(_0x0eec('0x10'));var toCsv=require('to-csv');var querystring=require(_0x0eec('0x11'));var Papa=require(_0x0eec('0x12'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x0eec('0x13'));var as=require(_0x0eec('0x14'));var hardwareService=require(_0x0eec('0x15'));var logger=require(_0x0eec('0x16'))(_0x0eec('0x17'));var utils=require('../../config/utils');var config=require(_0x0eec('0x18'));var licenseUtil=require(_0x0eec('0x19'));var db=require(_0x0eec('0x1a'))['db'];function respondWithStatusCode(_0x3696a4,_0x2ae4b9){_0x2ae4b9=_0x2ae4b9||0xcc;return function(_0xade9c6){if(_0xade9c6){return _0x3696a4[_0x0eec('0x1b')](_0x2ae4b9);}return _0x3696a4[_0x0eec('0x1c')](_0x2ae4b9)['end']();};}function respondWithResult(_0x3df297,_0x4fb9ff){_0x4fb9ff=_0x4fb9ff||0xc8;return function(_0x10be37){if(_0x10be37){return _0x3df297[_0x0eec('0x1c')](_0x4fb9ff)[_0x0eec('0x1d')](_0x10be37);}};}function respondWithFilteredResult(_0x13d5c2,_0x49c73d){return function(_0x3701e6){if(_0x3701e6){var _0xe9b743=typeof _0x49c73d[_0x0eec('0x1e')]==='undefined'&&typeof _0x49c73d[_0x0eec('0x1f')]===_0x0eec('0x20');var _0x536979=_0x3701e6[_0x0eec('0x21')];var _0x50a340=_0xe9b743?0x0:_0x49c73d[_0x0eec('0x1e')];var _0xb8e3dd=_0xe9b743?_0x3701e6['count']:_0x49c73d[_0x0eec('0x1e')]+_0x49c73d[_0x0eec('0x1f')];var _0x1da8da;if(_0xb8e3dd>=_0x536979){_0xb8e3dd=_0x536979;_0x1da8da=0xc8;}else{_0x1da8da=0xce;}_0x13d5c2[_0x0eec('0x1c')](_0x1da8da);return _0x13d5c2[_0x0eec('0x22')](_0x0eec('0x23'),_0x50a340+'-'+_0xb8e3dd+'/'+_0x536979)['json'](_0x3701e6);}return null;};}function patchUpdates(_0x264b12){return function(_0x1ce962){try{jsonpatch[_0x0eec('0x24')](_0x1ce962,_0x264b12,!![]);}catch(_0xaaf512){return BPromise[_0x0eec('0x25')](_0xaaf512);}return _0x1ce962['save']();};}function saveUpdates(_0xc47f67,_0x25fce8){return function(_0x215389){if(_0x215389){return _0x215389[_0x0eec('0x26')](_0xc47f67)[_0x0eec('0x27')](function(_0x1f4fc0){return _0x1f4fc0;});}return null;};}function removeEntity(_0x3009f3,_0x169062){return function(_0x14ad9b){if(_0x14ad9b){return _0x14ad9b[_0x0eec('0x28')]()['then'](function(){_0x3009f3['status'](0xcc)[_0x0eec('0x29')]();});}};}function handleEntityNotFound(_0x3c272d,_0x53c4f8){return function(_0x1b1ca6){if(!_0x1b1ca6){_0x3c272d[_0x0eec('0x1b')](0x194);}return _0x1b1ca6;};}function handleError(_0x5a191d,_0x5acc48){_0x5acc48=_0x5acc48||0x1f4;return function(_0x2b2005){logger[_0x0eec('0x2a')](_0x2b2005[_0x0eec('0x2b')]);if(_0x2b2005[_0x0eec('0x2c')]){delete _0x2b2005[_0x0eec('0x2c')];}_0x5a191d[_0x0eec('0x1c')](_0x5acc48)[_0x0eec('0x2d')](_0x2b2005);};}exports['index']=function(_0x57e71e,_0x41881e){var _0xf1f464={},_0x9b293a={},_0x27db31={'count':0x0,'rows':[]};var _0x365eae=_[_0x0eec('0x2e')](db[_0x0eec('0x2f')][_0x0eec('0x30')],function(_0x416906){return{'name':_0x416906[_0x0eec('0x31')],'type':_0x416906[_0x0eec('0x32')][_0x0eec('0x33')]};});_0x9b293a[_0x0eec('0x34')]=_[_0x0eec('0x2e')](_0x365eae,_0x0eec('0x2c'));_0x9b293a['query']=_[_0x0eec('0x35')](_0x57e71e[_0x0eec('0x36')]);_0x9b293a[_0x0eec('0x37')]=_['intersection'](_0x9b293a['model'],_0x9b293a['query']);_0xf1f464[_0x0eec('0x38')]=_[_0x0eec('0x39')](_0x9b293a['model'],qs['fields'](_0x57e71e[_0x0eec('0x36')][_0x0eec('0x3a')]));_0xf1f464[_0x0eec('0x38')]=_0xf1f464[_0x0eec('0x38')][_0x0eec('0x3b')]?_0xf1f464[_0x0eec('0x38')]:_0x9b293a[_0x0eec('0x34')];if(!_0x57e71e[_0x0eec('0x36')]['hasOwnProperty']('nolimit')){_0xf1f464[_0x0eec('0x1f')]=qs[_0x0eec('0x1f')](_0x57e71e[_0x0eec('0x36')][_0x0eec('0x1f')]);_0xf1f464[_0x0eec('0x1e')]=qs['offset'](_0x57e71e[_0x0eec('0x36')][_0x0eec('0x1e')]);}_0xf1f464[_0x0eec('0x3c')]=qs[_0x0eec('0x3d')](_0x57e71e[_0x0eec('0x36')][_0x0eec('0x3d')]);_0xf1f464['where']=qs[_0x0eec('0x37')](_[_0x0eec('0x3e')](_0x57e71e[_0x0eec('0x36')],_0x9b293a[_0x0eec('0x37')]),_0x365eae);if(_0x57e71e[_0x0eec('0x36')]['filter']){_0xf1f464['where']=_['merge'](_0xf1f464[_0x0eec('0x3f')],{'$or':_[_0x0eec('0x2e')](_0x365eae,function(_0x44eae2){if(_0x44eae2[_0x0eec('0x32')]!==_0x0eec('0x40')){var _0x41f49e={};_0x41f49e[_0x44eae2[_0x0eec('0x2c')]]={'$like':'%'+_0x57e71e[_0x0eec('0x36')][_0x0eec('0x41')]+'%'};return _0x41f49e;}})});}_0xf1f464=_[_0x0eec('0x42')]({},_0xf1f464,_0x57e71e['options']);var _0x3651e4={'where':_0xf1f464['where']};return db[_0x0eec('0x2f')][_0x0eec('0x21')](_0x3651e4)[_0x0eec('0x27')](function(_0x4289ed){_0x27db31['count']=_0x4289ed;if(_0x57e71e[_0x0eec('0x36')][_0x0eec('0x43')]){_0xf1f464[_0x0eec('0x44')]=[{'all':!![]}];}return db[_0x0eec('0x2f')][_0x0eec('0x45')](_0xf1f464);})[_0x0eec('0x27')](function(_0x22e253){_0x27db31[_0x0eec('0x46')]=_0x22e253;return _0x27db31;})['then'](respondWithFilteredResult(_0x41881e,_0xf1f464))[_0x0eec('0x47')](handleError(_0x41881e,null));};exports[_0x0eec('0x48')]=function(_0x9a5f90,_0x2345d9){var _0x18349c={'raw':!![],'where':{'id':_0x9a5f90[_0x0eec('0x49')]['id']}},_0x44c6b3={};_0x44c6b3[_0x0eec('0x34')]=_[_0x0eec('0x35')](db[_0x0eec('0x2f')][_0x0eec('0x30')]);_0x44c6b3[_0x0eec('0x36')]=_[_0x0eec('0x35')](_0x9a5f90[_0x0eec('0x36')]);_0x44c6b3[_0x0eec('0x37')]=_['intersection'](_0x44c6b3['model'],_0x44c6b3[_0x0eec('0x36')]);_0x18349c[_0x0eec('0x38')]=_['intersection'](_0x44c6b3[_0x0eec('0x34')],qs[_0x0eec('0x3a')](_0x9a5f90['query'][_0x0eec('0x3a')]));_0x18349c[_0x0eec('0x38')]=_0x18349c[_0x0eec('0x38')][_0x0eec('0x3b')]?_0x18349c['attributes']:_0x44c6b3[_0x0eec('0x34')];if(_0x9a5f90[_0x0eec('0x36')][_0x0eec('0x43')]){_0x18349c[_0x0eec('0x44')]=[{'all':!![]}];}_0x18349c=_[_0x0eec('0x42')]({},_0x18349c,_0x9a5f90[_0x0eec('0x4a')]);return db[_0x0eec('0x2f')][_0x0eec('0x4b')](_0x18349c)[_0x0eec('0x27')](handleEntityNotFound(_0x2345d9,null))[_0x0eec('0x27')](respondWithResult(_0x2345d9,null))[_0x0eec('0x47')](handleError(_0x2345d9,null));};exports['create']=function(_0x32c4ca,_0x35b592){return db['SugarcrmField']['create'](_0x32c4ca[_0x0eec('0x4c')],{})[_0x0eec('0x27')](respondWithResult(_0x35b592,0xc9))[_0x0eec('0x47')](handleError(_0x35b592,null));};exports['update']=function(_0x203b03,_0x302fec){if(_0x203b03[_0x0eec('0x4c')]['id']){delete _0x203b03[_0x0eec('0x4c')]['id'];}return db[_0x0eec('0x2f')][_0x0eec('0x4b')]({'where':{'id':_0x203b03[_0x0eec('0x49')]['id']}})[_0x0eec('0x27')](handleEntityNotFound(_0x302fec,null))['then'](saveUpdates(_0x203b03['body'],null))[_0x0eec('0x27')](respondWithResult(_0x302fec,null))[_0x0eec('0x47')](handleError(_0x302fec,null));};exports['destroy']=function(_0x32d478,_0x3c4c14){return db[_0x0eec('0x2f')][_0x0eec('0x4b')]({'where':{'id':_0x32d478[_0x0eec('0x49')]['id']}})[_0x0eec('0x27')](handleEntityNotFound(_0x3c4c14,null))[_0x0eec('0x27')](removeEntity(_0x3c4c14,null))[_0x0eec('0x47')](handleError(_0x3c4c14,null));};