Built motion from commit 43538d75.|2.5.35
[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 _0x9f20=['name','send','index','map','SugarcrmField','rawAttributes','type','key','model','keys','query','filters','attributes','length','order','sort','where','pick','filter','merge','options','findAll','rows','catch','show','params','intersection','fields','includeAll','include','find','create','body','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','update','then','error','stack'];(function(_0x4c0622,_0x5dacaf){var _0x1799d8=function(_0x2ba801){while(--_0x2ba801){_0x4c0622['push'](_0x4c0622['shift']());}};_0x1799d8(++_0x5dacaf);}(_0x9f20,0x1cb));var _0x09f2=function(_0x4f83c9,_0x4c98df){_0x4f83c9=_0x4f83c9-0x0;var _0x1e04bc=_0x9f20[_0x4f83c9];return _0x1e04bc;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x09f2('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x09f2('0x1'));var rp=require(_0x09f2('0x2'));var moment=require(_0x09f2('0x3'));var BPromise=require(_0x09f2('0x4'));var Mustache=require('mustache');var util=require(_0x09f2('0x5'));var path=require(_0x09f2('0x6'));var sox=require(_0x09f2('0x7'));var csv=require('to-csv');var ejs=require(_0x09f2('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x09f2('0x9'));var squel=require('squel');var crypto=require(_0x09f2('0xa'));var jsforce=require(_0x09f2('0xb'));var deskjs=require(_0x09f2('0xc'));var toCsv=require(_0x09f2('0xd'));var querystring=require(_0x09f2('0xe'));var Papa=require(_0x09f2('0xf'));var Redis=require(_0x09f2('0x10'));var authService=require(_0x09f2('0x11'));var qs=require(_0x09f2('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x09f2('0x13'));var logger=require(_0x09f2('0x14'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x09f2('0x15'));var db=require(_0x09f2('0x16'))['db'];function respondWithStatusCode(_0x3425b6,_0x12b1bc){_0x12b1bc=_0x12b1bc||0xcc;return function(_0x4f34b8){if(_0x4f34b8){return _0x3425b6[_0x09f2('0x17')](_0x12b1bc);}return _0x3425b6[_0x09f2('0x18')](_0x12b1bc)[_0x09f2('0x19')]();};}function respondWithResult(_0x4226a8,_0x34e66f){_0x34e66f=_0x34e66f||0xc8;return function(_0x4ae9e5){if(_0x4ae9e5){return _0x4226a8[_0x09f2('0x18')](_0x34e66f)[_0x09f2('0x1a')](_0x4ae9e5);}};}function respondWithFilteredResult(_0x3d2943,_0x349654){return function(_0x6bf557){if(_0x6bf557){var _0x4cb425=typeof _0x349654[_0x09f2('0x1b')]===_0x09f2('0x1c')&&typeof _0x349654['limit']===_0x09f2('0x1c');var _0x16cadf=_0x6bf557['count'];var _0x7606e6=_0x4cb425?0x0:_0x349654['offset'];var _0x5c7395=_0x4cb425?_0x6bf557[_0x09f2('0x1d')]:_0x349654[_0x09f2('0x1b')]+_0x349654[_0x09f2('0x1e')];var _0xea5ea;if(_0x5c7395>=_0x16cadf){_0x5c7395=_0x16cadf;_0xea5ea=0xc8;}else{_0xea5ea=0xce;}_0x3d2943[_0x09f2('0x18')](_0xea5ea);return _0x3d2943['set'](_0x09f2('0x1f'),_0x7606e6+'-'+_0x5c7395+'/'+_0x16cadf)[_0x09f2('0x1a')](_0x6bf557);}return null;};}function patchUpdates(_0x45894f){return function(_0x457255){try{jsonpatch[_0x09f2('0x20')](_0x457255,_0x45894f,!![]);}catch(_0x1caae0){return BPromise[_0x09f2('0x21')](_0x1caae0);}return _0x457255['save']();};}function saveUpdates(_0x5945f6,_0x215679){return function(_0x5693fa){if(_0x5693fa){return _0x5693fa[_0x09f2('0x22')](_0x5945f6)[_0x09f2('0x23')](function(_0x11493c){return _0x11493c;});}return null;};}function removeEntity(_0x4b2aba,_0x520ab4){return function(_0xb5bbae){if(_0xb5bbae){return _0xb5bbae['destroy']()[_0x09f2('0x23')](function(){_0x4b2aba[_0x09f2('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x27e3b7,_0x5c3ed7){return function(_0x58136e){if(!_0x58136e){_0x27e3b7['sendStatus'](0x194);}return _0x58136e;};}function handleError(_0x444a04,_0x266fb2){_0x266fb2=_0x266fb2||0x1f4;return function(_0x1cf2dd){logger[_0x09f2('0x24')](_0x1cf2dd[_0x09f2('0x25')]);if(_0x1cf2dd['name']){delete _0x1cf2dd[_0x09f2('0x26')];}_0x444a04[_0x09f2('0x18')](_0x266fb2)[_0x09f2('0x27')](_0x1cf2dd);};}exports[_0x09f2('0x28')]=function(_0x52624a,_0x4b3c2e){var _0x11d5e1={},_0x11fea0={},_0x253f63={'count':0x0,'rows':[]};var _0x1c25af=_[_0x09f2('0x29')](db[_0x09f2('0x2a')][_0x09f2('0x2b')],function(_0x1cab4b){return{'name':_0x1cab4b['fieldName'],'type':_0x1cab4b[_0x09f2('0x2c')][_0x09f2('0x2d')]};});_0x11fea0[_0x09f2('0x2e')]=_[_0x09f2('0x29')](_0x1c25af,_0x09f2('0x26'));_0x11fea0['query']=_[_0x09f2('0x2f')](_0x52624a[_0x09f2('0x30')]);_0x11fea0[_0x09f2('0x31')]=_['intersection'](_0x11fea0[_0x09f2('0x2e')],_0x11fea0[_0x09f2('0x30')]);_0x11d5e1[_0x09f2('0x32')]=_['intersection'](_0x11fea0[_0x09f2('0x2e')],qs['fields'](_0x52624a[_0x09f2('0x30')]['fields']));_0x11d5e1[_0x09f2('0x32')]=_0x11d5e1[_0x09f2('0x32')][_0x09f2('0x33')]?_0x11d5e1[_0x09f2('0x32')]:_0x11fea0['model'];if(!_0x52624a[_0x09f2('0x30')]['hasOwnProperty']('nolimit')){_0x11d5e1['limit']=qs[_0x09f2('0x1e')](_0x52624a[_0x09f2('0x30')][_0x09f2('0x1e')]);_0x11d5e1['offset']=qs['offset'](_0x52624a[_0x09f2('0x30')][_0x09f2('0x1b')]);}_0x11d5e1[_0x09f2('0x34')]=qs[_0x09f2('0x35')](_0x52624a['query'][_0x09f2('0x35')]);_0x11d5e1[_0x09f2('0x36')]=qs[_0x09f2('0x31')](_[_0x09f2('0x37')](_0x52624a['query'],_0x11fea0[_0x09f2('0x31')]),_0x1c25af);if(_0x52624a['query']['filter']){_0x11d5e1[_0x09f2('0x36')]=_['merge'](_0x11d5e1[_0x09f2('0x36')],{'$or':_[_0x09f2('0x29')](_0x1c25af,function(_0x15a041){if(_0x15a041[_0x09f2('0x2c')]!=='VIRTUAL'){var _0xe67b06={};_0xe67b06[_0x15a041[_0x09f2('0x26')]]={'$like':'%'+_0x52624a[_0x09f2('0x30')][_0x09f2('0x38')]+'%'};return _0xe67b06;}})});}_0x11d5e1=_[_0x09f2('0x39')]({},_0x11d5e1,_0x52624a[_0x09f2('0x3a')]);var _0x2ff8ae={'where':_0x11d5e1['where']};return db[_0x09f2('0x2a')][_0x09f2('0x1d')](_0x2ff8ae)[_0x09f2('0x23')](function(_0x20799a){_0x253f63[_0x09f2('0x1d')]=_0x20799a;if(_0x52624a[_0x09f2('0x30')]['includeAll']){_0x11d5e1['include']=[{'all':!![]}];}return db[_0x09f2('0x2a')][_0x09f2('0x3b')](_0x11d5e1);})[_0x09f2('0x23')](function(_0x3e80fe){_0x253f63[_0x09f2('0x3c')]=_0x3e80fe;return _0x253f63;})[_0x09f2('0x23')](respondWithFilteredResult(_0x4b3c2e,_0x11d5e1))[_0x09f2('0x3d')](handleError(_0x4b3c2e,null));};exports[_0x09f2('0x3e')]=function(_0x180912,_0x3b4402){var _0x5d31d2={'raw':!![],'where':{'id':_0x180912[_0x09f2('0x3f')]['id']}},_0x1c6257={};_0x1c6257['model']=_[_0x09f2('0x2f')](db[_0x09f2('0x2a')][_0x09f2('0x2b')]);_0x1c6257[_0x09f2('0x30')]=_[_0x09f2('0x2f')](_0x180912[_0x09f2('0x30')]);_0x1c6257[_0x09f2('0x31')]=_[_0x09f2('0x40')](_0x1c6257[_0x09f2('0x2e')],_0x1c6257[_0x09f2('0x30')]);_0x5d31d2[_0x09f2('0x32')]=_[_0x09f2('0x40')](_0x1c6257[_0x09f2('0x2e')],qs[_0x09f2('0x41')](_0x180912[_0x09f2('0x30')][_0x09f2('0x41')]));_0x5d31d2['attributes']=_0x5d31d2[_0x09f2('0x32')]['length']?_0x5d31d2['attributes']:_0x1c6257['model'];if(_0x180912[_0x09f2('0x30')][_0x09f2('0x42')]){_0x5d31d2[_0x09f2('0x43')]=[{'all':!![]}];}_0x5d31d2=_['merge']({},_0x5d31d2,_0x180912['options']);return db[_0x09f2('0x2a')][_0x09f2('0x44')](_0x5d31d2)[_0x09f2('0x23')](handleEntityNotFound(_0x3b4402,null))[_0x09f2('0x23')](respondWithResult(_0x3b4402,null))[_0x09f2('0x3d')](handleError(_0x3b4402,null));};exports[_0x09f2('0x45')]=function(_0x1cdce7,_0x375b26){return db[_0x09f2('0x2a')][_0x09f2('0x45')](_0x1cdce7['body'],{})[_0x09f2('0x23')](respondWithResult(_0x375b26,0xc9))['catch'](handleError(_0x375b26,null));};exports[_0x09f2('0x22')]=function(_0x261907,_0x2fa4f0){if(_0x261907[_0x09f2('0x46')]['id']){delete _0x261907[_0x09f2('0x46')]['id'];}return db[_0x09f2('0x2a')]['find']({'where':{'id':_0x261907[_0x09f2('0x3f')]['id']}})['then'](handleEntityNotFound(_0x2fa4f0,null))[_0x09f2('0x23')](saveUpdates(_0x261907[_0x09f2('0x46')],null))[_0x09f2('0x23')](respondWithResult(_0x2fa4f0,null))[_0x09f2('0x3d')](handleError(_0x2fa4f0,null));};exports['destroy']=function(_0x4051e0,_0x593cab){return db[_0x09f2('0x2a')][_0x09f2('0x44')]({'where':{'id':_0x4051e0[_0x09f2('0x3f')]['id']}})[_0x09f2('0x23')](handleEntityNotFound(_0x593cab,null))['then'](removeEntity(_0x593cab,null))['catch'](handleError(_0x593cab,null));};