Built motion from commit e6806ed6.|2.6.0
[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 _0xb6b8=['../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','apply','reject','save','then','error','stack','name','index','SugarcrmField','rawAttributes','fieldName','type','key','model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','options','findAll','rows','catch','show','params','keys','includeAll','include','find','create','update','body','destroy','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service'];(function(_0x5556cd,_0x130d27){var _0x31ec61=function(_0x2448fb){while(--_0x2448fb){_0x5556cd['push'](_0x5556cd['shift']());}};_0x31ec61(++_0x130d27);}(_0xb6b8,0x122));var _0x8b6b=function(_0x5db231,_0x4540e7){_0x5db231=_0x5db231-0x0;var _0x11d04a=_0xb6b8[_0x5db231];return _0x11d04a;};'use strict';var emlformat=require(_0x8b6b('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x8b6b('0x1'));var jsonpatch=require(_0x8b6b('0x2'));var rp=require('request-promise');var moment=require(_0x8b6b('0x3'));var BPromise=require(_0x8b6b('0x4'));var Mustache=require(_0x8b6b('0x5'));var util=require(_0x8b6b('0x6'));var path=require('path');var sox=require(_0x8b6b('0x7'));var csv=require(_0x8b6b('0x8'));var ejs=require(_0x8b6b('0x9'));var fs=require('fs');var fs_extra=require(_0x8b6b('0xa'));var _=require('lodash');var squel=require(_0x8b6b('0xb'));var crypto=require(_0x8b6b('0xc'));var jsforce=require(_0x8b6b('0xd'));var deskjs=require(_0x8b6b('0xe'));var toCsv=require(_0x8b6b('0x8'));var querystring=require(_0x8b6b('0xf'));var Papa=require('papaparse');var Redis=require(_0x8b6b('0x10'));var authService=require(_0x8b6b('0x11'));var qs=require(_0x8b6b('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x8b6b('0x13'));var logger=require(_0x8b6b('0x14'))(_0x8b6b('0x15'));var utils=require(_0x8b6b('0x16'));var config=require(_0x8b6b('0x17'));var licenseUtil=require(_0x8b6b('0x18'));var db=require(_0x8b6b('0x19'))['db'];function respondWithStatusCode(_0x558faa,_0x534ee1){_0x534ee1=_0x534ee1||0xcc;return function(_0x72ab60){if(_0x72ab60){return _0x558faa[_0x8b6b('0x1a')](_0x534ee1);}return _0x558faa[_0x8b6b('0x1b')](_0x534ee1)[_0x8b6b('0x1c')]();};}function respondWithResult(_0x41c63b,_0x2b34e9){_0x2b34e9=_0x2b34e9||0xc8;return function(_0x2440af){if(_0x2440af){return _0x41c63b[_0x8b6b('0x1b')](_0x2b34e9)[_0x8b6b('0x1d')](_0x2440af);}};}function respondWithFilteredResult(_0x442656,_0x3c7046){return function(_0x2ed3b6){if(_0x2ed3b6){var _0x1ca3bb=typeof _0x3c7046[_0x8b6b('0x1e')]==='undefined'&&typeof _0x3c7046[_0x8b6b('0x1f')]===_0x8b6b('0x20');var _0x3a0895=_0x2ed3b6[_0x8b6b('0x21')];var _0x2a3364=_0x1ca3bb?0x0:_0x3c7046[_0x8b6b('0x1e')];var _0x48a0d9=_0x1ca3bb?_0x2ed3b6[_0x8b6b('0x21')]:_0x3c7046['offset']+_0x3c7046[_0x8b6b('0x1f')];var _0x72fedf;if(_0x48a0d9>=_0x3a0895){_0x48a0d9=_0x3a0895;_0x72fedf=0xc8;}else{_0x72fedf=0xce;}_0x442656['status'](_0x72fedf);return _0x442656['set']('Content-Range',_0x2a3364+'-'+_0x48a0d9+'/'+_0x3a0895)[_0x8b6b('0x1d')](_0x2ed3b6);}return null;};}function patchUpdates(_0x336015){return function(_0x48619c){try{jsonpatch[_0x8b6b('0x22')](_0x48619c,_0x336015,!![]);}catch(_0xb80e75){return BPromise[_0x8b6b('0x23')](_0xb80e75);}return _0x48619c[_0x8b6b('0x24')]();};}function saveUpdates(_0x2c81b,_0x3bb6a9){return function(_0x51ed44){if(_0x51ed44){return _0x51ed44['update'](_0x2c81b)['then'](function(_0x1c0efe){return _0x1c0efe;});}return null;};}function removeEntity(_0x25ef83,_0x31f3cc){return function(_0x33e36e){if(_0x33e36e){return _0x33e36e['destroy']()[_0x8b6b('0x25')](function(){_0x25ef83[_0x8b6b('0x1b')](0xcc)[_0x8b6b('0x1c')]();});}};}function handleEntityNotFound(_0x201cc2,_0x762595){return function(_0x1fbd4d){if(!_0x1fbd4d){_0x201cc2['sendStatus'](0x194);}return _0x1fbd4d;};}function handleError(_0x4b35ec,_0x394bbb){_0x394bbb=_0x394bbb||0x1f4;return function(_0x180e3c){logger[_0x8b6b('0x26')](_0x180e3c[_0x8b6b('0x27')]);if(_0x180e3c[_0x8b6b('0x28')]){delete _0x180e3c['name'];}_0x4b35ec[_0x8b6b('0x1b')](_0x394bbb)['send'](_0x180e3c);};}exports[_0x8b6b('0x29')]=function(_0x3821b2,_0x423373){var _0x367bf={},_0x2e4440={},_0x779bc4={'count':0x0,'rows':[]};var _0x220b00=_['map'](db[_0x8b6b('0x2a')][_0x8b6b('0x2b')],function(_0x2dbd09){return{'name':_0x2dbd09[_0x8b6b('0x2c')],'type':_0x2dbd09[_0x8b6b('0x2d')][_0x8b6b('0x2e')]};});_0x2e4440[_0x8b6b('0x2f')]=_[_0x8b6b('0x30')](_0x220b00,_0x8b6b('0x28'));_0x2e4440[_0x8b6b('0x31')]=_['keys'](_0x3821b2['query']);_0x2e4440[_0x8b6b('0x32')]=_[_0x8b6b('0x33')](_0x2e4440[_0x8b6b('0x2f')],_0x2e4440[_0x8b6b('0x31')]);_0x367bf[_0x8b6b('0x34')]=_[_0x8b6b('0x33')](_0x2e4440[_0x8b6b('0x2f')],qs[_0x8b6b('0x35')](_0x3821b2['query'][_0x8b6b('0x35')]));_0x367bf['attributes']=_0x367bf[_0x8b6b('0x34')][_0x8b6b('0x36')]?_0x367bf[_0x8b6b('0x34')]:_0x2e4440[_0x8b6b('0x2f')];if(!_0x3821b2[_0x8b6b('0x31')][_0x8b6b('0x37')](_0x8b6b('0x38'))){_0x367bf[_0x8b6b('0x1f')]=qs[_0x8b6b('0x1f')](_0x3821b2[_0x8b6b('0x31')]['limit']);_0x367bf[_0x8b6b('0x1e')]=qs[_0x8b6b('0x1e')](_0x3821b2[_0x8b6b('0x31')][_0x8b6b('0x1e')]);}_0x367bf[_0x8b6b('0x39')]=qs[_0x8b6b('0x3a')](_0x3821b2[_0x8b6b('0x31')][_0x8b6b('0x3a')]);_0x367bf['where']=qs[_0x8b6b('0x32')](_[_0x8b6b('0x3b')](_0x3821b2[_0x8b6b('0x31')],_0x2e4440[_0x8b6b('0x32')]),_0x220b00);if(_0x3821b2['query'][_0x8b6b('0x3c')]){_0x367bf[_0x8b6b('0x3d')]=_[_0x8b6b('0x3e')](_0x367bf[_0x8b6b('0x3d')],{'$or':_[_0x8b6b('0x30')](_0x220b00,function(_0x238c2d){if(_0x238c2d[_0x8b6b('0x2d')]!=='VIRTUAL'){var _0x30aaa6={};_0x30aaa6[_0x238c2d[_0x8b6b('0x28')]]={'$like':'%'+_0x3821b2['query'][_0x8b6b('0x3c')]+'%'};return _0x30aaa6;}})});}_0x367bf=_[_0x8b6b('0x3e')]({},_0x367bf,_0x3821b2[_0x8b6b('0x3f')]);var _0x166401={'where':_0x367bf[_0x8b6b('0x3d')]};return db['SugarcrmField'][_0x8b6b('0x21')](_0x166401)['then'](function(_0x872888){_0x779bc4['count']=_0x872888;if(_0x3821b2[_0x8b6b('0x31')]['includeAll']){_0x367bf['include']=[{'all':!![]}];}return db[_0x8b6b('0x2a')][_0x8b6b('0x40')](_0x367bf);})[_0x8b6b('0x25')](function(_0x31a3a3){_0x779bc4[_0x8b6b('0x41')]=_0x31a3a3;return _0x779bc4;})[_0x8b6b('0x25')](respondWithFilteredResult(_0x423373,_0x367bf))[_0x8b6b('0x42')](handleError(_0x423373,null));};exports[_0x8b6b('0x43')]=function(_0xffdbc9,_0x510fc2){var _0x515c87={'raw':!![],'where':{'id':_0xffdbc9[_0x8b6b('0x44')]['id']}},_0x3b6018={};_0x3b6018['model']=_['keys'](db['SugarcrmField'][_0x8b6b('0x2b')]);_0x3b6018[_0x8b6b('0x31')]=_[_0x8b6b('0x45')](_0xffdbc9['query']);_0x3b6018[_0x8b6b('0x32')]=_[_0x8b6b('0x33')](_0x3b6018[_0x8b6b('0x2f')],_0x3b6018[_0x8b6b('0x31')]);_0x515c87[_0x8b6b('0x34')]=_[_0x8b6b('0x33')](_0x3b6018[_0x8b6b('0x2f')],qs[_0x8b6b('0x35')](_0xffdbc9['query'][_0x8b6b('0x35')]));_0x515c87[_0x8b6b('0x34')]=_0x515c87[_0x8b6b('0x34')][_0x8b6b('0x36')]?_0x515c87[_0x8b6b('0x34')]:_0x3b6018[_0x8b6b('0x2f')];if(_0xffdbc9['query'][_0x8b6b('0x46')]){_0x515c87[_0x8b6b('0x47')]=[{'all':!![]}];}_0x515c87=_[_0x8b6b('0x3e')]({},_0x515c87,_0xffdbc9['options']);return db[_0x8b6b('0x2a')][_0x8b6b('0x48')](_0x515c87)['then'](handleEntityNotFound(_0x510fc2,null))[_0x8b6b('0x25')](respondWithResult(_0x510fc2,null))[_0x8b6b('0x42')](handleError(_0x510fc2,null));};exports[_0x8b6b('0x49')]=function(_0x407aae,_0x4450c2){return db[_0x8b6b('0x2a')][_0x8b6b('0x49')](_0x407aae['body'],{})[_0x8b6b('0x25')](respondWithResult(_0x4450c2,0xc9))['catch'](handleError(_0x4450c2,null));};exports[_0x8b6b('0x4a')]=function(_0x13ea7f,_0x2b3b51){if(_0x13ea7f[_0x8b6b('0x4b')]['id']){delete _0x13ea7f['body']['id'];}return db['SugarcrmField'][_0x8b6b('0x48')]({'where':{'id':_0x13ea7f[_0x8b6b('0x44')]['id']}})[_0x8b6b('0x25')](handleEntityNotFound(_0x2b3b51,null))[_0x8b6b('0x25')](saveUpdates(_0x13ea7f[_0x8b6b('0x4b')],null))[_0x8b6b('0x25')](respondWithResult(_0x2b3b51,null))[_0x8b6b('0x42')](handleError(_0x2b3b51,null));};exports[_0x8b6b('0x4c')]=function(_0x1e0ed3,_0xabfe7e){return db[_0x8b6b('0x2a')]['find']({'where':{'id':_0x1e0ed3[_0x8b6b('0x44')]['id']}})[_0x8b6b('0x25')](handleEntityNotFound(_0xabfe7e,null))['then'](removeEntity(_0xabfe7e,null))[_0x8b6b('0x42')](handleError(_0xabfe7e,null));};