Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / intFreshsalesField / intFreshsalesField.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 _0x3e1a=['json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','destroy','send','index','FreshsalesField','rawAttributes','fieldName','type','key','model','map','name','query','keys','intersection','length','attributes','hasOwnProperty','order','sort','where','filters','pick','filter','merge','options','includeAll','findAll','show','fields','include','create','body','find','params','catch','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','fs-extra','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end'];(function(_0x590daa,_0x28be12){var _0x30098a=function(_0x69f1c0){while(--_0x69f1c0){_0x590daa['push'](_0x590daa['shift']());}};_0x30098a(++_0x28be12);}(_0x3e1a,0xbe));var _0xa3e1=function(_0x432c3a,_0x1bae57){_0x432c3a=_0x432c3a-0x0;var _0x28b285=_0x3e1a[_0x432c3a];return _0x28b285;};'use strict';var emlformat=require(_0xa3e1('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xa3e1('0x1'));var jsonpatch=require(_0xa3e1('0x2'));var rp=require(_0xa3e1('0x3'));var moment=require(_0xa3e1('0x4'));var BPromise=require(_0xa3e1('0x5'));var Mustache=require('mustache');var util=require(_0xa3e1('0x6'));var path=require(_0xa3e1('0x7'));var sox=require('sox');var csv=require(_0xa3e1('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xa3e1('0x9'));var _=require('lodash');var squel=require(_0xa3e1('0xa'));var crypto=require('crypto');var jsforce=require(_0xa3e1('0xb'));var deskjs=require(_0xa3e1('0xc'));var toCsv=require(_0xa3e1('0x8'));var querystring=require(_0xa3e1('0xd'));var Papa=require(_0xa3e1('0xe'));var Redis=require(_0xa3e1('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xa3e1('0x10'));var as=require(_0xa3e1('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa3e1('0x12'))(_0xa3e1('0x13'));var utils=require(_0xa3e1('0x14'));var config=require(_0xa3e1('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xa3e1('0x16'))['db'];function respondWithStatusCode(_0xe1a5a3,_0x431d0f){_0x431d0f=_0x431d0f||0xcc;return function(_0x363df8){if(_0x363df8){return _0xe1a5a3[_0xa3e1('0x17')](_0x431d0f);}return _0xe1a5a3[_0xa3e1('0x18')](_0x431d0f)[_0xa3e1('0x19')]();};}function respondWithResult(_0x38bc04,_0x38e2eb){_0x38e2eb=_0x38e2eb||0xc8;return function(_0x3283c7){if(_0x3283c7){return _0x38bc04[_0xa3e1('0x18')](_0x38e2eb)[_0xa3e1('0x1a')](_0x3283c7);}};}function respondWithFilteredResult(_0x38380f,_0x564f7c){return function(_0x449279){if(_0x449279){var _0x3c3c65=typeof _0x564f7c[_0xa3e1('0x1b')]===_0xa3e1('0x1c')&&typeof _0x564f7c[_0xa3e1('0x1d')]===_0xa3e1('0x1c');var _0x76e74=_0x449279[_0xa3e1('0x1e')];var _0x2fa94a=_0x3c3c65?0x0:_0x564f7c[_0xa3e1('0x1b')];var _0x42ed6e=_0x3c3c65?_0x449279[_0xa3e1('0x1e')]:_0x564f7c[_0xa3e1('0x1b')]+_0x564f7c['limit'];var _0xc91273;if(_0x42ed6e>=_0x76e74){_0x42ed6e=_0x76e74;_0xc91273=0xc8;}else{_0xc91273=0xce;}_0x38380f[_0xa3e1('0x18')](_0xc91273);return _0x38380f[_0xa3e1('0x1f')](_0xa3e1('0x20'),_0x2fa94a+'-'+_0x42ed6e+'/'+_0x76e74)['json'](_0x449279);}return null;};}function patchUpdates(_0x2f590f){return function(_0x2e602b){try{jsonpatch[_0xa3e1('0x21')](_0x2e602b,_0x2f590f,!![]);}catch(_0x3bf5d1){return BPromise['reject'](_0x3bf5d1);}return _0x2e602b[_0xa3e1('0x22')]();};}function saveUpdates(_0x385253,_0x3d450c){return function(_0x2b8d75){if(_0x2b8d75){return _0x2b8d75[_0xa3e1('0x23')](_0x385253)[_0xa3e1('0x24')](function(_0x3a1d02){return _0x3a1d02;});}return null;};}function removeEntity(_0x19ac78,_0x241c4b){return function(_0x336577){if(_0x336577){return _0x336577[_0xa3e1('0x25')]()[_0xa3e1('0x24')](function(){_0x19ac78[_0xa3e1('0x18')](0xcc)[_0xa3e1('0x19')]();});}};}function handleEntityNotFound(_0x179fb5,_0x24ec58){return function(_0x50bc8b){if(!_0x50bc8b){_0x179fb5[_0xa3e1('0x17')](0x194);}return _0x50bc8b;};}function handleError(_0x27589a,_0x41b86f){_0x41b86f=_0x41b86f||0x1f4;return function(_0xe014da){logger['error'](_0xe014da['stack']);if(_0xe014da['name']){delete _0xe014da['name'];}_0x27589a['status'](_0x41b86f)[_0xa3e1('0x26')](_0xe014da);};}exports[_0xa3e1('0x27')]=function(_0x29665a,_0x1ba483){var _0x347e7b={},_0x4667e7={},_0x425377={'count':0x0,'rows':[]};var _0x58ac26=_['map'](db[_0xa3e1('0x28')][_0xa3e1('0x29')],function(_0x26e633){return{'name':_0x26e633[_0xa3e1('0x2a')],'type':_0x26e633[_0xa3e1('0x2b')][_0xa3e1('0x2c')]};});_0x4667e7[_0xa3e1('0x2d')]=_[_0xa3e1('0x2e')](_0x58ac26,_0xa3e1('0x2f'));_0x4667e7[_0xa3e1('0x30')]=_[_0xa3e1('0x31')](_0x29665a[_0xa3e1('0x30')]);_0x4667e7['filters']=_[_0xa3e1('0x32')](_0x4667e7[_0xa3e1('0x2d')],_0x4667e7[_0xa3e1('0x30')]);_0x347e7b['attributes']=_['intersection'](_0x4667e7[_0xa3e1('0x2d')],qs['fields'](_0x29665a[_0xa3e1('0x30')]['fields']));_0x347e7b['attributes']=_0x347e7b['attributes'][_0xa3e1('0x33')]?_0x347e7b[_0xa3e1('0x34')]:_0x4667e7['model'];if(!_0x29665a['query'][_0xa3e1('0x35')]('nolimit')){_0x347e7b[_0xa3e1('0x1d')]=qs[_0xa3e1('0x1d')](_0x29665a[_0xa3e1('0x30')]['limit']);_0x347e7b[_0xa3e1('0x1b')]=qs[_0xa3e1('0x1b')](_0x29665a[_0xa3e1('0x30')][_0xa3e1('0x1b')]);}_0x347e7b[_0xa3e1('0x36')]=qs[_0xa3e1('0x37')](_0x29665a['query'][_0xa3e1('0x37')]);_0x347e7b[_0xa3e1('0x38')]=qs[_0xa3e1('0x39')](_[_0xa3e1('0x3a')](_0x29665a[_0xa3e1('0x30')],_0x4667e7[_0xa3e1('0x39')]),_0x58ac26);if(_0x29665a['query'][_0xa3e1('0x3b')]){_0x347e7b['where']=_[_0xa3e1('0x3c')](_0x347e7b[_0xa3e1('0x38')],{'$or':_[_0xa3e1('0x2e')](_0x58ac26,function(_0x187c51){if(_0x187c51[_0xa3e1('0x2b')]!=='VIRTUAL'){var _0x135cc5={};_0x135cc5[_0x187c51[_0xa3e1('0x2f')]]={'$like':'%'+_0x29665a[_0xa3e1('0x30')][_0xa3e1('0x3b')]+'%'};return _0x135cc5;}})});}_0x347e7b=_[_0xa3e1('0x3c')]({},_0x347e7b,_0x29665a[_0xa3e1('0x3d')]);var _0x7769fa={'where':_0x347e7b[_0xa3e1('0x38')]};return db[_0xa3e1('0x28')][_0xa3e1('0x1e')](_0x7769fa)[_0xa3e1('0x24')](function(_0x3d0a4a){_0x425377[_0xa3e1('0x1e')]=_0x3d0a4a;if(_0x29665a['query'][_0xa3e1('0x3e')]){_0x347e7b['include']=[{'all':!![]}];}return db['FreshsalesField'][_0xa3e1('0x3f')](_0x347e7b);})[_0xa3e1('0x24')](function(_0x26d109){_0x425377['rows']=_0x26d109;return _0x425377;})['then'](respondWithFilteredResult(_0x1ba483,_0x347e7b))['catch'](handleError(_0x1ba483,null));};exports[_0xa3e1('0x40')]=function(_0x57375d,_0x7225b8){var _0x3d57e6={'raw':!![],'where':{'id':_0x57375d['params']['id']}},_0x1b5e1b={};_0x1b5e1b[_0xa3e1('0x2d')]=_[_0xa3e1('0x31')](db[_0xa3e1('0x28')][_0xa3e1('0x29')]);_0x1b5e1b[_0xa3e1('0x30')]=_[_0xa3e1('0x31')](_0x57375d['query']);_0x1b5e1b[_0xa3e1('0x39')]=_[_0xa3e1('0x32')](_0x1b5e1b['model'],_0x1b5e1b[_0xa3e1('0x30')]);_0x3d57e6[_0xa3e1('0x34')]=_[_0xa3e1('0x32')](_0x1b5e1b[_0xa3e1('0x2d')],qs['fields'](_0x57375d[_0xa3e1('0x30')][_0xa3e1('0x41')]));_0x3d57e6['attributes']=_0x3d57e6['attributes'][_0xa3e1('0x33')]?_0x3d57e6[_0xa3e1('0x34')]:_0x1b5e1b[_0xa3e1('0x2d')];if(_0x57375d['query'][_0xa3e1('0x3e')]){_0x3d57e6[_0xa3e1('0x42')]=[{'all':!![]}];}_0x3d57e6=_['merge']({},_0x3d57e6,_0x57375d[_0xa3e1('0x3d')]);return db[_0xa3e1('0x28')]['find'](_0x3d57e6)[_0xa3e1('0x24')](handleEntityNotFound(_0x7225b8,null))[_0xa3e1('0x24')](respondWithResult(_0x7225b8,null))['catch'](handleError(_0x7225b8,null));};exports[_0xa3e1('0x43')]=function(_0x4f2c04,_0x54c3d2){return db[_0xa3e1('0x28')]['create'](_0x4f2c04[_0xa3e1('0x44')],{})[_0xa3e1('0x24')](respondWithResult(_0x54c3d2,0xc9))['catch'](handleError(_0x54c3d2,null));};exports[_0xa3e1('0x23')]=function(_0x1153e1,_0x22efac){if(_0x1153e1[_0xa3e1('0x44')]['id']){delete _0x1153e1[_0xa3e1('0x44')]['id'];}return db['FreshsalesField'][_0xa3e1('0x45')]({'where':{'id':_0x1153e1[_0xa3e1('0x46')]['id']}})[_0xa3e1('0x24')](handleEntityNotFound(_0x22efac,null))[_0xa3e1('0x24')](saveUpdates(_0x1153e1['body'],null))['then'](respondWithResult(_0x22efac,null))['catch'](handleError(_0x22efac,null));};exports[_0xa3e1('0x25')]=function(_0x531208,_0x32fec9){return db[_0xa3e1('0x28')][_0xa3e1('0x45')]({'where':{'id':_0x531208['params']['id']}})['then'](handleEntityNotFound(_0x32fec9,null))[_0xa3e1('0x24')](removeEntity(_0x32fec9,null))[_0xa3e1('0x47')](handleError(_0x32fec9,null));};