737c0f398d4761f38ba11574b209d81c9dfcc261
[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 _0x1032=['fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','filter','merge','options','includeAll','include','show','params','catch','create','body','destroy','find','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','json','offset','undefined','count','limit','Content-Range','apply','update','then','end','sendStatus','error','stack','name','send','index','map','SugarcrmField','rawAttributes'];(function(_0x1da7ca,_0x5b39d0){var _0x236537=function(_0x457195){while(--_0x457195){_0x1da7ca['push'](_0x1da7ca['shift']());}};_0x236537(++_0x5b39d0);}(_0x1032,0x6c));var _0x2103=function(_0xcc2f82,_0x54f2a3){_0xcc2f82=_0xcc2f82-0x0;var _0x25e109=_0x1032[_0xcc2f82];return _0x25e109;};'use strict';var emlformat=require(_0x2103('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x2103('0x1'));var jsonpatch=require(_0x2103('0x2'));var rp=require(_0x2103('0x3'));var moment=require(_0x2103('0x4'));var BPromise=require(_0x2103('0x5'));var Mustache=require(_0x2103('0x6'));var util=require(_0x2103('0x7'));var path=require('path');var sox=require(_0x2103('0x8'));var csv=require(_0x2103('0x9'));var ejs=require(_0x2103('0xa'));var fs=require('fs');var fs_extra=require(_0x2103('0xb'));var _=require(_0x2103('0xc'));var squel=require(_0x2103('0xd'));var crypto=require(_0x2103('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x2103('0xf'));var toCsv=require(_0x2103('0x9'));var querystring=require(_0x2103('0x10'));var Papa=require('papaparse');var Redis=require(_0x2103('0x11'));var authService=require(_0x2103('0x12'));var qs=require(_0x2103('0x13'));var as=require(_0x2103('0x14'));var hardwareService=require(_0x2103('0x15'));var logger=require(_0x2103('0x16'))(_0x2103('0x17'));var utils=require(_0x2103('0x18'));var config=require(_0x2103('0x19'));var licenseUtil=require(_0x2103('0x1a'));var db=require(_0x2103('0x1b'))['db'];function respondWithStatusCode(_0x325fbc,_0x2768e1){_0x2768e1=_0x2768e1||0xcc;return function(_0x38153b){if(_0x38153b){return _0x325fbc['sendStatus'](_0x2768e1);}return _0x325fbc[_0x2103('0x1c')](_0x2768e1)['end']();};}function respondWithResult(_0x1bb499,_0x23da6a){_0x23da6a=_0x23da6a||0xc8;return function(_0x1c5880){if(_0x1c5880){return _0x1bb499['status'](_0x23da6a)[_0x2103('0x1d')](_0x1c5880);}};}function respondWithFilteredResult(_0x11997c,_0x4762ab){return function(_0x25b558){if(_0x25b558){var _0x34f6b7=typeof _0x4762ab[_0x2103('0x1e')]===_0x2103('0x1f')&&typeof _0x4762ab['limit']===_0x2103('0x1f');var _0x250931=_0x25b558[_0x2103('0x20')];var _0x5c5eed=_0x34f6b7?0x0:_0x4762ab[_0x2103('0x1e')];var _0xb3fc3a=_0x34f6b7?_0x25b558[_0x2103('0x20')]:_0x4762ab[_0x2103('0x1e')]+_0x4762ab[_0x2103('0x21')];var _0x53f06c;if(_0xb3fc3a>=_0x250931){_0xb3fc3a=_0x250931;_0x53f06c=0xc8;}else{_0x53f06c=0xce;}_0x11997c['status'](_0x53f06c);return _0x11997c['set'](_0x2103('0x22'),_0x5c5eed+'-'+_0xb3fc3a+'/'+_0x250931)[_0x2103('0x1d')](_0x25b558);}return null;};}function patchUpdates(_0x47eeb6){return function(_0x4d31a8){try{jsonpatch[_0x2103('0x23')](_0x4d31a8,_0x47eeb6,!![]);}catch(_0x1c6956){return BPromise['reject'](_0x1c6956);}return _0x4d31a8['save']();};}function saveUpdates(_0x1756fc,_0x3463f1){return function(_0x28adeb){if(_0x28adeb){return _0x28adeb[_0x2103('0x24')](_0x1756fc)[_0x2103('0x25')](function(_0x2365df){return _0x2365df;});}return null;};}function removeEntity(_0x37f0cc,_0x2d65e6){return function(_0xc252d1){if(_0xc252d1){return _0xc252d1['destroy']()['then'](function(){_0x37f0cc[_0x2103('0x1c')](0xcc)[_0x2103('0x26')]();});}};}function handleEntityNotFound(_0x47b269,_0x45d3dd){return function(_0x4ed4c8){if(!_0x4ed4c8){_0x47b269[_0x2103('0x27')](0x194);}return _0x4ed4c8;};}function handleError(_0x31cea7,_0x6910bc){_0x6910bc=_0x6910bc||0x1f4;return function(_0x541a0d){logger[_0x2103('0x28')](_0x541a0d[_0x2103('0x29')]);if(_0x541a0d[_0x2103('0x2a')]){delete _0x541a0d['name'];}_0x31cea7[_0x2103('0x1c')](_0x6910bc)[_0x2103('0x2b')](_0x541a0d);};}exports[_0x2103('0x2c')]=function(_0x38e86a,_0xb21c3f){var _0x225f6a={},_0x26b374={},_0x1bbd3e={'count':0x0,'rows':[]};var _0x44a3c2=_[_0x2103('0x2d')](db[_0x2103('0x2e')][_0x2103('0x2f')],function(_0x4c5db8){return{'name':_0x4c5db8[_0x2103('0x30')],'type':_0x4c5db8[_0x2103('0x31')][_0x2103('0x32')]};});_0x26b374[_0x2103('0x33')]=_[_0x2103('0x2d')](_0x44a3c2,'name');_0x26b374['query']=_[_0x2103('0x34')](_0x38e86a[_0x2103('0x35')]);_0x26b374[_0x2103('0x36')]=_[_0x2103('0x37')](_0x26b374[_0x2103('0x33')],_0x26b374['query']);_0x225f6a[_0x2103('0x38')]=_[_0x2103('0x37')](_0x26b374[_0x2103('0x33')],qs[_0x2103('0x39')](_0x38e86a[_0x2103('0x35')][_0x2103('0x39')]));_0x225f6a[_0x2103('0x38')]=_0x225f6a[_0x2103('0x38')][_0x2103('0x3a')]?_0x225f6a[_0x2103('0x38')]:_0x26b374[_0x2103('0x33')];if(!_0x38e86a['query'][_0x2103('0x3b')](_0x2103('0x3c'))){_0x225f6a[_0x2103('0x21')]=qs[_0x2103('0x21')](_0x38e86a[_0x2103('0x35')][_0x2103('0x21')]);_0x225f6a[_0x2103('0x1e')]=qs[_0x2103('0x1e')](_0x38e86a[_0x2103('0x35')][_0x2103('0x1e')]);}_0x225f6a[_0x2103('0x3d')]=qs[_0x2103('0x3e')](_0x38e86a['query'][_0x2103('0x3e')]);_0x225f6a[_0x2103('0x3f')]=qs[_0x2103('0x36')](_[_0x2103('0x40')](_0x38e86a[_0x2103('0x35')],_0x26b374[_0x2103('0x36')]),_0x44a3c2);if(_0x38e86a[_0x2103('0x35')]['filter']){_0x225f6a[_0x2103('0x3f')]=_['merge'](_0x225f6a[_0x2103('0x3f')],{'$or':_[_0x2103('0x2d')](_0x44a3c2,function(_0x33e292){if(_0x33e292[_0x2103('0x31')]!==_0x2103('0x41')){var _0x360211={};_0x360211[_0x33e292[_0x2103('0x2a')]]={'$like':'%'+_0x38e86a['query'][_0x2103('0x42')]+'%'};return _0x360211;}})});}_0x225f6a=_[_0x2103('0x43')]({},_0x225f6a,_0x38e86a[_0x2103('0x44')]);var _0x5cf174={'where':_0x225f6a[_0x2103('0x3f')]};return db[_0x2103('0x2e')][_0x2103('0x20')](_0x5cf174)[_0x2103('0x25')](function(_0x2294ef){_0x1bbd3e[_0x2103('0x20')]=_0x2294ef;if(_0x38e86a[_0x2103('0x35')][_0x2103('0x45')]){_0x225f6a[_0x2103('0x46')]=[{'all':!![]}];}return db[_0x2103('0x2e')]['findAll'](_0x225f6a);})[_0x2103('0x25')](function(_0x349e8d){_0x1bbd3e['rows']=_0x349e8d;return _0x1bbd3e;})[_0x2103('0x25')](respondWithFilteredResult(_0xb21c3f,_0x225f6a))['catch'](handleError(_0xb21c3f,null));};exports[_0x2103('0x47')]=function(_0x4fdb07,_0x19194f){var _0x105300={'raw':!![],'where':{'id':_0x4fdb07[_0x2103('0x48')]['id']}},_0x3e48a8={};_0x3e48a8[_0x2103('0x33')]=_[_0x2103('0x34')](db[_0x2103('0x2e')][_0x2103('0x2f')]);_0x3e48a8[_0x2103('0x35')]=_[_0x2103('0x34')](_0x4fdb07[_0x2103('0x35')]);_0x3e48a8[_0x2103('0x36')]=_[_0x2103('0x37')](_0x3e48a8[_0x2103('0x33')],_0x3e48a8[_0x2103('0x35')]);_0x105300[_0x2103('0x38')]=_[_0x2103('0x37')](_0x3e48a8['model'],qs[_0x2103('0x39')](_0x4fdb07[_0x2103('0x35')][_0x2103('0x39')]));_0x105300[_0x2103('0x38')]=_0x105300[_0x2103('0x38')][_0x2103('0x3a')]?_0x105300[_0x2103('0x38')]:_0x3e48a8[_0x2103('0x33')];if(_0x4fdb07[_0x2103('0x35')]['includeAll']){_0x105300['include']=[{'all':!![]}];}_0x105300=_['merge']({},_0x105300,_0x4fdb07['options']);return db[_0x2103('0x2e')]['find'](_0x105300)[_0x2103('0x25')](handleEntityNotFound(_0x19194f,null))['then'](respondWithResult(_0x19194f,null))[_0x2103('0x49')](handleError(_0x19194f,null));};exports[_0x2103('0x4a')]=function(_0x14312,_0x174abd){return db['SugarcrmField']['create'](_0x14312['body'],{})[_0x2103('0x25')](respondWithResult(_0x174abd,0xc9))[_0x2103('0x49')](handleError(_0x174abd,null));};exports[_0x2103('0x24')]=function(_0x42b07d,_0x221b56){if(_0x42b07d['body']['id']){delete _0x42b07d[_0x2103('0x4b')]['id'];}return db[_0x2103('0x2e')]['find']({'where':{'id':_0x42b07d['params']['id']}})['then'](handleEntityNotFound(_0x221b56,null))[_0x2103('0x25')](saveUpdates(_0x42b07d[_0x2103('0x4b')],null))['then'](respondWithResult(_0x221b56,null))[_0x2103('0x49')](handleError(_0x221b56,null));};exports[_0x2103('0x4c')]=function(_0xf6a3d7,_0x47c551){return db[_0x2103('0x2e')][_0x2103('0x4d')]({'where':{'id':_0xf6a3d7[_0x2103('0x48')]['id']}})['then'](handleEntityNotFound(_0x47c551,null))[_0x2103('0x25')](removeEntity(_0x47c551,null))['catch'](handleError(_0x47c551,null));};