Built motion from commit 0d14f64c.|2.6.34
[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 _0xac3b=['SugarcrmField','includeAll','include','findAll','rows','catch','params','keys','find','create','body','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/license/util','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','then','destroy','error','name','send','index','map','rawAttributes','fieldName','type','key','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','order','sort','pick','filter','where','merge','VIRTUAL','options'];(function(_0x2fbcf6,_0x2e7155){var _0x3e7265=function(_0x15a3c3){while(--_0x15a3c3){_0x2fbcf6['push'](_0x2fbcf6['shift']());}};_0x3e7265(++_0x2e7155);}(_0xac3b,0xe9));var _0xbac3=function(_0x466247,_0x5d69e3){_0x466247=_0x466247-0x0;var _0x4b352e=_0xac3b[_0x466247];return _0x4b352e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbac3('0x0'));var zipdir=require(_0xbac3('0x1'));var jsonpatch=require(_0xbac3('0x2'));var rp=require(_0xbac3('0x3'));var moment=require(_0xbac3('0x4'));var BPromise=require(_0xbac3('0x5'));var Mustache=require(_0xbac3('0x6'));var util=require(_0xbac3('0x7'));var path=require(_0xbac3('0x8'));var sox=require('sox');var csv=require(_0xbac3('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xbac3('0xa'));var _=require('lodash');var squel=require(_0xbac3('0xb'));var crypto=require(_0xbac3('0xc'));var jsforce=require(_0xbac3('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xbac3('0x9'));var querystring=require(_0xbac3('0xe'));var Papa=require(_0xbac3('0xf'));var Redis=require(_0xbac3('0x10'));var authService=require(_0xbac3('0x11'));var qs=require(_0xbac3('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbac3('0x13'));var logger=require('../../config/logger')(_0xbac3('0x14'));var utils=require(_0xbac3('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xbac3('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x22782d,_0x4b838a){_0x4b838a=_0x4b838a||0xcc;return function(_0x48491c){if(_0x48491c){return _0x22782d[_0xbac3('0x17')](_0x4b838a);}return _0x22782d[_0xbac3('0x18')](_0x4b838a)[_0xbac3('0x19')]();};}function respondWithResult(_0xd9996e,_0x3e8a52){_0x3e8a52=_0x3e8a52||0xc8;return function(_0x56231b){if(_0x56231b){return _0xd9996e[_0xbac3('0x18')](_0x3e8a52)[_0xbac3('0x1a')](_0x56231b);}};}function respondWithFilteredResult(_0x1136f1,_0x28ad44){return function(_0x4a7903){if(_0x4a7903){var _0x3ccf74=typeof _0x28ad44[_0xbac3('0x1b')]==='undefined'&&typeof _0x28ad44[_0xbac3('0x1c')]===_0xbac3('0x1d');var _0x572551=_0x4a7903[_0xbac3('0x1e')];var _0x1680d1=_0x3ccf74?0x0:_0x28ad44[_0xbac3('0x1b')];var _0x5dd215=_0x3ccf74?_0x4a7903[_0xbac3('0x1e')]:_0x28ad44['offset']+_0x28ad44[_0xbac3('0x1c')];var _0x14342c;if(_0x5dd215>=_0x572551){_0x5dd215=_0x572551;_0x14342c=0xc8;}else{_0x14342c=0xce;}_0x1136f1[_0xbac3('0x18')](_0x14342c);return _0x1136f1[_0xbac3('0x1f')](_0xbac3('0x20'),_0x1680d1+'-'+_0x5dd215+'/'+_0x572551)[_0xbac3('0x1a')](_0x4a7903);}return null;};}function patchUpdates(_0x46d5a4){return function(_0x585314){try{jsonpatch[_0xbac3('0x21')](_0x585314,_0x46d5a4,!![]);}catch(_0x53a1dd){return BPromise[_0xbac3('0x22')](_0x53a1dd);}return _0x585314[_0xbac3('0x23')]();};}function saveUpdates(_0x1d6893,_0x564eef){return function(_0x50ae90){if(_0x50ae90){return _0x50ae90['update'](_0x1d6893)[_0xbac3('0x24')](function(_0x1e233b){return _0x1e233b;});}return null;};}function removeEntity(_0xbd482c,_0x31ee34){return function(_0x48e52b){if(_0x48e52b){return _0x48e52b[_0xbac3('0x25')]()[_0xbac3('0x24')](function(){_0xbd482c['status'](0xcc)[_0xbac3('0x19')]();});}};}function handleEntityNotFound(_0x1b80f8,_0x152651){return function(_0x3d2ecf){if(!_0x3d2ecf){_0x1b80f8['sendStatus'](0x194);}return _0x3d2ecf;};}function handleError(_0x223853,_0x12ef7e){_0x12ef7e=_0x12ef7e||0x1f4;return function(_0x50e61b){logger[_0xbac3('0x26')](_0x50e61b['stack']);if(_0x50e61b['name']){delete _0x50e61b[_0xbac3('0x27')];}_0x223853['status'](_0x12ef7e)[_0xbac3('0x28')](_0x50e61b);};}exports[_0xbac3('0x29')]=function(_0x1c336b,_0x3e9d4e){var _0x460c91={},_0x136f04={},_0x391234={'count':0x0,'rows':[]};var _0x3ffcc7=_[_0xbac3('0x2a')](db['SugarcrmField'][_0xbac3('0x2b')],function(_0x427021){return{'name':_0x427021[_0xbac3('0x2c')],'type':_0x427021[_0xbac3('0x2d')][_0xbac3('0x2e')]};});_0x136f04['model']=_[_0xbac3('0x2a')](_0x3ffcc7,_0xbac3('0x27'));_0x136f04[_0xbac3('0x2f')]=_['keys'](_0x1c336b[_0xbac3('0x2f')]);_0x136f04[_0xbac3('0x30')]=_[_0xbac3('0x31')](_0x136f04[_0xbac3('0x32')],_0x136f04['query']);_0x460c91['attributes']=_['intersection'](_0x136f04[_0xbac3('0x32')],qs[_0xbac3('0x33')](_0x1c336b[_0xbac3('0x2f')][_0xbac3('0x33')]));_0x460c91['attributes']=_0x460c91[_0xbac3('0x34')][_0xbac3('0x35')]?_0x460c91[_0xbac3('0x34')]:_0x136f04[_0xbac3('0x32')];if(!_0x1c336b[_0xbac3('0x2f')][_0xbac3('0x36')]('nolimit')){_0x460c91[_0xbac3('0x1c')]=qs[_0xbac3('0x1c')](_0x1c336b['query']['limit']);_0x460c91[_0xbac3('0x1b')]=qs[_0xbac3('0x1b')](_0x1c336b['query'][_0xbac3('0x1b')]);}_0x460c91[_0xbac3('0x37')]=qs[_0xbac3('0x38')](_0x1c336b[_0xbac3('0x2f')][_0xbac3('0x38')]);_0x460c91['where']=qs[_0xbac3('0x30')](_[_0xbac3('0x39')](_0x1c336b[_0xbac3('0x2f')],_0x136f04['filters']),_0x3ffcc7);if(_0x1c336b[_0xbac3('0x2f')][_0xbac3('0x3a')]){_0x460c91[_0xbac3('0x3b')]=_[_0xbac3('0x3c')](_0x460c91[_0xbac3('0x3b')],{'$or':_['map'](_0x3ffcc7,function(_0xb6cf21){if(_0xb6cf21[_0xbac3('0x2d')]!==_0xbac3('0x3d')){var _0x4edd8e={};_0x4edd8e[_0xb6cf21['name']]={'$like':'%'+_0x1c336b[_0xbac3('0x2f')][_0xbac3('0x3a')]+'%'};return _0x4edd8e;}})});}_0x460c91=_[_0xbac3('0x3c')]({},_0x460c91,_0x1c336b[_0xbac3('0x3e')]);var _0x432648={'where':_0x460c91[_0xbac3('0x3b')]};return db[_0xbac3('0x3f')][_0xbac3('0x1e')](_0x432648)[_0xbac3('0x24')](function(_0x3881d7){_0x391234[_0xbac3('0x1e')]=_0x3881d7;if(_0x1c336b['query'][_0xbac3('0x40')]){_0x460c91[_0xbac3('0x41')]=[{'all':!![]}];}return db[_0xbac3('0x3f')][_0xbac3('0x42')](_0x460c91);})['then'](function(_0x30551a){_0x391234[_0xbac3('0x43')]=_0x30551a;return _0x391234;})['then'](respondWithFilteredResult(_0x3e9d4e,_0x460c91))[_0xbac3('0x44')](handleError(_0x3e9d4e,null));};exports['show']=function(_0x26f69f,_0x4d82ba){var _0x2a591d={'raw':!![],'where':{'id':_0x26f69f[_0xbac3('0x45')]['id']}},_0x26c0e9={};_0x26c0e9[_0xbac3('0x32')]=_[_0xbac3('0x46')](db[_0xbac3('0x3f')]['rawAttributes']);_0x26c0e9[_0xbac3('0x2f')]=_['keys'](_0x26f69f[_0xbac3('0x2f')]);_0x26c0e9['filters']=_['intersection'](_0x26c0e9['model'],_0x26c0e9[_0xbac3('0x2f')]);_0x2a591d[_0xbac3('0x34')]=_[_0xbac3('0x31')](_0x26c0e9['model'],qs[_0xbac3('0x33')](_0x26f69f['query']['fields']));_0x2a591d[_0xbac3('0x34')]=_0x2a591d[_0xbac3('0x34')]['length']?_0x2a591d[_0xbac3('0x34')]:_0x26c0e9[_0xbac3('0x32')];if(_0x26f69f['query'][_0xbac3('0x40')]){_0x2a591d[_0xbac3('0x41')]=[{'all':!![]}];}_0x2a591d=_[_0xbac3('0x3c')]({},_0x2a591d,_0x26f69f[_0xbac3('0x3e')]);return db[_0xbac3('0x3f')][_0xbac3('0x47')](_0x2a591d)[_0xbac3('0x24')](handleEntityNotFound(_0x4d82ba,null))[_0xbac3('0x24')](respondWithResult(_0x4d82ba,null))['catch'](handleError(_0x4d82ba,null));};exports[_0xbac3('0x48')]=function(_0x2257bf,_0x5c1ac9){return db['SugarcrmField'][_0xbac3('0x48')](_0x2257bf[_0xbac3('0x49')],{})['then'](respondWithResult(_0x5c1ac9,0xc9))[_0xbac3('0x44')](handleError(_0x5c1ac9,null));};exports['update']=function(_0x39473b,_0x3cd926){if(_0x39473b['body']['id']){delete _0x39473b['body']['id'];}return db[_0xbac3('0x3f')]['find']({'where':{'id':_0x39473b['params']['id']}})[_0xbac3('0x24')](handleEntityNotFound(_0x3cd926,null))[_0xbac3('0x24')](saveUpdates(_0x39473b[_0xbac3('0x49')],null))[_0xbac3('0x24')](respondWithResult(_0x3cd926,null))[_0xbac3('0x44')](handleError(_0x3cd926,null));};exports[_0xbac3('0x25')]=function(_0x32b9d4,_0x6e0274){return db['SugarcrmField'][_0xbac3('0x47')]({'where':{'id':_0x32b9d4[_0xbac3('0x45')]['id']}})[_0xbac3('0x24')](handleEntityNotFound(_0x6e0274,null))[_0xbac3('0x24')](removeEntity(_0x6e0274,null))['catch'](handleError(_0x6e0274,null));};