Built motion from commit 497d3d92.|2.5.43
[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 _0x76cd=['order','sort','filters','pick','filter','where','merge','type','VIRTUAL','options','includeAll','SugarcrmField','findAll','rows','catch','show','fields','include','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','fs-extra','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','offset','undefined','limit','count','set','json','reject','save','update','destroy','then','sendStatus','error','stack','name','send','rawAttributes','fieldName','key','model','map','keys','query','intersection','attributes','length','nolimit'];(function(_0x3a3a6a,_0x5eb6a9){var _0xa89294=function(_0x55d78c){while(--_0x55d78c){_0x3a3a6a['push'](_0x3a3a6a['shift']());}};_0xa89294(++_0x5eb6a9);}(_0x76cd,0x192));var _0xd76c=function(_0x546118,_0xe7b54a){_0x546118=_0x546118-0x0;var _0x1078fc=_0x76cd[_0x546118];return _0x1078fc;};'use strict';var emlformat=require(_0xd76c('0x0'));var rimraf=require(_0xd76c('0x1'));var zipdir=require(_0xd76c('0x2'));var jsonpatch=require(_0xd76c('0x3'));var rp=require(_0xd76c('0x4'));var moment=require('moment');var BPromise=require(_0xd76c('0x5'));var Mustache=require(_0xd76c('0x6'));var util=require('util');var path=require(_0xd76c('0x7'));var sox=require(_0xd76c('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xd76c('0x9'));var _=require('lodash');var squel=require(_0xd76c('0xa'));var crypto=require(_0xd76c('0xb'));var jsforce=require(_0xd76c('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xd76c('0xd'));var Papa=require(_0xd76c('0xe'));var Redis=require(_0xd76c('0xf'));var authService=require(_0xd76c('0x10'));var qs=require(_0xd76c('0x11'));var as=require(_0xd76c('0x12'));var hardwareService=require(_0xd76c('0x13'));var logger=require('../../config/logger')(_0xd76c('0x14'));var utils=require(_0xd76c('0x15'));var config=require(_0xd76c('0x16'));var licenseUtil=require(_0xd76c('0x17'));var db=require(_0xd76c('0x18'))['db'];function respondWithStatusCode(_0xed113b,_0x37eb02){_0x37eb02=_0x37eb02||0xcc;return function(_0xca50c9){if(_0xca50c9){return _0xed113b['sendStatus'](_0x37eb02);}return _0xed113b[_0xd76c('0x19')](_0x37eb02)[_0xd76c('0x1a')]();};}function respondWithResult(_0x37be66,_0xb0b16e){_0xb0b16e=_0xb0b16e||0xc8;return function(_0x4f6c9b){if(_0x4f6c9b){return _0x37be66[_0xd76c('0x19')](_0xb0b16e)['json'](_0x4f6c9b);}};}function respondWithFilteredResult(_0x4ee10f,_0x366bbf){return function(_0x2b5f5c){if(_0x2b5f5c){var _0x348f51=typeof _0x366bbf[_0xd76c('0x1b')]===_0xd76c('0x1c')&&typeof _0x366bbf[_0xd76c('0x1d')]==='undefined';var _0x58aaf1=_0x2b5f5c[_0xd76c('0x1e')];var _0xe46c25=_0x348f51?0x0:_0x366bbf[_0xd76c('0x1b')];var _0x559cb7=_0x348f51?_0x2b5f5c[_0xd76c('0x1e')]:_0x366bbf['offset']+_0x366bbf[_0xd76c('0x1d')];var _0x193b48;if(_0x559cb7>=_0x58aaf1){_0x559cb7=_0x58aaf1;_0x193b48=0xc8;}else{_0x193b48=0xce;}_0x4ee10f[_0xd76c('0x19')](_0x193b48);return _0x4ee10f[_0xd76c('0x1f')]('Content-Range',_0xe46c25+'-'+_0x559cb7+'/'+_0x58aaf1)[_0xd76c('0x20')](_0x2b5f5c);}return null;};}function patchUpdates(_0x4bf5a2){return function(_0x2d1d24){try{jsonpatch['apply'](_0x2d1d24,_0x4bf5a2,!![]);}catch(_0x536a71){return BPromise[_0xd76c('0x21')](_0x536a71);}return _0x2d1d24[_0xd76c('0x22')]();};}function saveUpdates(_0x6ab639,_0x18d090){return function(_0x49e649){if(_0x49e649){return _0x49e649[_0xd76c('0x23')](_0x6ab639)['then'](function(_0x29d8ea){return _0x29d8ea;});}return null;};}function removeEntity(_0x58a271,_0x4cb38e){return function(_0xefd80f){if(_0xefd80f){return _0xefd80f[_0xd76c('0x24')]()[_0xd76c('0x25')](function(){_0x58a271[_0xd76c('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5e28a8,_0x4da4f3){return function(_0x17f7fc){if(!_0x17f7fc){_0x5e28a8[_0xd76c('0x26')](0x194);}return _0x17f7fc;};}function handleError(_0xc49f10,_0x3e54d5){_0x3e54d5=_0x3e54d5||0x1f4;return function(_0x32b460){logger[_0xd76c('0x27')](_0x32b460[_0xd76c('0x28')]);if(_0x32b460[_0xd76c('0x29')]){delete _0x32b460[_0xd76c('0x29')];}_0xc49f10[_0xd76c('0x19')](_0x3e54d5)[_0xd76c('0x2a')](_0x32b460);};}exports['index']=function(_0xdf3dc,_0x50d77a){var _0x512e03={},_0x2cd969={},_0x13547f={'count':0x0,'rows':[]};var _0x41330f=_['map'](db['SugarcrmField'][_0xd76c('0x2b')],function(_0x22ecab){return{'name':_0x22ecab[_0xd76c('0x2c')],'type':_0x22ecab['type'][_0xd76c('0x2d')]};});_0x2cd969[_0xd76c('0x2e')]=_[_0xd76c('0x2f')](_0x41330f,'name');_0x2cd969['query']=_[_0xd76c('0x30')](_0xdf3dc[_0xd76c('0x31')]);_0x2cd969['filters']=_[_0xd76c('0x32')](_0x2cd969['model'],_0x2cd969['query']);_0x512e03[_0xd76c('0x33')]=_[_0xd76c('0x32')](_0x2cd969[_0xd76c('0x2e')],qs['fields'](_0xdf3dc[_0xd76c('0x31')]['fields']));_0x512e03[_0xd76c('0x33')]=_0x512e03[_0xd76c('0x33')][_0xd76c('0x34')]?_0x512e03[_0xd76c('0x33')]:_0x2cd969[_0xd76c('0x2e')];if(!_0xdf3dc[_0xd76c('0x31')]['hasOwnProperty'](_0xd76c('0x35'))){_0x512e03['limit']=qs[_0xd76c('0x1d')](_0xdf3dc[_0xd76c('0x31')][_0xd76c('0x1d')]);_0x512e03['offset']=qs['offset'](_0xdf3dc['query']['offset']);}_0x512e03[_0xd76c('0x36')]=qs[_0xd76c('0x37')](_0xdf3dc[_0xd76c('0x31')][_0xd76c('0x37')]);_0x512e03['where']=qs[_0xd76c('0x38')](_[_0xd76c('0x39')](_0xdf3dc[_0xd76c('0x31')],_0x2cd969['filters']),_0x41330f);if(_0xdf3dc['query'][_0xd76c('0x3a')]){_0x512e03[_0xd76c('0x3b')]=_[_0xd76c('0x3c')](_0x512e03[_0xd76c('0x3b')],{'$or':_[_0xd76c('0x2f')](_0x41330f,function(_0x19b96b){if(_0x19b96b[_0xd76c('0x3d')]!==_0xd76c('0x3e')){var _0x28da0d={};_0x28da0d[_0x19b96b[_0xd76c('0x29')]]={'$like':'%'+_0xdf3dc[_0xd76c('0x31')][_0xd76c('0x3a')]+'%'};return _0x28da0d;}})});}_0x512e03=_[_0xd76c('0x3c')]({},_0x512e03,_0xdf3dc[_0xd76c('0x3f')]);var _0x5c29a6={'where':_0x512e03['where']};return db['SugarcrmField'][_0xd76c('0x1e')](_0x5c29a6)[_0xd76c('0x25')](function(_0x4147c7){_0x13547f[_0xd76c('0x1e')]=_0x4147c7;if(_0xdf3dc[_0xd76c('0x31')][_0xd76c('0x40')]){_0x512e03['include']=[{'all':!![]}];}return db[_0xd76c('0x41')][_0xd76c('0x42')](_0x512e03);})['then'](function(_0x2f073e){_0x13547f[_0xd76c('0x43')]=_0x2f073e;return _0x13547f;})[_0xd76c('0x25')](respondWithFilteredResult(_0x50d77a,_0x512e03))[_0xd76c('0x44')](handleError(_0x50d77a,null));};exports[_0xd76c('0x45')]=function(_0x57aa9f,_0x41df08){var _0x5bbf9b={'raw':!![],'where':{'id':_0x57aa9f['params']['id']}},_0x1b9ebe={};_0x1b9ebe[_0xd76c('0x2e')]=_['keys'](db['SugarcrmField'][_0xd76c('0x2b')]);_0x1b9ebe[_0xd76c('0x31')]=_[_0xd76c('0x30')](_0x57aa9f[_0xd76c('0x31')]);_0x1b9ebe[_0xd76c('0x38')]=_['intersection'](_0x1b9ebe[_0xd76c('0x2e')],_0x1b9ebe[_0xd76c('0x31')]);_0x5bbf9b[_0xd76c('0x33')]=_[_0xd76c('0x32')](_0x1b9ebe['model'],qs[_0xd76c('0x46')](_0x57aa9f[_0xd76c('0x31')][_0xd76c('0x46')]));_0x5bbf9b['attributes']=_0x5bbf9b[_0xd76c('0x33')][_0xd76c('0x34')]?_0x5bbf9b[_0xd76c('0x33')]:_0x1b9ebe[_0xd76c('0x2e')];if(_0x57aa9f[_0xd76c('0x31')][_0xd76c('0x40')]){_0x5bbf9b[_0xd76c('0x47')]=[{'all':!![]}];}_0x5bbf9b=_[_0xd76c('0x3c')]({},_0x5bbf9b,_0x57aa9f[_0xd76c('0x3f')]);return db[_0xd76c('0x41')][_0xd76c('0x48')](_0x5bbf9b)[_0xd76c('0x25')](handleEntityNotFound(_0x41df08,null))[_0xd76c('0x25')](respondWithResult(_0x41df08,null))[_0xd76c('0x44')](handleError(_0x41df08,null));};exports[_0xd76c('0x49')]=function(_0x4e9c27,_0x50f9b9){return db[_0xd76c('0x41')][_0xd76c('0x49')](_0x4e9c27[_0xd76c('0x4a')],{})[_0xd76c('0x25')](respondWithResult(_0x50f9b9,0xc9))[_0xd76c('0x44')](handleError(_0x50f9b9,null));};exports['update']=function(_0x3eb014,_0x391ea5){if(_0x3eb014[_0xd76c('0x4a')]['id']){delete _0x3eb014['body']['id'];}return db[_0xd76c('0x41')][_0xd76c('0x48')]({'where':{'id':_0x3eb014[_0xd76c('0x4b')]['id']}})['then'](handleEntityNotFound(_0x391ea5,null))[_0xd76c('0x25')](saveUpdates(_0x3eb014[_0xd76c('0x4a')],null))[_0xd76c('0x25')](respondWithResult(_0x391ea5,null))[_0xd76c('0x44')](handleError(_0x391ea5,null));};exports['destroy']=function(_0x133b93,_0x44bd24){return db['SugarcrmField'][_0xd76c('0x48')]({'where':{'id':_0x133b93[_0xd76c('0x4b')]['id']}})[_0xd76c('0x25')](handleEntityNotFound(_0x44bd24,null))['then'](removeEntity(_0x44bd24,null))[_0xd76c('0x44')](handleError(_0x44bd24,null));};