42b6df1e1a385336f23a1a4e7d9a5dd1c098d047
[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 _0xf881=['show','params','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','sendStatus','status','end','offset','limit','undefined','count','set','Content-Range','json','reject','save','update','then','destroy','error','stack','name','index','SugarcrmField','rawAttributes','fieldName','key','map','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','type','VIRTUAL','merge','options','includeAll','include','findAll','catch'];(function(_0xe278fb,_0x3250ed){var _0x5a42f3=function(_0x49468a){while(--_0x49468a){_0xe278fb['push'](_0xe278fb['shift']());}};_0x5a42f3(++_0x3250ed);}(_0xf881,0x1d9));var _0x1f88=function(_0x5d0a06,_0x2f8043){_0x5d0a06=_0x5d0a06-0x0;var _0x2350ca=_0xf881[_0x5d0a06];return _0x2350ca;};'use strict';var emlformat=require(_0x1f88('0x0'));var rimraf=require(_0x1f88('0x1'));var zipdir=require(_0x1f88('0x2'));var jsonpatch=require(_0x1f88('0x3'));var rp=require(_0x1f88('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x1f88('0x5'));var util=require(_0x1f88('0x6'));var path=require(_0x1f88('0x7'));var sox=require(_0x1f88('0x8'));var csv=require(_0x1f88('0x9'));var ejs=require(_0x1f88('0xa'));var fs=require('fs');var fs_extra=require(_0x1f88('0xb'));var _=require(_0x1f88('0xc'));var squel=require(_0x1f88('0xd'));var crypto=require(_0x1f88('0xe'));var jsforce=require(_0x1f88('0xf'));var deskjs=require(_0x1f88('0x10'));var toCsv=require('to-csv');var querystring=require(_0x1f88('0x11'));var Papa=require(_0x1f88('0x12'));var Redis=require(_0x1f88('0x13'));var authService=require(_0x1f88('0x14'));var qs=require(_0x1f88('0x15'));var as=require(_0x1f88('0x16'));var hardwareService=require(_0x1f88('0x17'));var logger=require(_0x1f88('0x18'))('api');var utils=require('../../config/utils');var config=require(_0x1f88('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x1f88('0x1a'))['db'];function respondWithStatusCode(_0x42844e,_0x41df0c){_0x41df0c=_0x41df0c||0xcc;return function(_0x1ce610){if(_0x1ce610){return _0x42844e[_0x1f88('0x1b')](_0x41df0c);}return _0x42844e[_0x1f88('0x1c')](_0x41df0c)[_0x1f88('0x1d')]();};}function respondWithResult(_0x29ab47,_0x488f9e){_0x488f9e=_0x488f9e||0xc8;return function(_0xdb9e38){if(_0xdb9e38){return _0x29ab47['status'](_0x488f9e)['json'](_0xdb9e38);}};}function respondWithFilteredResult(_0x3d5b6b,_0x213b0f){return function(_0x56cb9c){if(_0x56cb9c){var _0x1c6bd2=typeof _0x213b0f[_0x1f88('0x1e')]==='undefined'&&typeof _0x213b0f[_0x1f88('0x1f')]===_0x1f88('0x20');var _0x58a569=_0x56cb9c[_0x1f88('0x21')];var _0x29afa3=_0x1c6bd2?0x0:_0x213b0f[_0x1f88('0x1e')];var _0x4aba76=_0x1c6bd2?_0x56cb9c[_0x1f88('0x21')]:_0x213b0f[_0x1f88('0x1e')]+_0x213b0f[_0x1f88('0x1f')];var _0x4e8ac2;if(_0x4aba76>=_0x58a569){_0x4aba76=_0x58a569;_0x4e8ac2=0xc8;}else{_0x4e8ac2=0xce;}_0x3d5b6b[_0x1f88('0x1c')](_0x4e8ac2);return _0x3d5b6b[_0x1f88('0x22')](_0x1f88('0x23'),_0x29afa3+'-'+_0x4aba76+'/'+_0x58a569)[_0x1f88('0x24')](_0x56cb9c);}return null;};}function patchUpdates(_0xee1a8f){return function(_0x5f27df){try{jsonpatch['apply'](_0x5f27df,_0xee1a8f,!![]);}catch(_0x1a619c){return BPromise[_0x1f88('0x25')](_0x1a619c);}return _0x5f27df[_0x1f88('0x26')]();};}function saveUpdates(_0x206937,_0x4099b6){return function(_0x460856){if(_0x460856){return _0x460856[_0x1f88('0x27')](_0x206937)[_0x1f88('0x28')](function(_0x39ef99){return _0x39ef99;});}return null;};}function removeEntity(_0x15e515,_0x49c35e){return function(_0x1fd5b5){if(_0x1fd5b5){return _0x1fd5b5[_0x1f88('0x29')]()[_0x1f88('0x28')](function(){_0x15e515[_0x1f88('0x1c')](0xcc)[_0x1f88('0x1d')]();});}};}function handleEntityNotFound(_0xc33492,_0x11cb8c){return function(_0x1a5688){if(!_0x1a5688){_0xc33492[_0x1f88('0x1b')](0x194);}return _0x1a5688;};}function handleError(_0x5549c5,_0x246f6a){_0x246f6a=_0x246f6a||0x1f4;return function(_0x996b89){logger[_0x1f88('0x2a')](_0x996b89[_0x1f88('0x2b')]);if(_0x996b89[_0x1f88('0x2c')]){delete _0x996b89[_0x1f88('0x2c')];}_0x5549c5[_0x1f88('0x1c')](_0x246f6a)['send'](_0x996b89);};}exports[_0x1f88('0x2d')]=function(_0xc68e4c,_0x59df56){var _0x406336={},_0x418c49={},_0x23e5e8={'count':0x0,'rows':[]};var _0x37f096=_['map'](db[_0x1f88('0x2e')][_0x1f88('0x2f')],function(_0x193536){return{'name':_0x193536[_0x1f88('0x30')],'type':_0x193536['type'][_0x1f88('0x31')]};});_0x418c49['model']=_[_0x1f88('0x32')](_0x37f096,_0x1f88('0x2c'));_0x418c49['query']=_[_0x1f88('0x33')](_0xc68e4c[_0x1f88('0x34')]);_0x418c49[_0x1f88('0x35')]=_[_0x1f88('0x36')](_0x418c49[_0x1f88('0x37')],_0x418c49[_0x1f88('0x34')]);_0x406336[_0x1f88('0x38')]=_[_0x1f88('0x36')](_0x418c49[_0x1f88('0x37')],qs[_0x1f88('0x39')](_0xc68e4c[_0x1f88('0x34')][_0x1f88('0x39')]));_0x406336['attributes']=_0x406336[_0x1f88('0x38')][_0x1f88('0x3a')]?_0x406336[_0x1f88('0x38')]:_0x418c49[_0x1f88('0x37')];if(!_0xc68e4c['query'][_0x1f88('0x3b')]('nolimit')){_0x406336['limit']=qs[_0x1f88('0x1f')](_0xc68e4c['query'][_0x1f88('0x1f')]);_0x406336[_0x1f88('0x1e')]=qs[_0x1f88('0x1e')](_0xc68e4c['query'][_0x1f88('0x1e')]);}_0x406336[_0x1f88('0x3c')]=qs['sort'](_0xc68e4c[_0x1f88('0x34')][_0x1f88('0x3d')]);_0x406336[_0x1f88('0x3e')]=qs[_0x1f88('0x35')](_[_0x1f88('0x3f')](_0xc68e4c[_0x1f88('0x34')],_0x418c49[_0x1f88('0x35')]),_0x37f096);if(_0xc68e4c['query'][_0x1f88('0x40')]){_0x406336[_0x1f88('0x3e')]=_['merge'](_0x406336['where'],{'$or':_[_0x1f88('0x32')](_0x37f096,function(_0x18107e){if(_0x18107e[_0x1f88('0x41')]!==_0x1f88('0x42')){var _0x69aee6={};_0x69aee6[_0x18107e[_0x1f88('0x2c')]]={'$like':'%'+_0xc68e4c[_0x1f88('0x34')][_0x1f88('0x40')]+'%'};return _0x69aee6;}})});}_0x406336=_[_0x1f88('0x43')]({},_0x406336,_0xc68e4c[_0x1f88('0x44')]);var _0x20e6a4={'where':_0x406336['where']};return db[_0x1f88('0x2e')][_0x1f88('0x21')](_0x20e6a4)['then'](function(_0x1c0210){_0x23e5e8[_0x1f88('0x21')]=_0x1c0210;if(_0xc68e4c[_0x1f88('0x34')][_0x1f88('0x45')]){_0x406336[_0x1f88('0x46')]=[{'all':!![]}];}return db['SugarcrmField'][_0x1f88('0x47')](_0x406336);})[_0x1f88('0x28')](function(_0x5a9e41){_0x23e5e8['rows']=_0x5a9e41;return _0x23e5e8;})[_0x1f88('0x28')](respondWithFilteredResult(_0x59df56,_0x406336))[_0x1f88('0x48')](handleError(_0x59df56,null));};exports[_0x1f88('0x49')]=function(_0x222977,_0x7efdcb){var _0x364934={'raw':!![],'where':{'id':_0x222977[_0x1f88('0x4a')]['id']}},_0xd64542={};_0xd64542[_0x1f88('0x37')]=_['keys'](db['SugarcrmField'][_0x1f88('0x2f')]);_0xd64542[_0x1f88('0x34')]=_[_0x1f88('0x33')](_0x222977[_0x1f88('0x34')]);_0xd64542[_0x1f88('0x35')]=_[_0x1f88('0x36')](_0xd64542['model'],_0xd64542[_0x1f88('0x34')]);_0x364934[_0x1f88('0x38')]=_[_0x1f88('0x36')](_0xd64542[_0x1f88('0x37')],qs['fields'](_0x222977[_0x1f88('0x34')][_0x1f88('0x39')]));_0x364934[_0x1f88('0x38')]=_0x364934[_0x1f88('0x38')]['length']?_0x364934[_0x1f88('0x38')]:_0xd64542[_0x1f88('0x37')];if(_0x222977[_0x1f88('0x34')][_0x1f88('0x45')]){_0x364934['include']=[{'all':!![]}];}_0x364934=_[_0x1f88('0x43')]({},_0x364934,_0x222977[_0x1f88('0x44')]);return db[_0x1f88('0x2e')][_0x1f88('0x4b')](_0x364934)[_0x1f88('0x28')](handleEntityNotFound(_0x7efdcb,null))[_0x1f88('0x28')](respondWithResult(_0x7efdcb,null))[_0x1f88('0x48')](handleError(_0x7efdcb,null));};exports['create']=function(_0x57aa15,_0x306e35){return db[_0x1f88('0x2e')][_0x1f88('0x4c')](_0x57aa15[_0x1f88('0x4d')],{})[_0x1f88('0x28')](respondWithResult(_0x306e35,0xc9))[_0x1f88('0x48')](handleError(_0x306e35,null));};exports[_0x1f88('0x27')]=function(_0x59f73e,_0x1f34c8){if(_0x59f73e[_0x1f88('0x4d')]['id']){delete _0x59f73e['body']['id'];}return db[_0x1f88('0x2e')]['find']({'where':{'id':_0x59f73e[_0x1f88('0x4a')]['id']}})[_0x1f88('0x28')](handleEntityNotFound(_0x1f34c8,null))[_0x1f88('0x28')](saveUpdates(_0x59f73e['body'],null))[_0x1f88('0x28')](respondWithResult(_0x1f34c8,null))[_0x1f88('0x48')](handleError(_0x1f34c8,null));};exports['destroy']=function(_0x4ee5c6,_0x130c6e){return db['SugarcrmField'][_0x1f88('0x4b')]({'where':{'id':_0x4ee5c6['params']['id']}})[_0x1f88('0x28')](handleEntityNotFound(_0x130c6e,null))['then'](removeEntity(_0x130c6e,null))[_0x1f88('0x48')](handleError(_0x130c6e,null));};