f1f64dfabbdbddbba4841cdc8923509214d0bf9a
[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 _0xe39a=['json','undefined','limit','offset','count','set','Content-Range','apply','reject','save','then','destroy','stack','name','index','SugarcrmField','type','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','rows','show','params','rawAttributes','find','create','body','catch','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','status','end'];(function(_0xb73a1,_0x4a2c98){var _0x21c420=function(_0x2c6a14){while(--_0x2c6a14){_0xb73a1['push'](_0xb73a1['shift']());}};_0x21c420(++_0x4a2c98);}(_0xe39a,0x195));var _0xae39=function(_0x513a04,_0x2e642e){_0x513a04=_0x513a04-0x0;var _0x2829cf=_0xe39a[_0x513a04];return _0x2829cf;};'use strict';var emlformat=require(_0xae39('0x0'));var rimraf=require(_0xae39('0x1'));var zipdir=require(_0xae39('0x2'));var jsonpatch=require(_0xae39('0x3'));var rp=require(_0xae39('0x4'));var moment=require(_0xae39('0x5'));var BPromise=require(_0xae39('0x6'));var Mustache=require(_0xae39('0x7'));var util=require('util');var path=require('path');var sox=require(_0xae39('0x8'));var csv=require(_0xae39('0x9'));var ejs=require(_0xae39('0xa'));var fs=require('fs');var fs_extra=require(_0xae39('0xb'));var _=require(_0xae39('0xc'));var squel=require(_0xae39('0xd'));var crypto=require(_0xae39('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xae39('0xf'));var toCsv=require(_0xae39('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xae39('0x10'));var authService=require(_0xae39('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xae39('0x12'));var hardwareService=require(_0xae39('0x13'));var logger=require(_0xae39('0x14'))(_0xae39('0x15'));var utils=require(_0xae39('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xae39('0x17'));var db=require(_0xae39('0x18'))['db'];function respondWithStatusCode(_0x12ce0e,_0x35b717){_0x35b717=_0x35b717||0xcc;return function(_0x4bd9f6){if(_0x4bd9f6){return _0x12ce0e['sendStatus'](_0x35b717);}return _0x12ce0e[_0xae39('0x19')](_0x35b717)[_0xae39('0x1a')]();};}function respondWithResult(_0x504efb,_0x31f807){_0x31f807=_0x31f807||0xc8;return function(_0x2b120c){if(_0x2b120c){return _0x504efb[_0xae39('0x19')](_0x31f807)[_0xae39('0x1b')](_0x2b120c);}};}function respondWithFilteredResult(_0x27d255,_0x489217){return function(_0x138029){if(_0x138029){var _0x96546b=typeof _0x489217['offset']===_0xae39('0x1c')&&typeof _0x489217[_0xae39('0x1d')]===_0xae39('0x1c');var _0x4b485b=_0x138029['count'];var _0x1e8b94=_0x96546b?0x0:_0x489217[_0xae39('0x1e')];var _0x285a45=_0x96546b?_0x138029[_0xae39('0x1f')]:_0x489217[_0xae39('0x1e')]+_0x489217[_0xae39('0x1d')];var _0x374b4a;if(_0x285a45>=_0x4b485b){_0x285a45=_0x4b485b;_0x374b4a=0xc8;}else{_0x374b4a=0xce;}_0x27d255[_0xae39('0x19')](_0x374b4a);return _0x27d255[_0xae39('0x20')](_0xae39('0x21'),_0x1e8b94+'-'+_0x285a45+'/'+_0x4b485b)['json'](_0x138029);}return null;};}function patchUpdates(_0x27fd32){return function(_0x417083){try{jsonpatch[_0xae39('0x22')](_0x417083,_0x27fd32,!![]);}catch(_0x35076e){return BPromise[_0xae39('0x23')](_0x35076e);}return _0x417083[_0xae39('0x24')]();};}function saveUpdates(_0x4ee4b1,_0xc8b476){return function(_0x3aab5f){if(_0x3aab5f){return _0x3aab5f['update'](_0x4ee4b1)[_0xae39('0x25')](function(_0x29d6f1){return _0x29d6f1;});}return null;};}function removeEntity(_0x436657,_0x10b1aa){return function(_0x89ad0){if(_0x89ad0){return _0x89ad0[_0xae39('0x26')]()[_0xae39('0x25')](function(){_0x436657[_0xae39('0x19')](0xcc)[_0xae39('0x1a')]();});}};}function handleEntityNotFound(_0x59e93a,_0x486365){return function(_0x2769de){if(!_0x2769de){_0x59e93a['sendStatus'](0x194);}return _0x2769de;};}function handleError(_0x2c180d,_0x283bbf){_0x283bbf=_0x283bbf||0x1f4;return function(_0x2c4eaf){logger['error'](_0x2c4eaf[_0xae39('0x27')]);if(_0x2c4eaf[_0xae39('0x28')]){delete _0x2c4eaf[_0xae39('0x28')];}_0x2c180d['status'](_0x283bbf)['send'](_0x2c4eaf);};}exports[_0xae39('0x29')]=function(_0x2119a5,_0x23b9b3){var _0x5bf498={},_0x2fbc24={},_0x2b624a={'count':0x0,'rows':[]};var _0x4242a5=_['map'](db[_0xae39('0x2a')]['rawAttributes'],function(_0x216547){return{'name':_0x216547['fieldName'],'type':_0x216547[_0xae39('0x2b')]['key']};});_0x2fbc24[_0xae39('0x2c')]=_[_0xae39('0x2d')](_0x4242a5,'name');_0x2fbc24[_0xae39('0x2e')]=_[_0xae39('0x2f')](_0x2119a5['query']);_0x2fbc24[_0xae39('0x30')]=_['intersection'](_0x2fbc24[_0xae39('0x2c')],_0x2fbc24['query']);_0x5bf498[_0xae39('0x31')]=_[_0xae39('0x32')](_0x2fbc24['model'],qs[_0xae39('0x33')](_0x2119a5[_0xae39('0x2e')][_0xae39('0x33')]));_0x5bf498[_0xae39('0x31')]=_0x5bf498[_0xae39('0x31')][_0xae39('0x34')]?_0x5bf498[_0xae39('0x31')]:_0x2fbc24['model'];if(!_0x2119a5['query'][_0xae39('0x35')](_0xae39('0x36'))){_0x5bf498[_0xae39('0x1d')]=qs['limit'](_0x2119a5[_0xae39('0x2e')]['limit']);_0x5bf498[_0xae39('0x1e')]=qs[_0xae39('0x1e')](_0x2119a5['query'][_0xae39('0x1e')]);}_0x5bf498[_0xae39('0x37')]=qs['sort'](_0x2119a5[_0xae39('0x2e')][_0xae39('0x38')]);_0x5bf498[_0xae39('0x39')]=qs['filters'](_[_0xae39('0x3a')](_0x2119a5[_0xae39('0x2e')],_0x2fbc24[_0xae39('0x30')]),_0x4242a5);if(_0x2119a5['query'][_0xae39('0x3b')]){_0x5bf498[_0xae39('0x39')]=_[_0xae39('0x3c')](_0x5bf498['where'],{'$or':_[_0xae39('0x2d')](_0x4242a5,function(_0x17f31f){if(_0x17f31f[_0xae39('0x2b')]!=='VIRTUAL'){var _0x3b6ebd={};_0x3b6ebd[_0x17f31f['name']]={'$like':'%'+_0x2119a5[_0xae39('0x2e')]['filter']+'%'};return _0x3b6ebd;}})});}_0x5bf498=_['merge']({},_0x5bf498,_0x2119a5[_0xae39('0x3d')]);var _0x5566f3={'where':_0x5bf498[_0xae39('0x39')]};return db['SugarcrmField'][_0xae39('0x1f')](_0x5566f3)[_0xae39('0x25')](function(_0x247216){_0x2b624a[_0xae39('0x1f')]=_0x247216;if(_0x2119a5['query'][_0xae39('0x3e')]){_0x5bf498[_0xae39('0x3f')]=[{'all':!![]}];}return db[_0xae39('0x2a')]['findAll'](_0x5bf498);})[_0xae39('0x25')](function(_0x8a301b){_0x2b624a[_0xae39('0x40')]=_0x8a301b;return _0x2b624a;})[_0xae39('0x25')](respondWithFilteredResult(_0x23b9b3,_0x5bf498))['catch'](handleError(_0x23b9b3,null));};exports[_0xae39('0x41')]=function(_0x3e900e,_0x2c357e){var _0x45b9f7={'raw':!![],'where':{'id':_0x3e900e[_0xae39('0x42')]['id']}},_0x3eeb39={};_0x3eeb39[_0xae39('0x2c')]=_[_0xae39('0x2f')](db[_0xae39('0x2a')][_0xae39('0x43')]);_0x3eeb39['query']=_[_0xae39('0x2f')](_0x3e900e['query']);_0x3eeb39[_0xae39('0x30')]=_[_0xae39('0x32')](_0x3eeb39[_0xae39('0x2c')],_0x3eeb39[_0xae39('0x2e')]);_0x45b9f7['attributes']=_['intersection'](_0x3eeb39['model'],qs['fields'](_0x3e900e[_0xae39('0x2e')][_0xae39('0x33')]));_0x45b9f7['attributes']=_0x45b9f7[_0xae39('0x31')]['length']?_0x45b9f7[_0xae39('0x31')]:_0x3eeb39[_0xae39('0x2c')];if(_0x3e900e[_0xae39('0x2e')][_0xae39('0x3e')]){_0x45b9f7[_0xae39('0x3f')]=[{'all':!![]}];}_0x45b9f7=_[_0xae39('0x3c')]({},_0x45b9f7,_0x3e900e['options']);return db[_0xae39('0x2a')][_0xae39('0x44')](_0x45b9f7)[_0xae39('0x25')](handleEntityNotFound(_0x2c357e,null))[_0xae39('0x25')](respondWithResult(_0x2c357e,null))['catch'](handleError(_0x2c357e,null));};exports[_0xae39('0x45')]=function(_0x5249fb,_0x4b6318){return db[_0xae39('0x2a')][_0xae39('0x45')](_0x5249fb[_0xae39('0x46')],{})[_0xae39('0x25')](respondWithResult(_0x4b6318,0xc9))[_0xae39('0x47')](handleError(_0x4b6318,null));};exports['update']=function(_0x5e9d1a,_0x56c43f){if(_0x5e9d1a[_0xae39('0x46')]['id']){delete _0x5e9d1a[_0xae39('0x46')]['id'];}return db[_0xae39('0x2a')]['find']({'where':{'id':_0x5e9d1a[_0xae39('0x42')]['id']}})['then'](handleEntityNotFound(_0x56c43f,null))[_0xae39('0x25')](saveUpdates(_0x5e9d1a['body'],null))[_0xae39('0x25')](respondWithResult(_0x56c43f,null))['catch'](handleError(_0x56c43f,null));};exports['destroy']=function(_0x2b94a3,_0x64e00c){return db[_0xae39('0x2a')][_0xae39('0x44')]({'where':{'id':_0x2b94a3[_0xae39('0x42')]['id']}})[_0xae39('0x25')](handleEntityNotFound(_0x64e00c,null))[_0xae39('0x25')](removeEntity(_0x64e00c,null))[_0xae39('0x47')](handleError(_0x64e00c,null));};