185aa44eaa9eb2026ee11ad5942288eafdd5a081
[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 _0x39f8=['model','query','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','keys','length','find','create','body','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','reject','save','then','destroy','stack','name','send','index','map','ZohoField','rawAttributes','fieldName','type','key'];(function(_0x41ff30,_0x10f6f7){var _0x544f11=function(_0x270390){while(--_0x270390){_0x41ff30['push'](_0x41ff30['shift']());}};_0x544f11(++_0x10f6f7);}(_0x39f8,0xb3));var _0x839f=function(_0x147662,_0x5deefb){_0x147662=_0x147662-0x0;var _0x8e91c9=_0x39f8[_0x147662];return _0x8e91c9;};'use strict';var emlformat=require(_0x839f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x839f('0x1'));var jsonpatch=require(_0x839f('0x2'));var rp=require(_0x839f('0x3'));var moment=require(_0x839f('0x4'));var BPromise=require(_0x839f('0x5'));var Mustache=require(_0x839f('0x6'));var util=require(_0x839f('0x7'));var path=require('path');var sox=require(_0x839f('0x8'));var csv=require('to-csv');var ejs=require(_0x839f('0x9'));var fs=require('fs');var fs_extra=require(_0x839f('0xa'));var _=require('lodash');var squel=require(_0x839f('0xb'));var crypto=require('crypto');var jsforce=require(_0x839f('0xc'));var deskjs=require(_0x839f('0xd'));var toCsv=require(_0x839f('0xe'));var querystring=require(_0x839f('0xf'));var Papa=require(_0x839f('0x10'));var Redis=require(_0x839f('0x11'));var authService=require(_0x839f('0x12'));var qs=require(_0x839f('0x13'));var as=require(_0x839f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x839f('0x15'));var utils=require(_0x839f('0x16'));var config=require(_0x839f('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x839f('0x18'))['db'];function respondWithStatusCode(_0x5d619d,_0x1f77cd){_0x1f77cd=_0x1f77cd||0xcc;return function(_0x4147e4){if(_0x4147e4){return _0x5d619d[_0x839f('0x19')](_0x1f77cd);}return _0x5d619d[_0x839f('0x1a')](_0x1f77cd)[_0x839f('0x1b')]();};}function respondWithResult(_0x3dff99,_0x27e3f7){_0x27e3f7=_0x27e3f7||0xc8;return function(_0x566883){if(_0x566883){return _0x3dff99[_0x839f('0x1a')](_0x27e3f7)[_0x839f('0x1c')](_0x566883);}};}function respondWithFilteredResult(_0x1d0c25,_0xda540){return function(_0x58cf55){if(_0x58cf55){var _0x4441ed=typeof _0xda540[_0x839f('0x1d')]===_0x839f('0x1e')&&typeof _0xda540[_0x839f('0x1f')]==='undefined';var _0x1b30f1=_0x58cf55[_0x839f('0x20')];var _0x3ec6ce=_0x4441ed?0x0:_0xda540[_0x839f('0x1d')];var _0x2bb40e=_0x4441ed?_0x58cf55[_0x839f('0x20')]:_0xda540[_0x839f('0x1d')]+_0xda540['limit'];var _0x4f1fce;if(_0x2bb40e>=_0x1b30f1){_0x2bb40e=_0x1b30f1;_0x4f1fce=0xc8;}else{_0x4f1fce=0xce;}_0x1d0c25[_0x839f('0x1a')](_0x4f1fce);return _0x1d0c25[_0x839f('0x21')]('Content-Range',_0x3ec6ce+'-'+_0x2bb40e+'/'+_0x1b30f1)[_0x839f('0x1c')](_0x58cf55);}return null;};}function patchUpdates(_0x1fd5d0){return function(_0x4bfc98){try{jsonpatch[_0x839f('0x22')](_0x4bfc98,_0x1fd5d0,!![]);}catch(_0xaef648){return BPromise[_0x839f('0x23')](_0xaef648);}return _0x4bfc98[_0x839f('0x24')]();};}function saveUpdates(_0xb6b1d4,_0x217f58){return function(_0x345e13){if(_0x345e13){return _0x345e13['update'](_0xb6b1d4)[_0x839f('0x25')](function(_0x10aafd){return _0x10aafd;});}return null;};}function removeEntity(_0x2684eb,_0x188336){return function(_0x3197c2){if(_0x3197c2){return _0x3197c2[_0x839f('0x26')]()[_0x839f('0x25')](function(){_0x2684eb[_0x839f('0x1a')](0xcc)[_0x839f('0x1b')]();});}};}function handleEntityNotFound(_0x38d131,_0x4c5a03){return function(_0x3c157a){if(!_0x3c157a){_0x38d131[_0x839f('0x19')](0x194);}return _0x3c157a;};}function handleError(_0xd16c02,_0x12f981){_0x12f981=_0x12f981||0x1f4;return function(_0x250582){logger['error'](_0x250582[_0x839f('0x27')]);if(_0x250582[_0x839f('0x28')]){delete _0x250582[_0x839f('0x28')];}_0xd16c02[_0x839f('0x1a')](_0x12f981)[_0x839f('0x29')](_0x250582);};}exports[_0x839f('0x2a')]=function(_0x2f9fd0,_0x602c5){var _0x41237e={},_0x3893c7={},_0x5977f3={'count':0x0,'rows':[]};var _0x2856ab=_[_0x839f('0x2b')](db[_0x839f('0x2c')][_0x839f('0x2d')],function(_0x5ec155){return{'name':_0x5ec155[_0x839f('0x2e')],'type':_0x5ec155[_0x839f('0x2f')][_0x839f('0x30')]};});_0x3893c7[_0x839f('0x31')]=_[_0x839f('0x2b')](_0x2856ab,_0x839f('0x28'));_0x3893c7['query']=_['keys'](_0x2f9fd0[_0x839f('0x32')]);_0x3893c7[_0x839f('0x33')]=_[_0x839f('0x34')](_0x3893c7[_0x839f('0x31')],_0x3893c7[_0x839f('0x32')]);_0x41237e[_0x839f('0x35')]=_[_0x839f('0x34')](_0x3893c7[_0x839f('0x31')],qs[_0x839f('0x36')](_0x2f9fd0[_0x839f('0x32')][_0x839f('0x36')]));_0x41237e[_0x839f('0x35')]=_0x41237e[_0x839f('0x35')]['length']?_0x41237e['attributes']:_0x3893c7[_0x839f('0x31')];if(!_0x2f9fd0['query'][_0x839f('0x37')]('nolimit')){_0x41237e['limit']=qs[_0x839f('0x1f')](_0x2f9fd0['query'][_0x839f('0x1f')]);_0x41237e[_0x839f('0x1d')]=qs[_0x839f('0x1d')](_0x2f9fd0['query'][_0x839f('0x1d')]);}_0x41237e[_0x839f('0x38')]=qs[_0x839f('0x39')](_0x2f9fd0[_0x839f('0x32')][_0x839f('0x39')]);_0x41237e[_0x839f('0x3a')]=qs[_0x839f('0x33')](_[_0x839f('0x3b')](_0x2f9fd0[_0x839f('0x32')],_0x3893c7[_0x839f('0x33')]),_0x2856ab);if(_0x2f9fd0[_0x839f('0x32')]['filter']){_0x41237e['where']=_[_0x839f('0x3c')](_0x41237e[_0x839f('0x3a')],{'$or':_[_0x839f('0x2b')](_0x2856ab,function(_0x479cc4){if(_0x479cc4[_0x839f('0x2f')]!==_0x839f('0x3d')){var _0x35eec6={};_0x35eec6[_0x479cc4[_0x839f('0x28')]]={'$like':'%'+_0x2f9fd0[_0x839f('0x32')][_0x839f('0x3e')]+'%'};return _0x35eec6;}})});}_0x41237e=_[_0x839f('0x3c')]({},_0x41237e,_0x2f9fd0[_0x839f('0x3f')]);var _0xb27ce3={'where':_0x41237e['where']};return db[_0x839f('0x2c')][_0x839f('0x20')](_0xb27ce3)[_0x839f('0x25')](function(_0x231684){_0x5977f3[_0x839f('0x20')]=_0x231684;if(_0x2f9fd0[_0x839f('0x32')][_0x839f('0x40')]){_0x41237e[_0x839f('0x41')]=[{'all':!![]}];}return db[_0x839f('0x2c')][_0x839f('0x42')](_0x41237e);})['then'](function(_0xe9ad4d){_0x5977f3[_0x839f('0x43')]=_0xe9ad4d;return _0x5977f3;})[_0x839f('0x25')](respondWithFilteredResult(_0x602c5,_0x41237e))[_0x839f('0x44')](handleError(_0x602c5,null));};exports[_0x839f('0x45')]=function(_0x39c299,_0x158916){var _0x43640b={'raw':!![],'where':{'id':_0x39c299[_0x839f('0x46')]['id']}},_0xb50571={};_0xb50571[_0x839f('0x31')]=_[_0x839f('0x47')](db[_0x839f('0x2c')][_0x839f('0x2d')]);_0xb50571[_0x839f('0x32')]=_['keys'](_0x39c299[_0x839f('0x32')]);_0xb50571[_0x839f('0x33')]=_['intersection'](_0xb50571[_0x839f('0x31')],_0xb50571[_0x839f('0x32')]);_0x43640b[_0x839f('0x35')]=_[_0x839f('0x34')](_0xb50571[_0x839f('0x31')],qs[_0x839f('0x36')](_0x39c299['query']['fields']));_0x43640b['attributes']=_0x43640b[_0x839f('0x35')][_0x839f('0x48')]?_0x43640b[_0x839f('0x35')]:_0xb50571[_0x839f('0x31')];if(_0x39c299[_0x839f('0x32')][_0x839f('0x40')]){_0x43640b['include']=[{'all':!![]}];}_0x43640b=_[_0x839f('0x3c')]({},_0x43640b,_0x39c299[_0x839f('0x3f')]);return db[_0x839f('0x2c')][_0x839f('0x49')](_0x43640b)[_0x839f('0x25')](handleEntityNotFound(_0x158916,null))[_0x839f('0x25')](respondWithResult(_0x158916,null))[_0x839f('0x44')](handleError(_0x158916,null));};exports[_0x839f('0x4a')]=function(_0x1f0fe4,_0x379f65){return db[_0x839f('0x2c')][_0x839f('0x4a')](_0x1f0fe4[_0x839f('0x4b')],{})[_0x839f('0x25')](respondWithResult(_0x379f65,0xc9))[_0x839f('0x44')](handleError(_0x379f65,null));};exports['update']=function(_0x3bc38a,_0x34a617){if(_0x3bc38a[_0x839f('0x4b')]['id']){delete _0x3bc38a[_0x839f('0x4b')]['id'];}return db[_0x839f('0x2c')][_0x839f('0x49')]({'where':{'id':_0x3bc38a['params']['id']}})[_0x839f('0x25')](handleEntityNotFound(_0x34a617,null))[_0x839f('0x25')](saveUpdates(_0x3bc38a[_0x839f('0x4b')],null))['then'](respondWithResult(_0x34a617,null))[_0x839f('0x44')](handleError(_0x34a617,null));};exports[_0x839f('0x26')]=function(_0x425bc7,_0x2ff5e2){return db[_0x839f('0x2c')]['find']({'where':{'id':_0x425bc7[_0x839f('0x46')]['id']}})[_0x839f('0x25')](handleEntityNotFound(_0x2ff5e2,null))[_0x839f('0x25')](removeEntity(_0x2ff5e2,null))['catch'](handleError(_0x2ff5e2,null));};