Built motion from commit fe909640.|2.6.8
[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 _0x334f=['length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','includeAll','include','findAll','rows','catch','options','find','create','body','params','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','map','FreshsalesField','rawAttributes','fieldName','type','model','query','keys','attributes','intersection','fields'];(function(_0x46a206,_0x5c7116){var _0x19a05d=function(_0x4c1c70){while(--_0x4c1c70){_0x46a206['push'](_0x46a206['shift']());}};_0x19a05d(++_0x5c7116);}(_0x334f,0x140));var _0xf334=function(_0x3e8df9,_0x384c9b){_0x3e8df9=_0x3e8df9-0x0;var _0x4970f6=_0x334f[_0x3e8df9];return _0x4970f6;};'use strict';var emlformat=require(_0xf334('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf334('0x1'));var rp=require(_0xf334('0x2'));var moment=require(_0xf334('0x3'));var BPromise=require(_0xf334('0x4'));var Mustache=require(_0xf334('0x5'));var util=require('util');var path=require(_0xf334('0x6'));var sox=require(_0xf334('0x7'));var csv=require(_0xf334('0x8'));var ejs=require(_0xf334('0x9'));var fs=require('fs');var fs_extra=require(_0xf334('0xa'));var _=require(_0xf334('0xb'));var squel=require(_0xf334('0xc'));var crypto=require(_0xf334('0xd'));var jsforce=require(_0xf334('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xf334('0x8'));var querystring=require(_0xf334('0xf'));var Papa=require(_0xf334('0x10'));var Redis=require(_0xf334('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xf334('0x12'));var as=require(_0xf334('0x13'));var hardwareService=require(_0xf334('0x14'));var logger=require(_0xf334('0x15'))(_0xf334('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xf334('0x17'));var db=require(_0xf334('0x18'))['db'];function respondWithStatusCode(_0x4ac18e,_0x302fe8){_0x302fe8=_0x302fe8||0xcc;return function(_0x5776ad){if(_0x5776ad){return _0x4ac18e[_0xf334('0x19')](_0x302fe8);}return _0x4ac18e[_0xf334('0x1a')](_0x302fe8)[_0xf334('0x1b')]();};}function respondWithResult(_0x121320,_0x373043){_0x373043=_0x373043||0xc8;return function(_0x1433c4){if(_0x1433c4){return _0x121320['status'](_0x373043)[_0xf334('0x1c')](_0x1433c4);}};}function respondWithFilteredResult(_0x4e9e1,_0x139515){return function(_0x4e8782){if(_0x4e8782){var _0x99a55=typeof _0x139515['offset']===_0xf334('0x1d')&&typeof _0x139515[_0xf334('0x1e')]===_0xf334('0x1d');var _0x524766=_0x4e8782[_0xf334('0x1f')];var _0x20a570=_0x99a55?0x0:_0x139515[_0xf334('0x20')];var _0x5630ad=_0x99a55?_0x4e8782[_0xf334('0x1f')]:_0x139515[_0xf334('0x20')]+_0x139515['limit'];var _0xfedca3;if(_0x5630ad>=_0x524766){_0x5630ad=_0x524766;_0xfedca3=0xc8;}else{_0xfedca3=0xce;}_0x4e9e1[_0xf334('0x1a')](_0xfedca3);return _0x4e9e1[_0xf334('0x21')](_0xf334('0x22'),_0x20a570+'-'+_0x5630ad+'/'+_0x524766)[_0xf334('0x1c')](_0x4e8782);}return null;};}function patchUpdates(_0x192cd8){return function(_0x54e9fa){try{jsonpatch[_0xf334('0x23')](_0x54e9fa,_0x192cd8,!![]);}catch(_0x21d632){return BPromise[_0xf334('0x24')](_0x21d632);}return _0x54e9fa[_0xf334('0x25')]();};}function saveUpdates(_0x5d0a4c,_0x3c5636){return function(_0x31e58a){if(_0x31e58a){return _0x31e58a[_0xf334('0x26')](_0x5d0a4c)['then'](function(_0x145f46){return _0x145f46;});}return null;};}function removeEntity(_0x6d29b1,_0xab0338){return function(_0x2c575c){if(_0x2c575c){return _0x2c575c[_0xf334('0x27')]()[_0xf334('0x28')](function(){_0x6d29b1['status'](0xcc)[_0xf334('0x1b')]();});}};}function handleEntityNotFound(_0x4d3467,_0x3c8a0b){return function(_0xe68a65){if(!_0xe68a65){_0x4d3467[_0xf334('0x19')](0x194);}return _0xe68a65;};}function handleError(_0x150a2b,_0x5a8c2f){_0x5a8c2f=_0x5a8c2f||0x1f4;return function(_0x9aad51){logger[_0xf334('0x29')](_0x9aad51[_0xf334('0x2a')]);if(_0x9aad51[_0xf334('0x2b')]){delete _0x9aad51[_0xf334('0x2b')];}_0x150a2b['status'](_0x5a8c2f)['send'](_0x9aad51);};}exports['index']=function(_0x3fb41a,_0x2f1c1c){var _0x3a9ab7={},_0x3f52ad={},_0x3cd251={'count':0x0,'rows':[]};var _0x50681f=_[_0xf334('0x2c')](db[_0xf334('0x2d')][_0xf334('0x2e')],function(_0x374e68){return{'name':_0x374e68[_0xf334('0x2f')],'type':_0x374e68[_0xf334('0x30')]['key']};});_0x3f52ad[_0xf334('0x31')]=_[_0xf334('0x2c')](_0x50681f,_0xf334('0x2b'));_0x3f52ad[_0xf334('0x32')]=_[_0xf334('0x33')](_0x3fb41a['query']);_0x3f52ad['filters']=_['intersection'](_0x3f52ad[_0xf334('0x31')],_0x3f52ad['query']);_0x3a9ab7[_0xf334('0x34')]=_[_0xf334('0x35')](_0x3f52ad[_0xf334('0x31')],qs[_0xf334('0x36')](_0x3fb41a[_0xf334('0x32')][_0xf334('0x36')]));_0x3a9ab7[_0xf334('0x34')]=_0x3a9ab7['attributes'][_0xf334('0x37')]?_0x3a9ab7[_0xf334('0x34')]:_0x3f52ad[_0xf334('0x31')];if(!_0x3fb41a[_0xf334('0x32')][_0xf334('0x38')](_0xf334('0x39'))){_0x3a9ab7[_0xf334('0x1e')]=qs[_0xf334('0x1e')](_0x3fb41a[_0xf334('0x32')]['limit']);_0x3a9ab7[_0xf334('0x20')]=qs[_0xf334('0x20')](_0x3fb41a[_0xf334('0x32')][_0xf334('0x20')]);}_0x3a9ab7[_0xf334('0x3a')]=qs[_0xf334('0x3b')](_0x3fb41a[_0xf334('0x32')][_0xf334('0x3b')]);_0x3a9ab7[_0xf334('0x3c')]=qs[_0xf334('0x3d')](_[_0xf334('0x3e')](_0x3fb41a[_0xf334('0x32')],_0x3f52ad['filters']),_0x50681f);if(_0x3fb41a['query'][_0xf334('0x3f')]){_0x3a9ab7['where']=_[_0xf334('0x40')](_0x3a9ab7[_0xf334('0x3c')],{'$or':_[_0xf334('0x2c')](_0x50681f,function(_0x12c761){if(_0x12c761[_0xf334('0x30')]!=='VIRTUAL'){var _0x18511f={};_0x18511f[_0x12c761[_0xf334('0x2b')]]={'$like':'%'+_0x3fb41a[_0xf334('0x32')][_0xf334('0x3f')]+'%'};return _0x18511f;}})});}_0x3a9ab7=_['merge']({},_0x3a9ab7,_0x3fb41a['options']);var _0x5f5781={'where':_0x3a9ab7[_0xf334('0x3c')]};return db[_0xf334('0x2d')]['count'](_0x5f5781)[_0xf334('0x28')](function(_0x5c1016){_0x3cd251[_0xf334('0x1f')]=_0x5c1016;if(_0x3fb41a[_0xf334('0x32')][_0xf334('0x41')]){_0x3a9ab7[_0xf334('0x42')]=[{'all':!![]}];}return db[_0xf334('0x2d')][_0xf334('0x43')](_0x3a9ab7);})['then'](function(_0x189c8d){_0x3cd251[_0xf334('0x44')]=_0x189c8d;return _0x3cd251;})[_0xf334('0x28')](respondWithFilteredResult(_0x2f1c1c,_0x3a9ab7))[_0xf334('0x45')](handleError(_0x2f1c1c,null));};exports['show']=function(_0x30925f,_0x823e9b){var _0xe527bf={'raw':!![],'where':{'id':_0x30925f['params']['id']}},_0x231f06={};_0x231f06['model']=_[_0xf334('0x33')](db[_0xf334('0x2d')][_0xf334('0x2e')]);_0x231f06[_0xf334('0x32')]=_[_0xf334('0x33')](_0x30925f['query']);_0x231f06[_0xf334('0x3d')]=_[_0xf334('0x35')](_0x231f06[_0xf334('0x31')],_0x231f06[_0xf334('0x32')]);_0xe527bf['attributes']=_[_0xf334('0x35')](_0x231f06['model'],qs[_0xf334('0x36')](_0x30925f[_0xf334('0x32')][_0xf334('0x36')]));_0xe527bf[_0xf334('0x34')]=_0xe527bf['attributes']['length']?_0xe527bf[_0xf334('0x34')]:_0x231f06[_0xf334('0x31')];if(_0x30925f['query'][_0xf334('0x41')]){_0xe527bf[_0xf334('0x42')]=[{'all':!![]}];}_0xe527bf=_[_0xf334('0x40')]({},_0xe527bf,_0x30925f[_0xf334('0x46')]);return db[_0xf334('0x2d')][_0xf334('0x47')](_0xe527bf)['then'](handleEntityNotFound(_0x823e9b,null))[_0xf334('0x28')](respondWithResult(_0x823e9b,null))[_0xf334('0x45')](handleError(_0x823e9b,null));};exports[_0xf334('0x48')]=function(_0x241462,_0x8e67fc){return db[_0xf334('0x2d')][_0xf334('0x48')](_0x241462[_0xf334('0x49')],{})[_0xf334('0x28')](respondWithResult(_0x8e67fc,0xc9))[_0xf334('0x45')](handleError(_0x8e67fc,null));};exports[_0xf334('0x26')]=function(_0x5e17ae,_0xdf037c){if(_0x5e17ae[_0xf334('0x49')]['id']){delete _0x5e17ae[_0xf334('0x49')]['id'];}return db['FreshsalesField'][_0xf334('0x47')]({'where':{'id':_0x5e17ae['params']['id']}})[_0xf334('0x28')](handleEntityNotFound(_0xdf037c,null))[_0xf334('0x28')](saveUpdates(_0x5e17ae[_0xf334('0x49')],null))['then'](respondWithResult(_0xdf037c,null))[_0xf334('0x45')](handleError(_0xdf037c,null));};exports['destroy']=function(_0x5e2e71,_0x2745dc){return db[_0xf334('0x2d')][_0xf334('0x47')]({'where':{'id':_0x5e2e71[_0xf334('0x4a')]['id']}})['then'](handleEntityNotFound(_0x2745dc,null))['then'](removeEntity(_0x2745dc,null))['catch'](handleError(_0x2745dc,null));};