e69b228de744e7f4e0a89228cfa6982b9c72cd84
[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 _0x4f0b=['bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','count','offset','limit','set','Content-Range','apply','update','end','error','stack','name','send','index','map','SugarcrmField','rawAttributes','type','key','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','where','merge','VIRTUAL','options','then','includeAll','include','findAll','show','params','catch','create','body','destroy','find','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x3ceb6c,_0x554602){var _0x256814=function(_0x7800cf){while(--_0x7800cf){_0x3ceb6c['push'](_0x3ceb6c['shift']());}};_0x256814(++_0x554602);}(_0x4f0b,0x96));var _0xb4f0=function(_0x249da4,_0x81b7b5){_0x249da4=_0x249da4-0x0;var _0x4f23b5=_0x4f0b[_0x249da4];return _0x4f23b5;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb4f0('0x0'));var zipdir=require(_0xb4f0('0x1'));var jsonpatch=require(_0xb4f0('0x2'));var rp=require(_0xb4f0('0x3'));var moment=require('moment');var BPromise=require(_0xb4f0('0x4'));var Mustache=require(_0xb4f0('0x5'));var util=require(_0xb4f0('0x6'));var path=require(_0xb4f0('0x7'));var sox=require(_0xb4f0('0x8'));var csv=require(_0xb4f0('0x9'));var ejs=require(_0xb4f0('0xa'));var fs=require('fs');var fs_extra=require(_0xb4f0('0xb'));var _=require(_0xb4f0('0xc'));var squel=require(_0xb4f0('0xd'));var crypto=require(_0xb4f0('0xe'));var jsforce=require(_0xb4f0('0xf'));var deskjs=require(_0xb4f0('0x10'));var toCsv=require(_0xb4f0('0x9'));var querystring=require(_0xb4f0('0x11'));var Papa=require(_0xb4f0('0x12'));var Redis=require(_0xb4f0('0x13'));var authService=require(_0xb4f0('0x14'));var qs=require(_0xb4f0('0x15'));var as=require(_0xb4f0('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xb4f0('0x17'));var utils=require(_0xb4f0('0x18'));var config=require(_0xb4f0('0x19'));var licenseUtil=require(_0xb4f0('0x1a'));var db=require(_0xb4f0('0x1b'))['db'];function respondWithStatusCode(_0x1db6ac,_0x35b47e){_0x35b47e=_0x35b47e||0xcc;return function(_0x49f291){if(_0x49f291){return _0x1db6ac[_0xb4f0('0x1c')](_0x35b47e);}return _0x1db6ac[_0xb4f0('0x1d')](_0x35b47e)['end']();};}function respondWithResult(_0x98acc1,_0x4577df){_0x4577df=_0x4577df||0xc8;return function(_0x38b062){if(_0x38b062){return _0x98acc1[_0xb4f0('0x1d')](_0x4577df)[_0xb4f0('0x1e')](_0x38b062);}};}function respondWithFilteredResult(_0x7796df,_0x4e8515){return function(_0x9d3503){if(_0x9d3503){var _0x117880=typeof _0x4e8515['offset']===_0xb4f0('0x1f')&&typeof _0x4e8515['limit']===_0xb4f0('0x1f');var _0x25256b=_0x9d3503[_0xb4f0('0x20')];var _0x234665=_0x117880?0x0:_0x4e8515['offset'];var _0x44b51a=_0x117880?_0x9d3503[_0xb4f0('0x20')]:_0x4e8515[_0xb4f0('0x21')]+_0x4e8515[_0xb4f0('0x22')];var _0x1c8d6b;if(_0x44b51a>=_0x25256b){_0x44b51a=_0x25256b;_0x1c8d6b=0xc8;}else{_0x1c8d6b=0xce;}_0x7796df['status'](_0x1c8d6b);return _0x7796df[_0xb4f0('0x23')](_0xb4f0('0x24'),_0x234665+'-'+_0x44b51a+'/'+_0x25256b)[_0xb4f0('0x1e')](_0x9d3503);}return null;};}function patchUpdates(_0xc5bda3){return function(_0x21031d){try{jsonpatch[_0xb4f0('0x25')](_0x21031d,_0xc5bda3,!![]);}catch(_0x56a191){return BPromise['reject'](_0x56a191);}return _0x21031d['save']();};}function saveUpdates(_0xa4fa7e,_0x102ea2){return function(_0x4ef645){if(_0x4ef645){return _0x4ef645[_0xb4f0('0x26')](_0xa4fa7e)['then'](function(_0x169237){return _0x169237;});}return null;};}function removeEntity(_0x4612dd,_0x3fb518){return function(_0x3f26e0){if(_0x3f26e0){return _0x3f26e0['destroy']()['then'](function(){_0x4612dd[_0xb4f0('0x1d')](0xcc)[_0xb4f0('0x27')]();});}};}function handleEntityNotFound(_0x8b862e,_0x14b9b0){return function(_0x1b555c){if(!_0x1b555c){_0x8b862e[_0xb4f0('0x1c')](0x194);}return _0x1b555c;};}function handleError(_0x328a15,_0x165c29){_0x165c29=_0x165c29||0x1f4;return function(_0x36e28b){logger[_0xb4f0('0x28')](_0x36e28b[_0xb4f0('0x29')]);if(_0x36e28b[_0xb4f0('0x2a')]){delete _0x36e28b[_0xb4f0('0x2a')];}_0x328a15[_0xb4f0('0x1d')](_0x165c29)[_0xb4f0('0x2b')](_0x36e28b);};}exports[_0xb4f0('0x2c')]=function(_0x4452ef,_0xc2d60d){var _0x577d3c={},_0x3f37cf={},_0x4c89a1={'count':0x0,'rows':[]};var _0x372027=_[_0xb4f0('0x2d')](db[_0xb4f0('0x2e')][_0xb4f0('0x2f')],function(_0x373fad){return{'name':_0x373fad['fieldName'],'type':_0x373fad[_0xb4f0('0x30')][_0xb4f0('0x31')]};});_0x3f37cf[_0xb4f0('0x32')]=_[_0xb4f0('0x2d')](_0x372027,_0xb4f0('0x2a'));_0x3f37cf['query']=_[_0xb4f0('0x33')](_0x4452ef[_0xb4f0('0x34')]);_0x3f37cf[_0xb4f0('0x35')]=_[_0xb4f0('0x36')](_0x3f37cf[_0xb4f0('0x32')],_0x3f37cf[_0xb4f0('0x34')]);_0x577d3c[_0xb4f0('0x37')]=_[_0xb4f0('0x36')](_0x3f37cf[_0xb4f0('0x32')],qs[_0xb4f0('0x38')](_0x4452ef[_0xb4f0('0x34')]['fields']));_0x577d3c[_0xb4f0('0x37')]=_0x577d3c[_0xb4f0('0x37')]['length']?_0x577d3c[_0xb4f0('0x37')]:_0x3f37cf['model'];if(!_0x4452ef[_0xb4f0('0x34')][_0xb4f0('0x39')](_0xb4f0('0x3a'))){_0x577d3c['limit']=qs['limit'](_0x4452ef[_0xb4f0('0x34')]['limit']);_0x577d3c['offset']=qs[_0xb4f0('0x21')](_0x4452ef[_0xb4f0('0x34')][_0xb4f0('0x21')]);}_0x577d3c[_0xb4f0('0x3b')]=qs[_0xb4f0('0x3c')](_0x4452ef[_0xb4f0('0x34')][_0xb4f0('0x3c')]);_0x577d3c['where']=qs[_0xb4f0('0x35')](_[_0xb4f0('0x3d')](_0x4452ef['query'],_0x3f37cf[_0xb4f0('0x35')]),_0x372027);if(_0x4452ef['query']['filter']){_0x577d3c[_0xb4f0('0x3e')]=_[_0xb4f0('0x3f')](_0x577d3c[_0xb4f0('0x3e')],{'$or':_[_0xb4f0('0x2d')](_0x372027,function(_0x3a0e89){if(_0x3a0e89[_0xb4f0('0x30')]!==_0xb4f0('0x40')){var _0x5f5779={};_0x5f5779[_0x3a0e89[_0xb4f0('0x2a')]]={'$like':'%'+_0x4452ef[_0xb4f0('0x34')]['filter']+'%'};return _0x5f5779;}})});}_0x577d3c=_[_0xb4f0('0x3f')]({},_0x577d3c,_0x4452ef[_0xb4f0('0x41')]);var _0x2ea4a3={'where':_0x577d3c[_0xb4f0('0x3e')]};return db['SugarcrmField'][_0xb4f0('0x20')](_0x2ea4a3)[_0xb4f0('0x42')](function(_0x2f66b4){_0x4c89a1[_0xb4f0('0x20')]=_0x2f66b4;if(_0x4452ef['query'][_0xb4f0('0x43')]){_0x577d3c[_0xb4f0('0x44')]=[{'all':!![]}];}return db['SugarcrmField'][_0xb4f0('0x45')](_0x577d3c);})[_0xb4f0('0x42')](function(_0x3aec4b){_0x4c89a1['rows']=_0x3aec4b;return _0x4c89a1;})[_0xb4f0('0x42')](respondWithFilteredResult(_0xc2d60d,_0x577d3c))['catch'](handleError(_0xc2d60d,null));};exports[_0xb4f0('0x46')]=function(_0x49116c,_0x276685){var _0x308009={'raw':!![],'where':{'id':_0x49116c[_0xb4f0('0x47')]['id']}},_0x12ac99={};_0x12ac99[_0xb4f0('0x32')]=_['keys'](db[_0xb4f0('0x2e')][_0xb4f0('0x2f')]);_0x12ac99[_0xb4f0('0x34')]=_['keys'](_0x49116c[_0xb4f0('0x34')]);_0x12ac99[_0xb4f0('0x35')]=_[_0xb4f0('0x36')](_0x12ac99[_0xb4f0('0x32')],_0x12ac99[_0xb4f0('0x34')]);_0x308009[_0xb4f0('0x37')]=_[_0xb4f0('0x36')](_0x12ac99[_0xb4f0('0x32')],qs['fields'](_0x49116c[_0xb4f0('0x34')][_0xb4f0('0x38')]));_0x308009[_0xb4f0('0x37')]=_0x308009[_0xb4f0('0x37')]['length']?_0x308009['attributes']:_0x12ac99[_0xb4f0('0x32')];if(_0x49116c['query'][_0xb4f0('0x43')]){_0x308009[_0xb4f0('0x44')]=[{'all':!![]}];}_0x308009=_['merge']({},_0x308009,_0x49116c[_0xb4f0('0x41')]);return db['SugarcrmField']['find'](_0x308009)[_0xb4f0('0x42')](handleEntityNotFound(_0x276685,null))['then'](respondWithResult(_0x276685,null))[_0xb4f0('0x48')](handleError(_0x276685,null));};exports[_0xb4f0('0x49')]=function(_0x852a4c,_0x2497ae){return db['SugarcrmField'][_0xb4f0('0x49')](_0x852a4c['body'],{})[_0xb4f0('0x42')](respondWithResult(_0x2497ae,0xc9))[_0xb4f0('0x48')](handleError(_0x2497ae,null));};exports[_0xb4f0('0x26')]=function(_0xc338b6,_0x5c2b39){if(_0xc338b6[_0xb4f0('0x4a')]['id']){delete _0xc338b6[_0xb4f0('0x4a')]['id'];}return db[_0xb4f0('0x2e')]['find']({'where':{'id':_0xc338b6[_0xb4f0('0x47')]['id']}})[_0xb4f0('0x42')](handleEntityNotFound(_0x5c2b39,null))[_0xb4f0('0x42')](saveUpdates(_0xc338b6[_0xb4f0('0x4a')],null))[_0xb4f0('0x42')](respondWithResult(_0x5c2b39,null))['catch'](handleError(_0x5c2b39,null));};exports[_0xb4f0('0x4b')]=function(_0x4dac8d,_0x41b5e1){return db['SugarcrmField'][_0xb4f0('0x4c')]({'where':{'id':_0x4dac8d['params']['id']}})[_0xb4f0('0x42')](handleEntityNotFound(_0x41b5e1,null))[_0xb4f0('0x42')](removeEntity(_0x41b5e1,null))[_0xb4f0('0x48')](handleError(_0x41b5e1,null));};