Built motion from commit 64440dd5.|2.6.29
[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 _0xbf0a=['create','body','find','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','apply','reject','save','update','then','destroy','end','error','stack','name','send','index','map','rawAttributes','fieldName','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','VIRTUAL','filter','options','SugarcrmField','include','findAll','rows','catch','show','params','includeAll'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xbf0a,0xa3));var _0xabf0=function(_0x4e1301,_0x31d640){_0x4e1301=_0x4e1301-0x0;var _0x161d46=_0xbf0a[_0x4e1301];return _0x161d46;};'use strict';var emlformat=require(_0xabf0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xabf0('0x1'));var jsonpatch=require(_0xabf0('0x2'));var rp=require(_0xabf0('0x3'));var moment=require(_0xabf0('0x4'));var BPromise=require(_0xabf0('0x5'));var Mustache=require(_0xabf0('0x6'));var util=require(_0xabf0('0x7'));var path=require(_0xabf0('0x8'));var sox=require(_0xabf0('0x9'));var csv=require(_0xabf0('0xa'));var ejs=require(_0xabf0('0xb'));var fs=require('fs');var fs_extra=require(_0xabf0('0xc'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xabf0('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xabf0('0xe'));var toCsv=require('to-csv');var querystring=require(_0xabf0('0xf'));var Papa=require(_0xabf0('0x10'));var Redis=require(_0xabf0('0x11'));var authService=require(_0xabf0('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xabf0('0x13'));var hardwareService=require(_0xabf0('0x14'));var logger=require('../../config/logger')(_0xabf0('0x15'));var utils=require(_0xabf0('0x16'));var config=require(_0xabf0('0x17'));var licenseUtil=require(_0xabf0('0x18'));var db=require(_0xabf0('0x19'))['db'];function respondWithStatusCode(_0xf2b904,_0x3ccdd2){_0x3ccdd2=_0x3ccdd2||0xcc;return function(_0x14a644){if(_0x14a644){return _0xf2b904[_0xabf0('0x1a')](_0x3ccdd2);}return _0xf2b904[_0xabf0('0x1b')](_0x3ccdd2)['end']();};}function respondWithResult(_0x5b805c,_0x5ba7f6){_0x5ba7f6=_0x5ba7f6||0xc8;return function(_0x50a06d){if(_0x50a06d){return _0x5b805c[_0xabf0('0x1b')](_0x5ba7f6)[_0xabf0('0x1c')](_0x50a06d);}};}function respondWithFilteredResult(_0x2b21d0,_0x157851){return function(_0x3249ee){if(_0x3249ee){var _0x2e0e31=typeof _0x157851[_0xabf0('0x1d')]===_0xabf0('0x1e')&&typeof _0x157851[_0xabf0('0x1f')]==='undefined';var _0x4aa40d=_0x3249ee['count'];var _0x5e22ec=_0x2e0e31?0x0:_0x157851[_0xabf0('0x1d')];var _0x462b08=_0x2e0e31?_0x3249ee[_0xabf0('0x20')]:_0x157851[_0xabf0('0x1d')]+_0x157851[_0xabf0('0x1f')];var _0x362d86;if(_0x462b08>=_0x4aa40d){_0x462b08=_0x4aa40d;_0x362d86=0xc8;}else{_0x362d86=0xce;}_0x2b21d0['status'](_0x362d86);return _0x2b21d0[_0xabf0('0x21')]('Content-Range',_0x5e22ec+'-'+_0x462b08+'/'+_0x4aa40d)['json'](_0x3249ee);}return null;};}function patchUpdates(_0x49c64c){return function(_0x5c422d){try{jsonpatch[_0xabf0('0x22')](_0x5c422d,_0x49c64c,!![]);}catch(_0x3e4f59){return BPromise[_0xabf0('0x23')](_0x3e4f59);}return _0x5c422d[_0xabf0('0x24')]();};}function saveUpdates(_0x5cfaa5,_0x2b643f){return function(_0x1b9d45){if(_0x1b9d45){return _0x1b9d45[_0xabf0('0x25')](_0x5cfaa5)[_0xabf0('0x26')](function(_0x3256d7){return _0x3256d7;});}return null;};}function removeEntity(_0x5a0536,_0x998f83){return function(_0x400184){if(_0x400184){return _0x400184[_0xabf0('0x27')]()[_0xabf0('0x26')](function(){_0x5a0536['status'](0xcc)[_0xabf0('0x28')]();});}};}function handleEntityNotFound(_0xf1600a,_0x2a4bbb){return function(_0x5e43fd){if(!_0x5e43fd){_0xf1600a['sendStatus'](0x194);}return _0x5e43fd;};}function handleError(_0x3352eb,_0x57193e){_0x57193e=_0x57193e||0x1f4;return function(_0x277e6d){logger[_0xabf0('0x29')](_0x277e6d[_0xabf0('0x2a')]);if(_0x277e6d[_0xabf0('0x2b')]){delete _0x277e6d['name'];}_0x3352eb['status'](_0x57193e)[_0xabf0('0x2c')](_0x277e6d);};}exports[_0xabf0('0x2d')]=function(_0x3ceae3,_0x1790ac){var _0x3c547f={},_0x1a9963={},_0x363a5e={'count':0x0,'rows':[]};var _0x1f6c8c=_[_0xabf0('0x2e')](db['SugarcrmField'][_0xabf0('0x2f')],function(_0x24977a){return{'name':_0x24977a[_0xabf0('0x30')],'type':_0x24977a['type'][_0xabf0('0x31')]};});_0x1a9963[_0xabf0('0x32')]=_[_0xabf0('0x2e')](_0x1f6c8c,'name');_0x1a9963[_0xabf0('0x33')]=_[_0xabf0('0x34')](_0x3ceae3['query']);_0x1a9963[_0xabf0('0x35')]=_['intersection'](_0x1a9963[_0xabf0('0x32')],_0x1a9963[_0xabf0('0x33')]);_0x3c547f[_0xabf0('0x36')]=_[_0xabf0('0x37')](_0x1a9963['model'],qs[_0xabf0('0x38')](_0x3ceae3[_0xabf0('0x33')]['fields']));_0x3c547f[_0xabf0('0x36')]=_0x3c547f['attributes'][_0xabf0('0x39')]?_0x3c547f['attributes']:_0x1a9963['model'];if(!_0x3ceae3[_0xabf0('0x33')][_0xabf0('0x3a')](_0xabf0('0x3b'))){_0x3c547f['limit']=qs['limit'](_0x3ceae3[_0xabf0('0x33')][_0xabf0('0x1f')]);_0x3c547f[_0xabf0('0x1d')]=qs[_0xabf0('0x1d')](_0x3ceae3[_0xabf0('0x33')][_0xabf0('0x1d')]);}_0x3c547f[_0xabf0('0x3c')]=qs[_0xabf0('0x3d')](_0x3ceae3[_0xabf0('0x33')][_0xabf0('0x3d')]);_0x3c547f[_0xabf0('0x3e')]=qs[_0xabf0('0x35')](_[_0xabf0('0x3f')](_0x3ceae3['query'],_0x1a9963['filters']),_0x1f6c8c);if(_0x3ceae3[_0xabf0('0x33')]['filter']){_0x3c547f[_0xabf0('0x3e')]=_[_0xabf0('0x40')](_0x3c547f[_0xabf0('0x3e')],{'$or':_[_0xabf0('0x2e')](_0x1f6c8c,function(_0x450288){if(_0x450288[_0xabf0('0x41')]!==_0xabf0('0x42')){var _0x100cd4={};_0x100cd4[_0x450288['name']]={'$like':'%'+_0x3ceae3[_0xabf0('0x33')][_0xabf0('0x43')]+'%'};return _0x100cd4;}})});}_0x3c547f=_[_0xabf0('0x40')]({},_0x3c547f,_0x3ceae3[_0xabf0('0x44')]);var _0x4a99b7={'where':_0x3c547f[_0xabf0('0x3e')]};return db[_0xabf0('0x45')]['count'](_0x4a99b7)[_0xabf0('0x26')](function(_0x4ca66c){_0x363a5e[_0xabf0('0x20')]=_0x4ca66c;if(_0x3ceae3[_0xabf0('0x33')]['includeAll']){_0x3c547f[_0xabf0('0x46')]=[{'all':!![]}];}return db[_0xabf0('0x45')][_0xabf0('0x47')](_0x3c547f);})[_0xabf0('0x26')](function(_0x2f60b1){_0x363a5e[_0xabf0('0x48')]=_0x2f60b1;return _0x363a5e;})[_0xabf0('0x26')](respondWithFilteredResult(_0x1790ac,_0x3c547f))[_0xabf0('0x49')](handleError(_0x1790ac,null));};exports[_0xabf0('0x4a')]=function(_0x26d5b6,_0x786f32){var _0x11327e={'raw':!![],'where':{'id':_0x26d5b6[_0xabf0('0x4b')]['id']}},_0x2f8b2b={};_0x2f8b2b[_0xabf0('0x32')]=_['keys'](db[_0xabf0('0x45')][_0xabf0('0x2f')]);_0x2f8b2b['query']=_[_0xabf0('0x34')](_0x26d5b6[_0xabf0('0x33')]);_0x2f8b2b[_0xabf0('0x35')]=_[_0xabf0('0x37')](_0x2f8b2b[_0xabf0('0x32')],_0x2f8b2b['query']);_0x11327e[_0xabf0('0x36')]=_[_0xabf0('0x37')](_0x2f8b2b[_0xabf0('0x32')],qs[_0xabf0('0x38')](_0x26d5b6[_0xabf0('0x33')][_0xabf0('0x38')]));_0x11327e[_0xabf0('0x36')]=_0x11327e[_0xabf0('0x36')][_0xabf0('0x39')]?_0x11327e[_0xabf0('0x36')]:_0x2f8b2b[_0xabf0('0x32')];if(_0x26d5b6[_0xabf0('0x33')][_0xabf0('0x4c')]){_0x11327e[_0xabf0('0x46')]=[{'all':!![]}];}_0x11327e=_['merge']({},_0x11327e,_0x26d5b6[_0xabf0('0x44')]);return db[_0xabf0('0x45')]['find'](_0x11327e)[_0xabf0('0x26')](handleEntityNotFound(_0x786f32,null))[_0xabf0('0x26')](respondWithResult(_0x786f32,null))[_0xabf0('0x49')](handleError(_0x786f32,null));};exports[_0xabf0('0x4d')]=function(_0x923df7,_0x42a5e1){return db[_0xabf0('0x45')][_0xabf0('0x4d')](_0x923df7[_0xabf0('0x4e')],{})[_0xabf0('0x26')](respondWithResult(_0x42a5e1,0xc9))[_0xabf0('0x49')](handleError(_0x42a5e1,null));};exports[_0xabf0('0x25')]=function(_0x7bc501,_0x3f888d){if(_0x7bc501[_0xabf0('0x4e')]['id']){delete _0x7bc501[_0xabf0('0x4e')]['id'];}return db['SugarcrmField'][_0xabf0('0x4f')]({'where':{'id':_0x7bc501[_0xabf0('0x4b')]['id']}})['then'](handleEntityNotFound(_0x3f888d,null))[_0xabf0('0x26')](saveUpdates(_0x7bc501[_0xabf0('0x4e')],null))[_0xabf0('0x26')](respondWithResult(_0x3f888d,null))[_0xabf0('0x49')](handleError(_0x3f888d,null));};exports[_0xabf0('0x27')]=function(_0x199fb0,_0x49db64){return db['SugarcrmField'][_0xabf0('0x4f')]({'where':{'id':_0x199fb0[_0xabf0('0x4b')]['id']}})['then'](handleEntityNotFound(_0x49db64,null))[_0xabf0('0x26')](removeEntity(_0x49db64,null))['catch'](handleError(_0x49db64,null));};