Built motion from commit (unavailable).|2.5.31
[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 _0xb821=['order','sort','pick','filter','where','merge','VIRTUAL','options','include','findAll','show','keys','includeAll','find','catch','body','update','rimraf','zip-dir','moment','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','then','destroy','sendStatus','error','stack','name','send','index','SugarcrmField','rawAttributes','fieldName','type','key','model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x322e14,_0xb0abd){var _0x28c008=function(_0x185bc2){while(--_0x185bc2){_0x322e14['push'](_0x322e14['shift']());}};_0x28c008(++_0xb0abd);}(_0xb821,0xa7));var _0x1b82=function(_0x20fe95,_0x311e9a){_0x20fe95=_0x20fe95-0x0;var _0x39fae8=_0xb821[_0x20fe95];return _0x39fae8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1b82('0x0'));var zipdir=require(_0x1b82('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x1b82('0x2'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x1b82('0x3'));var path=require(_0x1b82('0x4'));var sox=require(_0x1b82('0x5'));var csv=require(_0x1b82('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1b82('0x7'));var _=require(_0x1b82('0x8'));var squel=require(_0x1b82('0x9'));var crypto=require(_0x1b82('0xa'));var jsforce=require(_0x1b82('0xb'));var deskjs=require(_0x1b82('0xc'));var toCsv=require(_0x1b82('0x6'));var querystring=require(_0x1b82('0xd'));var Papa=require(_0x1b82('0xe'));var Redis=require('ioredis');var authService=require(_0x1b82('0xf'));var qs=require(_0x1b82('0x10'));var as=require(_0x1b82('0x11'));var hardwareService=require(_0x1b82('0x12'));var logger=require(_0x1b82('0x13'))(_0x1b82('0x14'));var utils=require(_0x1b82('0x15'));var config=require(_0x1b82('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x1b82('0x17'))['db'];function respondWithStatusCode(_0x241d11,_0x2391f5){_0x2391f5=_0x2391f5||0xcc;return function(_0x61b6eb){if(_0x61b6eb){return _0x241d11['sendStatus'](_0x2391f5);}return _0x241d11[_0x1b82('0x18')](_0x2391f5)['end']();};}function respondWithResult(_0x54915f,_0x1e553a){_0x1e553a=_0x1e553a||0xc8;return function(_0x4bf75b){if(_0x4bf75b){return _0x54915f[_0x1b82('0x18')](_0x1e553a)[_0x1b82('0x19')](_0x4bf75b);}};}function respondWithFilteredResult(_0x5d4cf1,_0x46c2cf){return function(_0x5dab7d){if(_0x5dab7d){var _0x563261=typeof _0x46c2cf[_0x1b82('0x1a')]==='undefined'&&typeof _0x46c2cf[_0x1b82('0x1b')]===_0x1b82('0x1c');var _0xf42818=_0x5dab7d['count'];var _0x514082=_0x563261?0x0:_0x46c2cf[_0x1b82('0x1a')];var _0x5d66c3=_0x563261?_0x5dab7d[_0x1b82('0x1d')]:_0x46c2cf[_0x1b82('0x1a')]+_0x46c2cf[_0x1b82('0x1b')];var _0x594a63;if(_0x5d66c3>=_0xf42818){_0x5d66c3=_0xf42818;_0x594a63=0xc8;}else{_0x594a63=0xce;}_0x5d4cf1[_0x1b82('0x18')](_0x594a63);return _0x5d4cf1[_0x1b82('0x1e')](_0x1b82('0x1f'),_0x514082+'-'+_0x5d66c3+'/'+_0xf42818)[_0x1b82('0x19')](_0x5dab7d);}return null;};}function patchUpdates(_0x10d45c){return function(_0x47e99b){try{jsonpatch[_0x1b82('0x20')](_0x47e99b,_0x10d45c,!![]);}catch(_0x1892b0){return BPromise[_0x1b82('0x21')](_0x1892b0);}return _0x47e99b[_0x1b82('0x22')]();};}function saveUpdates(_0x26e481,_0x31fd64){return function(_0x2d07f4){if(_0x2d07f4){return _0x2d07f4['update'](_0x26e481)[_0x1b82('0x23')](function(_0x233740){return _0x233740;});}return null;};}function removeEntity(_0x5b8d09,_0x561d78){return function(_0x225b81){if(_0x225b81){return _0x225b81[_0x1b82('0x24')]()['then'](function(){_0x5b8d09[_0x1b82('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5cd458,_0x5f556b){return function(_0xf2e556){if(!_0xf2e556){_0x5cd458[_0x1b82('0x25')](0x194);}return _0xf2e556;};}function handleError(_0xfd00d1,_0x257b79){_0x257b79=_0x257b79||0x1f4;return function(_0x548a3b){logger[_0x1b82('0x26')](_0x548a3b[_0x1b82('0x27')]);if(_0x548a3b[_0x1b82('0x28')]){delete _0x548a3b[_0x1b82('0x28')];}_0xfd00d1[_0x1b82('0x18')](_0x257b79)[_0x1b82('0x29')](_0x548a3b);};}exports[_0x1b82('0x2a')]=function(_0x21ea34,_0x39641a){var _0x1f9c6b={},_0x2fe45d={},_0x37275f={'count':0x0,'rows':[]};var _0x466441=_['map'](db[_0x1b82('0x2b')][_0x1b82('0x2c')],function(_0x155a34){return{'name':_0x155a34[_0x1b82('0x2d')],'type':_0x155a34[_0x1b82('0x2e')][_0x1b82('0x2f')]};});_0x2fe45d[_0x1b82('0x30')]=_[_0x1b82('0x31')](_0x466441,_0x1b82('0x28'));_0x2fe45d[_0x1b82('0x32')]=_['keys'](_0x21ea34[_0x1b82('0x32')]);_0x2fe45d[_0x1b82('0x33')]=_[_0x1b82('0x34')](_0x2fe45d[_0x1b82('0x30')],_0x2fe45d['query']);_0x1f9c6b[_0x1b82('0x35')]=_[_0x1b82('0x34')](_0x2fe45d['model'],qs[_0x1b82('0x36')](_0x21ea34[_0x1b82('0x32')][_0x1b82('0x36')]));_0x1f9c6b['attributes']=_0x1f9c6b['attributes'][_0x1b82('0x37')]?_0x1f9c6b['attributes']:_0x2fe45d['model'];if(!_0x21ea34[_0x1b82('0x32')][_0x1b82('0x38')](_0x1b82('0x39'))){_0x1f9c6b['limit']=qs[_0x1b82('0x1b')](_0x21ea34[_0x1b82('0x32')][_0x1b82('0x1b')]);_0x1f9c6b[_0x1b82('0x1a')]=qs['offset'](_0x21ea34[_0x1b82('0x32')][_0x1b82('0x1a')]);}_0x1f9c6b[_0x1b82('0x3a')]=qs['sort'](_0x21ea34['query'][_0x1b82('0x3b')]);_0x1f9c6b['where']=qs[_0x1b82('0x33')](_[_0x1b82('0x3c')](_0x21ea34[_0x1b82('0x32')],_0x2fe45d[_0x1b82('0x33')]),_0x466441);if(_0x21ea34[_0x1b82('0x32')][_0x1b82('0x3d')]){_0x1f9c6b[_0x1b82('0x3e')]=_[_0x1b82('0x3f')](_0x1f9c6b['where'],{'$or':_['map'](_0x466441,function(_0x18b624){if(_0x18b624['type']!==_0x1b82('0x40')){var _0x592449={};_0x592449[_0x18b624[_0x1b82('0x28')]]={'$like':'%'+_0x21ea34[_0x1b82('0x32')][_0x1b82('0x3d')]+'%'};return _0x592449;}})});}_0x1f9c6b=_[_0x1b82('0x3f')]({},_0x1f9c6b,_0x21ea34[_0x1b82('0x41')]);var _0x202bb4={'where':_0x1f9c6b['where']};return db[_0x1b82('0x2b')]['count'](_0x202bb4)[_0x1b82('0x23')](function(_0x4e5659){_0x37275f[_0x1b82('0x1d')]=_0x4e5659;if(_0x21ea34['query']['includeAll']){_0x1f9c6b[_0x1b82('0x42')]=[{'all':!![]}];}return db[_0x1b82('0x2b')][_0x1b82('0x43')](_0x1f9c6b);})[_0x1b82('0x23')](function(_0x3eb429){_0x37275f['rows']=_0x3eb429;return _0x37275f;})[_0x1b82('0x23')](respondWithFilteredResult(_0x39641a,_0x1f9c6b))['catch'](handleError(_0x39641a,null));};exports[_0x1b82('0x44')]=function(_0x2fcf04,_0x17e47f){var _0x3adf9c={'raw':!![],'where':{'id':_0x2fcf04['params']['id']}},_0x365ab4={};_0x365ab4[_0x1b82('0x30')]=_['keys'](db[_0x1b82('0x2b')][_0x1b82('0x2c')]);_0x365ab4['query']=_[_0x1b82('0x45')](_0x2fcf04[_0x1b82('0x32')]);_0x365ab4[_0x1b82('0x33')]=_[_0x1b82('0x34')](_0x365ab4[_0x1b82('0x30')],_0x365ab4[_0x1b82('0x32')]);_0x3adf9c[_0x1b82('0x35')]=_['intersection'](_0x365ab4[_0x1b82('0x30')],qs['fields'](_0x2fcf04[_0x1b82('0x32')][_0x1b82('0x36')]));_0x3adf9c[_0x1b82('0x35')]=_0x3adf9c[_0x1b82('0x35')][_0x1b82('0x37')]?_0x3adf9c[_0x1b82('0x35')]:_0x365ab4[_0x1b82('0x30')];if(_0x2fcf04[_0x1b82('0x32')][_0x1b82('0x46')]){_0x3adf9c[_0x1b82('0x42')]=[{'all':!![]}];}_0x3adf9c=_[_0x1b82('0x3f')]({},_0x3adf9c,_0x2fcf04[_0x1b82('0x41')]);return db[_0x1b82('0x2b')][_0x1b82('0x47')](_0x3adf9c)['then'](handleEntityNotFound(_0x17e47f,null))['then'](respondWithResult(_0x17e47f,null))[_0x1b82('0x48')](handleError(_0x17e47f,null));};exports['create']=function(_0x12d9ac,_0x3df0af){return db[_0x1b82('0x2b')]['create'](_0x12d9ac[_0x1b82('0x49')],{})['then'](respondWithResult(_0x3df0af,0xc9))['catch'](handleError(_0x3df0af,null));};exports[_0x1b82('0x4a')]=function(_0x2aadf7,_0x242324){if(_0x2aadf7['body']['id']){delete _0x2aadf7[_0x1b82('0x49')]['id'];}return db[_0x1b82('0x2b')]['find']({'where':{'id':_0x2aadf7['params']['id']}})[_0x1b82('0x23')](handleEntityNotFound(_0x242324,null))[_0x1b82('0x23')](saveUpdates(_0x2aadf7[_0x1b82('0x49')],null))['then'](respondWithResult(_0x242324,null))[_0x1b82('0x48')](handleError(_0x242324,null));};exports[_0x1b82('0x24')]=function(_0x31fb5d,_0x29f9ae){return db[_0x1b82('0x2b')][_0x1b82('0x47')]({'where':{'id':_0x31fb5d['params']['id']}})[_0x1b82('0x23')](handleEntityNotFound(_0x29f9ae,null))['then'](removeEntity(_0x29f9ae,null))[_0x1b82('0x48')](handleError(_0x29f9ae,null));};