2d020ff8f544f4caca0eec5ef15fd2622b826d8a
[motion2.git] / server / api / intZohoField / intZohoField.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 _0xac9b=['zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','ejs','fs-extra','squel','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','ZohoField','rawAttributes','fieldName','type','map','query','keys','filters','intersection','attributes','model','fields','length','hasOwnProperty','order','sort','where','pick','VIRTUAL','filter','merge','options','includeAll','findAll','catch','find','create','body','params','rimraf'];(function(_0x36c270,_0x2569ff){var _0x276c73=function(_0x27ea41){while(--_0x27ea41){_0x36c270['push'](_0x36c270['shift']());}};_0x276c73(++_0x2569ff);}(_0xac9b,0x8d));var _0xbac9=function(_0x5f1617,_0x46277b){_0x5f1617=_0x5f1617-0x0;var _0x3af5da=_0xac9b[_0x5f1617];return _0x3af5da;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbac9('0x0'));var zipdir=require(_0xbac9('0x1'));var jsonpatch=require(_0xbac9('0x2'));var rp=require(_0xbac9('0x3'));var moment=require(_0xbac9('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xbac9('0x5'));var util=require(_0xbac9('0x6'));var path=require(_0xbac9('0x7'));var sox=require(_0xbac9('0x8'));var csv=require('to-csv');var ejs=require(_0xbac9('0x9'));var fs=require('fs');var fs_extra=require(_0xbac9('0xa'));var _=require('lodash');var squel=require(_0xbac9('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xbac9('0xc'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xbac9('0xd'));var authService=require(_0xbac9('0xe'));var qs=require(_0xbac9('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbac9('0x10'));var logger=require(_0xbac9('0x11'))('api');var utils=require(_0xbac9('0x12'));var config=require(_0xbac9('0x13'));var licenseUtil=require(_0xbac9('0x14'));var db=require(_0xbac9('0x15'))['db'];function respondWithStatusCode(_0x2ff50f,_0x5df52d){_0x5df52d=_0x5df52d||0xcc;return function(_0x126837){if(_0x126837){return _0x2ff50f[_0xbac9('0x16')](_0x5df52d);}return _0x2ff50f[_0xbac9('0x17')](_0x5df52d)[_0xbac9('0x18')]();};}function respondWithResult(_0x137001,_0x345e3f){_0x345e3f=_0x345e3f||0xc8;return function(_0x58bfe5){if(_0x58bfe5){return _0x137001[_0xbac9('0x17')](_0x345e3f)[_0xbac9('0x19')](_0x58bfe5);}};}function respondWithFilteredResult(_0xd9057b,_0x457a43){return function(_0x35b14e){if(_0x35b14e){var _0x2e6d06=typeof _0x457a43[_0xbac9('0x1a')]===_0xbac9('0x1b')&&typeof _0x457a43[_0xbac9('0x1c')]===_0xbac9('0x1b');var _0x36b939=_0x35b14e[_0xbac9('0x1d')];var _0x1afc3d=_0x2e6d06?0x0:_0x457a43[_0xbac9('0x1a')];var _0x4b6bac=_0x2e6d06?_0x35b14e[_0xbac9('0x1d')]:_0x457a43['offset']+_0x457a43[_0xbac9('0x1c')];var _0x16d269;if(_0x4b6bac>=_0x36b939){_0x4b6bac=_0x36b939;_0x16d269=0xc8;}else{_0x16d269=0xce;}_0xd9057b['status'](_0x16d269);return _0xd9057b[_0xbac9('0x1e')](_0xbac9('0x1f'),_0x1afc3d+'-'+_0x4b6bac+'/'+_0x36b939)[_0xbac9('0x19')](_0x35b14e);}return null;};}function patchUpdates(_0x7b279d){return function(_0x8d1fa7){try{jsonpatch[_0xbac9('0x20')](_0x8d1fa7,_0x7b279d,!![]);}catch(_0x37ebd8){return BPromise[_0xbac9('0x21')](_0x37ebd8);}return _0x8d1fa7[_0xbac9('0x22')]();};}function saveUpdates(_0x27b5a3,_0x27d6ec){return function(_0x32ac2c){if(_0x32ac2c){return _0x32ac2c[_0xbac9('0x23')](_0x27b5a3)[_0xbac9('0x24')](function(_0x6b91c3){return _0x6b91c3;});}return null;};}function removeEntity(_0x513bca,_0x7d8976){return function(_0x501fe6){if(_0x501fe6){return _0x501fe6[_0xbac9('0x25')]()[_0xbac9('0x24')](function(){_0x513bca[_0xbac9('0x17')](0xcc)[_0xbac9('0x18')]();});}};}function handleEntityNotFound(_0x1b7fcd,_0x509763){return function(_0x5a0ca4){if(!_0x5a0ca4){_0x1b7fcd[_0xbac9('0x16')](0x194);}return _0x5a0ca4;};}function handleError(_0x5a62ee,_0x13b7ad){_0x13b7ad=_0x13b7ad||0x1f4;return function(_0x9c760f){logger[_0xbac9('0x26')](_0x9c760f[_0xbac9('0x27')]);if(_0x9c760f['name']){delete _0x9c760f[_0xbac9('0x28')];}_0x5a62ee['status'](_0x13b7ad)[_0xbac9('0x29')](_0x9c760f);};}exports['index']=function(_0xcda4,_0x63995a){var _0x72e0c9={},_0x23bc7c={},_0x776b1c={'count':0x0,'rows':[]};var _0x3b5046=_['map'](db[_0xbac9('0x2a')][_0xbac9('0x2b')],function(_0x42ae51){return{'name':_0x42ae51[_0xbac9('0x2c')],'type':_0x42ae51[_0xbac9('0x2d')]['key']};});_0x23bc7c['model']=_[_0xbac9('0x2e')](_0x3b5046,_0xbac9('0x28'));_0x23bc7c[_0xbac9('0x2f')]=_[_0xbac9('0x30')](_0xcda4[_0xbac9('0x2f')]);_0x23bc7c[_0xbac9('0x31')]=_[_0xbac9('0x32')](_0x23bc7c['model'],_0x23bc7c[_0xbac9('0x2f')]);_0x72e0c9[_0xbac9('0x33')]=_[_0xbac9('0x32')](_0x23bc7c[_0xbac9('0x34')],qs[_0xbac9('0x35')](_0xcda4[_0xbac9('0x2f')][_0xbac9('0x35')]));_0x72e0c9['attributes']=_0x72e0c9[_0xbac9('0x33')][_0xbac9('0x36')]?_0x72e0c9[_0xbac9('0x33')]:_0x23bc7c[_0xbac9('0x34')];if(!_0xcda4[_0xbac9('0x2f')][_0xbac9('0x37')]('nolimit')){_0x72e0c9[_0xbac9('0x1c')]=qs[_0xbac9('0x1c')](_0xcda4['query'][_0xbac9('0x1c')]);_0x72e0c9[_0xbac9('0x1a')]=qs[_0xbac9('0x1a')](_0xcda4[_0xbac9('0x2f')][_0xbac9('0x1a')]);}_0x72e0c9[_0xbac9('0x38')]=qs[_0xbac9('0x39')](_0xcda4[_0xbac9('0x2f')][_0xbac9('0x39')]);_0x72e0c9[_0xbac9('0x3a')]=qs['filters'](_[_0xbac9('0x3b')](_0xcda4[_0xbac9('0x2f')],_0x23bc7c[_0xbac9('0x31')]),_0x3b5046);if(_0xcda4[_0xbac9('0x2f')]['filter']){_0x72e0c9[_0xbac9('0x3a')]=_['merge'](_0x72e0c9[_0xbac9('0x3a')],{'$or':_[_0xbac9('0x2e')](_0x3b5046,function(_0xfbde22){if(_0xfbde22[_0xbac9('0x2d')]!==_0xbac9('0x3c')){var _0x127c39={};_0x127c39[_0xfbde22['name']]={'$like':'%'+_0xcda4[_0xbac9('0x2f')][_0xbac9('0x3d')]+'%'};return _0x127c39;}})});}_0x72e0c9=_[_0xbac9('0x3e')]({},_0x72e0c9,_0xcda4[_0xbac9('0x3f')]);var _0x84c9d9={'where':_0x72e0c9[_0xbac9('0x3a')]};return db[_0xbac9('0x2a')][_0xbac9('0x1d')](_0x84c9d9)[_0xbac9('0x24')](function(_0x4e1f26){_0x776b1c['count']=_0x4e1f26;if(_0xcda4[_0xbac9('0x2f')][_0xbac9('0x40')]){_0x72e0c9['include']=[{'all':!![]}];}return db[_0xbac9('0x2a')][_0xbac9('0x41')](_0x72e0c9);})['then'](function(_0x20f73d){_0x776b1c['rows']=_0x20f73d;return _0x776b1c;})[_0xbac9('0x24')](respondWithFilteredResult(_0x63995a,_0x72e0c9))[_0xbac9('0x42')](handleError(_0x63995a,null));};exports['show']=function(_0x4c48ba,_0xbfe2e2){var _0x23198b={'raw':!![],'where':{'id':_0x4c48ba['params']['id']}},_0x2eb47e={};_0x2eb47e[_0xbac9('0x34')]=_[_0xbac9('0x30')](db[_0xbac9('0x2a')]['rawAttributes']);_0x2eb47e[_0xbac9('0x2f')]=_[_0xbac9('0x30')](_0x4c48ba[_0xbac9('0x2f')]);_0x2eb47e['filters']=_[_0xbac9('0x32')](_0x2eb47e[_0xbac9('0x34')],_0x2eb47e[_0xbac9('0x2f')]);_0x23198b[_0xbac9('0x33')]=_[_0xbac9('0x32')](_0x2eb47e[_0xbac9('0x34')],qs[_0xbac9('0x35')](_0x4c48ba[_0xbac9('0x2f')][_0xbac9('0x35')]));_0x23198b[_0xbac9('0x33')]=_0x23198b['attributes'][_0xbac9('0x36')]?_0x23198b[_0xbac9('0x33')]:_0x2eb47e[_0xbac9('0x34')];if(_0x4c48ba['query'][_0xbac9('0x40')]){_0x23198b['include']=[{'all':!![]}];}_0x23198b=_[_0xbac9('0x3e')]({},_0x23198b,_0x4c48ba[_0xbac9('0x3f')]);return db[_0xbac9('0x2a')][_0xbac9('0x43')](_0x23198b)[_0xbac9('0x24')](handleEntityNotFound(_0xbfe2e2,null))[_0xbac9('0x24')](respondWithResult(_0xbfe2e2,null))['catch'](handleError(_0xbfe2e2,null));};exports[_0xbac9('0x44')]=function(_0x408c91,_0x4cd992){return db['ZohoField'][_0xbac9('0x44')](_0x408c91[_0xbac9('0x45')],{})[_0xbac9('0x24')](respondWithResult(_0x4cd992,0xc9))[_0xbac9('0x42')](handleError(_0x4cd992,null));};exports[_0xbac9('0x23')]=function(_0x4b8d51,_0x4b83f4){if(_0x4b8d51[_0xbac9('0x45')]['id']){delete _0x4b8d51[_0xbac9('0x45')]['id'];}return db[_0xbac9('0x2a')][_0xbac9('0x43')]({'where':{'id':_0x4b8d51['params']['id']}})[_0xbac9('0x24')](handleEntityNotFound(_0x4b83f4,null))[_0xbac9('0x24')](saveUpdates(_0x4b8d51['body'],null))[_0xbac9('0x24')](respondWithResult(_0x4b83f4,null))['catch'](handleError(_0x4b83f4,null));};exports['destroy']=function(_0x4ec98c,_0x4a3a4a){return db[_0xbac9('0x2a')]['find']({'where':{'id':_0x4ec98c[_0xbac9('0x46')]['id']}})[_0xbac9('0x24')](handleEntityNotFound(_0x4a3a4a,null))[_0xbac9('0x24')](removeEntity(_0x4a3a4a,null))[_0xbac9('0x42')](handleError(_0x4a3a4a,null));};