d24a7cc0b12a9df2a32c971518a85afd997fa13b
[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 _0x9e88=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','json','count','offset','limit','status','set','Content-Range','save','update','destroy','then','error','stack','name','index','FreshsalesField','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','rows','catch','params','includeAll','options','find','create','body','html-pdf','rimraf','zip-dir','request-promise','bluebird','mustache','sox','ejs','squel','crypto','desk.js','to-csv','querystring','papaparse'];(function(_0xcf5f30,_0x3d08c6){var _0x1e174f=function(_0x3a056e){while(--_0x3a056e){_0xcf5f30['push'](_0xcf5f30['shift']());}};_0x1e174f(++_0x3d08c6);}(_0x9e88,0x1ce));var _0x89e8=function(_0x27bbaa,_0x11f6ef){_0x27bbaa=_0x27bbaa-0x0;var _0x1fcf65=_0x9e88[_0x27bbaa];return _0x1fcf65;};'use strict';var pdf=require(_0x89e8('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x89e8('0x1'));var zipdir=require(_0x89e8('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x89e8('0x3'));var moment=require('moment');var BPromise=require(_0x89e8('0x4'));var Mustache=require(_0x89e8('0x5'));var util=require('util');var path=require('path');var sox=require(_0x89e8('0x6'));var csv=require('to-csv');var ejs=require(_0x89e8('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0x89e8('0x8'));var crypto=require(_0x89e8('0x9'));var jsforce=require('jsforce');var deskjs=require(_0x89e8('0xa'));var toCsv=require(_0x89e8('0xb'));var querystring=require(_0x89e8('0xc'));var Papa=require(_0x89e8('0xd'));var Redis=require(_0x89e8('0xe'));var authService=require(_0x89e8('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x89e8('0x10'));var hardwareService=require(_0x89e8('0x11'));var logger=require(_0x89e8('0x12'))('api');var utils=require(_0x89e8('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x89e8('0x14'));var db=require(_0x89e8('0x15'))['db'];function respondWithStatusCode(_0xdcd558,_0x19af40){_0x19af40=_0x19af40||0xcc;return function(_0x41ae99){if(_0x41ae99){return _0xdcd558[_0x89e8('0x16')](_0x19af40);}return _0xdcd558['status'](_0x19af40)[_0x89e8('0x17')]();};}function respondWithResult(_0x4d8ffb,_0x22c7ca){_0x22c7ca=_0x22c7ca||0xc8;return function(_0x1d0983){if(_0x1d0983){return _0x4d8ffb['status'](_0x22c7ca)[_0x89e8('0x18')](_0x1d0983);}};}function respondWithFilteredResult(_0x48294b,_0x16f2d4){return function(_0x42adac){if(_0x42adac){var _0xc69884=_0x42adac[_0x89e8('0x19')],_0xe8598b=_0x16f2d4[_0x89e8('0x1a')],_0x66d4fc=_0x16f2d4[_0x89e8('0x1a')]+_0x16f2d4[_0x89e8('0x1b')],_0x252279;if(_0x66d4fc>=_0xc69884){_0x66d4fc=_0xc69884;_0x252279=0xc8;}else{_0x252279=0xce;}_0x48294b[_0x89e8('0x1c')](_0x252279);return _0x48294b[_0x89e8('0x1d')](_0x89e8('0x1e'),_0xe8598b+'-'+_0x66d4fc+'/'+_0xc69884)[_0x89e8('0x18')](_0x42adac);}return null;};}function patchUpdates(_0x2f6491){return function(_0x4ba417){try{jsonpatch['apply'](_0x4ba417,_0x2f6491,!![]);}catch(_0x5dbe1f){return BPromise['reject'](_0x5dbe1f);}return _0x4ba417[_0x89e8('0x1f')]();};}function saveUpdates(_0x4120c8,_0x3f16ba){return function(_0x19c0b1){if(_0x19c0b1){return _0x19c0b1[_0x89e8('0x20')](_0x4120c8)['then'](function(_0x33f1d5){return _0x33f1d5;});}return null;};}function removeEntity(_0x3f0d9e,_0x2caefc){return function(_0x243db3){if(_0x243db3){return _0x243db3[_0x89e8('0x21')]()[_0x89e8('0x22')](function(){_0x3f0d9e[_0x89e8('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x20c1c1,_0x5c18a8){return function(_0x4eae32){if(!_0x4eae32){_0x20c1c1['sendStatus'](0x194);}return _0x4eae32;};}function handleError(_0x11d2c9,_0x5a8505){_0x5a8505=_0x5a8505||0x1f4;return function(_0x3e5f0b){logger[_0x89e8('0x23')](_0x3e5f0b[_0x89e8('0x24')]);if(_0x3e5f0b[_0x89e8('0x25')]){delete _0x3e5f0b[_0x89e8('0x25')];}_0x11d2c9['status'](_0x5a8505)['send'](_0x3e5f0b);};}exports[_0x89e8('0x26')]=function(_0x2501e1,_0x5c7ccc){var _0x343ba7={},_0x59ce73={},_0x362445={'count':0x0,'rows':[]};var _0xa4b595=_['map'](db[_0x89e8('0x27')][_0x89e8('0x28')],function(_0x7c1d64){return{'name':_0x7c1d64[_0x89e8('0x29')],'type':_0x7c1d64[_0x89e8('0x2a')][_0x89e8('0x2b')]};});_0x59ce73[_0x89e8('0x2c')]=_[_0x89e8('0x2d')](_0xa4b595,_0x89e8('0x25'));_0x59ce73[_0x89e8('0x2e')]=_[_0x89e8('0x2f')](_0x2501e1['query']);_0x59ce73[_0x89e8('0x30')]=_[_0x89e8('0x31')](_0x59ce73['model'],_0x59ce73[_0x89e8('0x2e')]);_0x343ba7[_0x89e8('0x32')]=_[_0x89e8('0x31')](_0x59ce73[_0x89e8('0x2c')],qs['fields'](_0x2501e1[_0x89e8('0x2e')][_0x89e8('0x33')]));_0x343ba7[_0x89e8('0x32')]=_0x343ba7['attributes'][_0x89e8('0x34')]?_0x343ba7[_0x89e8('0x32')]:_0x59ce73[_0x89e8('0x2c')];if(!_0x2501e1[_0x89e8('0x2e')]['hasOwnProperty'](_0x89e8('0x35'))){_0x343ba7[_0x89e8('0x1b')]=qs[_0x89e8('0x1b')](_0x2501e1[_0x89e8('0x2e')][_0x89e8('0x1b')]);_0x343ba7['offset']=qs[_0x89e8('0x1a')](_0x2501e1['query'][_0x89e8('0x1a')]);}_0x343ba7[_0x89e8('0x36')]=qs[_0x89e8('0x37')](_0x2501e1['query'][_0x89e8('0x37')]);_0x343ba7[_0x89e8('0x38')]=qs['filters'](_[_0x89e8('0x39')](_0x2501e1[_0x89e8('0x2e')],_0x59ce73[_0x89e8('0x30')]),_0xa4b595);if(_0x2501e1[_0x89e8('0x2e')][_0x89e8('0x3a')]){_0x343ba7[_0x89e8('0x38')]=_[_0x89e8('0x3b')](_0x343ba7[_0x89e8('0x38')],{'$or':_[_0x89e8('0x2d')](_0xa4b595,function(_0x13a384){if(_0x13a384['type']!=='VIRTUAL'){var _0xf61acc={};_0xf61acc[_0x13a384[_0x89e8('0x25')]]={'$like':'%'+_0x2501e1[_0x89e8('0x2e')][_0x89e8('0x3a')]+'%'};return _0xf61acc;}})});}_0x343ba7=_[_0x89e8('0x3b')]({},_0x343ba7,_0x2501e1['options']);var _0x62d71d={'where':_0x343ba7[_0x89e8('0x38')]};return db[_0x89e8('0x27')][_0x89e8('0x19')](_0x62d71d)[_0x89e8('0x22')](function(_0x313c8d){_0x362445[_0x89e8('0x19')]=_0x313c8d;if(_0x2501e1[_0x89e8('0x2e')]['includeAll']){_0x343ba7['include']=[{'all':!![]}];}return db[_0x89e8('0x27')]['findAll'](_0x343ba7);})['then'](function(_0x457801){_0x362445[_0x89e8('0x3c')]=_0x457801;return _0x362445;})['then'](respondWithFilteredResult(_0x5c7ccc,_0x343ba7))[_0x89e8('0x3d')](handleError(_0x5c7ccc,null));};exports['show']=function(_0x12b54a,_0x4be4f6){var _0x403ae5={'raw':!![],'where':{'id':_0x12b54a[_0x89e8('0x3e')]['id']}},_0x221f47={};_0x221f47[_0x89e8('0x2c')]=_[_0x89e8('0x2f')](db[_0x89e8('0x27')][_0x89e8('0x28')]);_0x221f47[_0x89e8('0x2e')]=_[_0x89e8('0x2f')](_0x12b54a[_0x89e8('0x2e')]);_0x221f47[_0x89e8('0x30')]=_['intersection'](_0x221f47[_0x89e8('0x2c')],_0x221f47[_0x89e8('0x2e')]);_0x403ae5[_0x89e8('0x32')]=_[_0x89e8('0x31')](_0x221f47[_0x89e8('0x2c')],qs['fields'](_0x12b54a[_0x89e8('0x2e')]['fields']));_0x403ae5[_0x89e8('0x32')]=_0x403ae5[_0x89e8('0x32')]['length']?_0x403ae5[_0x89e8('0x32')]:_0x221f47[_0x89e8('0x2c')];if(_0x12b54a['query'][_0x89e8('0x3f')]){_0x403ae5['include']=[{'all':!![]}];}_0x403ae5=_[_0x89e8('0x3b')]({},_0x403ae5,_0x12b54a[_0x89e8('0x40')]);return db[_0x89e8('0x27')][_0x89e8('0x41')](_0x403ae5)[_0x89e8('0x22')](handleEntityNotFound(_0x4be4f6,null))[_0x89e8('0x22')](respondWithResult(_0x4be4f6,null))['catch'](handleError(_0x4be4f6,null));};exports['create']=function(_0x1ef511,_0x5a203a){return db[_0x89e8('0x27')][_0x89e8('0x42')](_0x1ef511[_0x89e8('0x43')],{})[_0x89e8('0x22')](respondWithResult(_0x5a203a,0xc9))[_0x89e8('0x3d')](handleError(_0x5a203a,null));};exports[_0x89e8('0x20')]=function(_0xa39944,_0x3967b3){if(_0xa39944[_0x89e8('0x43')]['id']){delete _0xa39944[_0x89e8('0x43')]['id'];}return db[_0x89e8('0x27')][_0x89e8('0x41')]({'where':{'id':_0xa39944['params']['id']}})[_0x89e8('0x22')](handleEntityNotFound(_0x3967b3,null))[_0x89e8('0x22')](saveUpdates(_0xa39944[_0x89e8('0x43')],null))[_0x89e8('0x22')](respondWithResult(_0x3967b3,null))[_0x89e8('0x3d')](handleError(_0x3967b3,null));};exports['destroy']=function(_0x454758,_0x1b64e1){return db[_0x89e8('0x27')][_0x89e8('0x41')]({'where':{'id':_0x454758[_0x89e8('0x3e')]['id']}})[_0x89e8('0x22')](handleEntityNotFound(_0x1b64e1,null))[_0x89e8('0x22')](removeEntity(_0x1b64e1,null))[_0x89e8('0x3d')](handleError(_0x1b64e1,null));};