Built motion from commit c116dc8b.|2.6.30
[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 _0x5cea=['where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','create','update','body','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','then','destroy','sendStatus','name','send','ZohoField','fieldName','type','model','map','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort'];(function(_0x5072ea,_0x2f0aab){var _0x4ff860=function(_0x99c327){while(--_0x99c327){_0x5072ea['push'](_0x5072ea['shift']());}};_0x4ff860(++_0x2f0aab);}(_0x5cea,0x138));var _0xa5ce=function(_0x4a475a,_0x257a36){_0x4a475a=_0x4a475a-0x0;var _0x2e63d6=_0x5cea[_0x4a475a];return _0x2e63d6;};'use strict';var emlformat=require(_0xa5ce('0x0'));var rimraf=require(_0xa5ce('0x1'));var zipdir=require(_0xa5ce('0x2'));var jsonpatch=require(_0xa5ce('0x3'));var rp=require(_0xa5ce('0x4'));var moment=require(_0xa5ce('0x5'));var BPromise=require(_0xa5ce('0x6'));var Mustache=require(_0xa5ce('0x7'));var util=require(_0xa5ce('0x8'));var path=require(_0xa5ce('0x9'));var sox=require('sox');var csv=require(_0xa5ce('0xa'));var ejs=require(_0xa5ce('0xb'));var fs=require('fs');var fs_extra=require(_0xa5ce('0xc'));var _=require(_0xa5ce('0xd'));var squel=require(_0xa5ce('0xe'));var crypto=require(_0xa5ce('0xf'));var jsforce=require(_0xa5ce('0x10'));var deskjs=require(_0xa5ce('0x11'));var toCsv=require(_0xa5ce('0xa'));var querystring=require(_0xa5ce('0x12'));var Papa=require('papaparse');var Redis=require(_0xa5ce('0x13'));var authService=require('../../components/auth/service');var qs=require(_0xa5ce('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xa5ce('0x15'));var logger=require('../../config/logger')(_0xa5ce('0x16'));var utils=require(_0xa5ce('0x17'));var config=require(_0xa5ce('0x18'));var licenseUtil=require(_0xa5ce('0x19'));var db=require(_0xa5ce('0x1a'))['db'];function respondWithStatusCode(_0x42e37c,_0x5e5305){_0x5e5305=_0x5e5305||0xcc;return function(_0x599f2b){if(_0x599f2b){return _0x42e37c['sendStatus'](_0x5e5305);}return _0x42e37c['status'](_0x5e5305)['end']();};}function respondWithResult(_0x3844c2,_0x10c57a){_0x10c57a=_0x10c57a||0xc8;return function(_0x50c558){if(_0x50c558){return _0x3844c2[_0xa5ce('0x1b')](_0x10c57a)[_0xa5ce('0x1c')](_0x50c558);}};}function respondWithFilteredResult(_0x5a4210,_0x10901e){return function(_0x206788){if(_0x206788){var _0xcd8815=typeof _0x10901e[_0xa5ce('0x1d')]==='undefined'&&typeof _0x10901e['limit']===_0xa5ce('0x1e');var _0x262b0b=_0x206788[_0xa5ce('0x1f')];var _0x2ab552=_0xcd8815?0x0:_0x10901e[_0xa5ce('0x1d')];var _0x481873=_0xcd8815?_0x206788['count']:_0x10901e[_0xa5ce('0x1d')]+_0x10901e[_0xa5ce('0x20')];var _0x1aea88;if(_0x481873>=_0x262b0b){_0x481873=_0x262b0b;_0x1aea88=0xc8;}else{_0x1aea88=0xce;}_0x5a4210['status'](_0x1aea88);return _0x5a4210[_0xa5ce('0x21')](_0xa5ce('0x22'),_0x2ab552+'-'+_0x481873+'/'+_0x262b0b)[_0xa5ce('0x1c')](_0x206788);}return null;};}function patchUpdates(_0x191a02){return function(_0x5dba55){try{jsonpatch[_0xa5ce('0x23')](_0x5dba55,_0x191a02,!![]);}catch(_0x163cb8){return BPromise[_0xa5ce('0x24')](_0x163cb8);}return _0x5dba55[_0xa5ce('0x25')]();};}function saveUpdates(_0x3767b9,_0xd55fea){return function(_0x461b66){if(_0x461b66){return _0x461b66['update'](_0x3767b9)[_0xa5ce('0x26')](function(_0x58858e){return _0x58858e;});}return null;};}function removeEntity(_0x3ee707,_0x1b8887){return function(_0x1112ac){if(_0x1112ac){return _0x1112ac[_0xa5ce('0x27')]()[_0xa5ce('0x26')](function(){_0x3ee707['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x1c7de6,_0xa8fcaa){return function(_0x179ecb){if(!_0x179ecb){_0x1c7de6[_0xa5ce('0x28')](0x194);}return _0x179ecb;};}function handleError(_0x45ad6c,_0x1a4b7a){_0x1a4b7a=_0x1a4b7a||0x1f4;return function(_0x363fe2){logger['error'](_0x363fe2['stack']);if(_0x363fe2[_0xa5ce('0x29')]){delete _0x363fe2[_0xa5ce('0x29')];}_0x45ad6c[_0xa5ce('0x1b')](_0x1a4b7a)[_0xa5ce('0x2a')](_0x363fe2);};}exports['index']=function(_0x197453,_0x3ebcdf){var _0x20b59f={},_0x5dcb9b={},_0x732213={'count':0x0,'rows':[]};var _0x257221=_['map'](db[_0xa5ce('0x2b')]['rawAttributes'],function(_0x7928b3){return{'name':_0x7928b3[_0xa5ce('0x2c')],'type':_0x7928b3[_0xa5ce('0x2d')]['key']};});_0x5dcb9b[_0xa5ce('0x2e')]=_[_0xa5ce('0x2f')](_0x257221,'name');_0x5dcb9b['query']=_[_0xa5ce('0x30')](_0x197453[_0xa5ce('0x31')]);_0x5dcb9b[_0xa5ce('0x32')]=_[_0xa5ce('0x33')](_0x5dcb9b[_0xa5ce('0x2e')],_0x5dcb9b[_0xa5ce('0x31')]);_0x20b59f['attributes']=_['intersection'](_0x5dcb9b[_0xa5ce('0x2e')],qs[_0xa5ce('0x34')](_0x197453[_0xa5ce('0x31')][_0xa5ce('0x34')]));_0x20b59f[_0xa5ce('0x35')]=_0x20b59f[_0xa5ce('0x35')][_0xa5ce('0x36')]?_0x20b59f[_0xa5ce('0x35')]:_0x5dcb9b[_0xa5ce('0x2e')];if(!_0x197453[_0xa5ce('0x31')][_0xa5ce('0x37')]('nolimit')){_0x20b59f['limit']=qs[_0xa5ce('0x20')](_0x197453['query'][_0xa5ce('0x20')]);_0x20b59f[_0xa5ce('0x1d')]=qs[_0xa5ce('0x1d')](_0x197453[_0xa5ce('0x31')][_0xa5ce('0x1d')]);}_0x20b59f[_0xa5ce('0x38')]=qs[_0xa5ce('0x39')](_0x197453[_0xa5ce('0x31')]['sort']);_0x20b59f[_0xa5ce('0x3a')]=qs[_0xa5ce('0x32')](_['pick'](_0x197453[_0xa5ce('0x31')],_0x5dcb9b[_0xa5ce('0x32')]),_0x257221);if(_0x197453['query'][_0xa5ce('0x3b')]){_0x20b59f[_0xa5ce('0x3a')]=_[_0xa5ce('0x3c')](_0x20b59f[_0xa5ce('0x3a')],{'$or':_[_0xa5ce('0x2f')](_0x257221,function(_0x4c0038){if(_0x4c0038[_0xa5ce('0x2d')]!==_0xa5ce('0x3d')){var _0x5559be={};_0x5559be[_0x4c0038[_0xa5ce('0x29')]]={'$like':'%'+_0x197453[_0xa5ce('0x31')][_0xa5ce('0x3b')]+'%'};return _0x5559be;}})});}_0x20b59f=_['merge']({},_0x20b59f,_0x197453[_0xa5ce('0x3e')]);var _0x41c209={'where':_0x20b59f[_0xa5ce('0x3a')]};return db['ZohoField'][_0xa5ce('0x1f')](_0x41c209)[_0xa5ce('0x26')](function(_0x5f784f){_0x732213[_0xa5ce('0x1f')]=_0x5f784f;if(_0x197453[_0xa5ce('0x31')][_0xa5ce('0x3f')]){_0x20b59f[_0xa5ce('0x40')]=[{'all':!![]}];}return db[_0xa5ce('0x2b')][_0xa5ce('0x41')](_0x20b59f);})[_0xa5ce('0x26')](function(_0x3ac622){_0x732213[_0xa5ce('0x42')]=_0x3ac622;return _0x732213;})[_0xa5ce('0x26')](respondWithFilteredResult(_0x3ebcdf,_0x20b59f))[_0xa5ce('0x43')](handleError(_0x3ebcdf,null));};exports[_0xa5ce('0x44')]=function(_0x54a5e8,_0x375c9a){var _0x23e679={'raw':!![],'where':{'id':_0x54a5e8[_0xa5ce('0x45')]['id']}},_0x19c8e0={};_0x19c8e0[_0xa5ce('0x2e')]=_[_0xa5ce('0x30')](db['ZohoField']['rawAttributes']);_0x19c8e0[_0xa5ce('0x31')]=_[_0xa5ce('0x30')](_0x54a5e8[_0xa5ce('0x31')]);_0x19c8e0['filters']=_[_0xa5ce('0x33')](_0x19c8e0[_0xa5ce('0x2e')],_0x19c8e0['query']);_0x23e679['attributes']=_[_0xa5ce('0x33')](_0x19c8e0['model'],qs['fields'](_0x54a5e8[_0xa5ce('0x31')]['fields']));_0x23e679[_0xa5ce('0x35')]=_0x23e679['attributes'][_0xa5ce('0x36')]?_0x23e679[_0xa5ce('0x35')]:_0x19c8e0['model'];if(_0x54a5e8[_0xa5ce('0x31')][_0xa5ce('0x3f')]){_0x23e679['include']=[{'all':!![]}];}_0x23e679=_[_0xa5ce('0x3c')]({},_0x23e679,_0x54a5e8[_0xa5ce('0x3e')]);return db[_0xa5ce('0x2b')]['find'](_0x23e679)[_0xa5ce('0x26')](handleEntityNotFound(_0x375c9a,null))[_0xa5ce('0x26')](respondWithResult(_0x375c9a,null))[_0xa5ce('0x43')](handleError(_0x375c9a,null));};exports[_0xa5ce('0x46')]=function(_0x366254,_0x51fa02){return db['ZohoField']['create'](_0x366254['body'],{})[_0xa5ce('0x26')](respondWithResult(_0x51fa02,0xc9))[_0xa5ce('0x43')](handleError(_0x51fa02,null));};exports[_0xa5ce('0x47')]=function(_0x3ff098,_0x509272){if(_0x3ff098['body']['id']){delete _0x3ff098[_0xa5ce('0x48')]['id'];}return db[_0xa5ce('0x2b')][_0xa5ce('0x49')]({'where':{'id':_0x3ff098['params']['id']}})[_0xa5ce('0x26')](handleEntityNotFound(_0x509272,null))['then'](saveUpdates(_0x3ff098[_0xa5ce('0x48')],null))['then'](respondWithResult(_0x509272,null))[_0xa5ce('0x43')](handleError(_0x509272,null));};exports['destroy']=function(_0x106d41,_0x33caef){return db[_0xa5ce('0x2b')]['find']({'where':{'id':_0x106d41['params']['id']}})['then'](handleEntityNotFound(_0x33caef,null))[_0xa5ce('0x26')](removeEntity(_0x33caef,null))[_0xa5ce('0x43')](handleError(_0x33caef,null));};