04597d2e4e39d0d7988fd15833705720a138a8e7
[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 _0xeeb9=['eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../mysqldb','status','end','offset','limit','undefined','count','set','json','apply','reject','save','then','destroy','sendStatus','stack','name','send','index','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','map','VIRTUAL','ZohoField','includeAll','include','rows','show','params','keys','options','create','body','catch','update'];(function(_0x1cc8fe,_0x105328){var _0x230054=function(_0x1a1b56){while(--_0x1a1b56){_0x1cc8fe['push'](_0x1cc8fe['shift']());}};_0x230054(++_0x105328);}(_0xeeb9,0xde));var _0x9eeb=function(_0x5d1442,_0x364059){_0x5d1442=_0x5d1442-0x0;var _0x43d1eb=_0xeeb9[_0x5d1442];return _0x43d1eb;};'use strict';var emlformat=require(_0x9eeb('0x0'));var rimraf=require(_0x9eeb('0x1'));var zipdir=require(_0x9eeb('0x2'));var jsonpatch=require(_0x9eeb('0x3'));var rp=require(_0x9eeb('0x4'));var moment=require('moment');var BPromise=require(_0x9eeb('0x5'));var Mustache=require('mustache');var util=require(_0x9eeb('0x6'));var path=require('path');var sox=require(_0x9eeb('0x7'));var csv=require(_0x9eeb('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x9eeb('0x9'));var _=require(_0x9eeb('0xa'));var squel=require(_0x9eeb('0xb'));var crypto=require(_0x9eeb('0xc'));var jsforce=require(_0x9eeb('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x9eeb('0xe'));var Papa=require('papaparse');var Redis=require(_0x9eeb('0xf'));var authService=require(_0x9eeb('0x10'));var qs=require(_0x9eeb('0x11'));var as=require(_0x9eeb('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x9eeb('0x13'))(_0x9eeb('0x14'));var utils=require('../../config/utils');var config=require(_0x9eeb('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x9eeb('0x16'))['db'];function respondWithStatusCode(_0x392628,_0xcf117b){_0xcf117b=_0xcf117b||0xcc;return function(_0x19fc75){if(_0x19fc75){return _0x392628['sendStatus'](_0xcf117b);}return _0x392628[_0x9eeb('0x17')](_0xcf117b)[_0x9eeb('0x18')]();};}function respondWithResult(_0x442129,_0x5bc00d){_0x5bc00d=_0x5bc00d||0xc8;return function(_0xaeb984){if(_0xaeb984){return _0x442129['status'](_0x5bc00d)['json'](_0xaeb984);}};}function respondWithFilteredResult(_0x520cf7,_0x53fae1){return function(_0x10dc9f){if(_0x10dc9f){var _0x13c889=typeof _0x53fae1[_0x9eeb('0x19')]==='undefined'&&typeof _0x53fae1[_0x9eeb('0x1a')]===_0x9eeb('0x1b');var _0x4dc679=_0x10dc9f[_0x9eeb('0x1c')];var _0x27a977=_0x13c889?0x0:_0x53fae1[_0x9eeb('0x19')];var _0x266c1c=_0x13c889?_0x10dc9f[_0x9eeb('0x1c')]:_0x53fae1[_0x9eeb('0x19')]+_0x53fae1[_0x9eeb('0x1a')];var _0x101310;if(_0x266c1c>=_0x4dc679){_0x266c1c=_0x4dc679;_0x101310=0xc8;}else{_0x101310=0xce;}_0x520cf7[_0x9eeb('0x17')](_0x101310);return _0x520cf7[_0x9eeb('0x1d')]('Content-Range',_0x27a977+'-'+_0x266c1c+'/'+_0x4dc679)[_0x9eeb('0x1e')](_0x10dc9f);}return null;};}function patchUpdates(_0x38f44f){return function(_0x5a96cc){try{jsonpatch[_0x9eeb('0x1f')](_0x5a96cc,_0x38f44f,!![]);}catch(_0x18ed79){return BPromise[_0x9eeb('0x20')](_0x18ed79);}return _0x5a96cc[_0x9eeb('0x21')]();};}function saveUpdates(_0x4333ba,_0xd2b705){return function(_0x9efc22){if(_0x9efc22){return _0x9efc22['update'](_0x4333ba)[_0x9eeb('0x22')](function(_0x3af05d){return _0x3af05d;});}return null;};}function removeEntity(_0x5d27b4,_0x5eee4d){return function(_0x453299){if(_0x453299){return _0x453299[_0x9eeb('0x23')]()['then'](function(){_0x5d27b4['status'](0xcc)[_0x9eeb('0x18')]();});}};}function handleEntityNotFound(_0x18b0e1,_0x32e752){return function(_0x5e6fdb){if(!_0x5e6fdb){_0x18b0e1[_0x9eeb('0x24')](0x194);}return _0x5e6fdb;};}function handleError(_0x4c4672,_0x51aaff){_0x51aaff=_0x51aaff||0x1f4;return function(_0x20da08){logger['error'](_0x20da08[_0x9eeb('0x25')]);if(_0x20da08[_0x9eeb('0x26')]){delete _0x20da08[_0x9eeb('0x26')];}_0x4c4672['status'](_0x51aaff)[_0x9eeb('0x27')](_0x20da08);};}exports[_0x9eeb('0x28')]=function(_0x43d6b8,_0x472f44){var _0x5e218a={},_0x570bec={},_0x9fce37={'count':0x0,'rows':[]};var _0x109bd3=_['map'](db['ZohoField'][_0x9eeb('0x29')],function(_0x46e140){return{'name':_0x46e140[_0x9eeb('0x2a')],'type':_0x46e140[_0x9eeb('0x2b')][_0x9eeb('0x2c')]};});_0x570bec[_0x9eeb('0x2d')]=_['map'](_0x109bd3,_0x9eeb('0x26'));_0x570bec['query']=_['keys'](_0x43d6b8[_0x9eeb('0x2e')]);_0x570bec['filters']=_[_0x9eeb('0x2f')](_0x570bec[_0x9eeb('0x2d')],_0x570bec[_0x9eeb('0x2e')]);_0x5e218a[_0x9eeb('0x30')]=_['intersection'](_0x570bec[_0x9eeb('0x2d')],qs[_0x9eeb('0x31')](_0x43d6b8['query'][_0x9eeb('0x31')]));_0x5e218a[_0x9eeb('0x30')]=_0x5e218a[_0x9eeb('0x30')][_0x9eeb('0x32')]?_0x5e218a[_0x9eeb('0x30')]:_0x570bec[_0x9eeb('0x2d')];if(!_0x43d6b8[_0x9eeb('0x2e')][_0x9eeb('0x33')](_0x9eeb('0x34'))){_0x5e218a[_0x9eeb('0x1a')]=qs[_0x9eeb('0x1a')](_0x43d6b8['query']['limit']);_0x5e218a[_0x9eeb('0x19')]=qs['offset'](_0x43d6b8[_0x9eeb('0x2e')][_0x9eeb('0x19')]);}_0x5e218a[_0x9eeb('0x35')]=qs[_0x9eeb('0x36')](_0x43d6b8[_0x9eeb('0x2e')][_0x9eeb('0x36')]);_0x5e218a['where']=qs[_0x9eeb('0x37')](_[_0x9eeb('0x38')](_0x43d6b8['query'],_0x570bec[_0x9eeb('0x37')]),_0x109bd3);if(_0x43d6b8[_0x9eeb('0x2e')][_0x9eeb('0x39')]){_0x5e218a[_0x9eeb('0x3a')]=_[_0x9eeb('0x3b')](_0x5e218a['where'],{'$or':_[_0x9eeb('0x3c')](_0x109bd3,function(_0x162371){if(_0x162371[_0x9eeb('0x2b')]!==_0x9eeb('0x3d')){var _0x54ab32={};_0x54ab32[_0x162371[_0x9eeb('0x26')]]={'$like':'%'+_0x43d6b8[_0x9eeb('0x2e')]['filter']+'%'};return _0x54ab32;}})});}_0x5e218a=_['merge']({},_0x5e218a,_0x43d6b8['options']);var _0x6bc921={'where':_0x5e218a[_0x9eeb('0x3a')]};return db[_0x9eeb('0x3e')][_0x9eeb('0x1c')](_0x6bc921)['then'](function(_0x46e710){_0x9fce37[_0x9eeb('0x1c')]=_0x46e710;if(_0x43d6b8[_0x9eeb('0x2e')][_0x9eeb('0x3f')]){_0x5e218a[_0x9eeb('0x40')]=[{'all':!![]}];}return db[_0x9eeb('0x3e')]['findAll'](_0x5e218a);})[_0x9eeb('0x22')](function(_0x24dae6){_0x9fce37[_0x9eeb('0x41')]=_0x24dae6;return _0x9fce37;})[_0x9eeb('0x22')](respondWithFilteredResult(_0x472f44,_0x5e218a))['catch'](handleError(_0x472f44,null));};exports[_0x9eeb('0x42')]=function(_0x4c1548,_0x47bee0){var _0x278769={'raw':!![],'where':{'id':_0x4c1548[_0x9eeb('0x43')]['id']}},_0x2e7363={};_0x2e7363[_0x9eeb('0x2d')]=_[_0x9eeb('0x44')](db[_0x9eeb('0x3e')]['rawAttributes']);_0x2e7363['query']=_['keys'](_0x4c1548[_0x9eeb('0x2e')]);_0x2e7363[_0x9eeb('0x37')]=_[_0x9eeb('0x2f')](_0x2e7363[_0x9eeb('0x2d')],_0x2e7363[_0x9eeb('0x2e')]);_0x278769[_0x9eeb('0x30')]=_['intersection'](_0x2e7363[_0x9eeb('0x2d')],qs[_0x9eeb('0x31')](_0x4c1548[_0x9eeb('0x2e')][_0x9eeb('0x31')]));_0x278769[_0x9eeb('0x30')]=_0x278769[_0x9eeb('0x30')][_0x9eeb('0x32')]?_0x278769['attributes']:_0x2e7363[_0x9eeb('0x2d')];if(_0x4c1548[_0x9eeb('0x2e')]['includeAll']){_0x278769[_0x9eeb('0x40')]=[{'all':!![]}];}_0x278769=_[_0x9eeb('0x3b')]({},_0x278769,_0x4c1548[_0x9eeb('0x45')]);return db[_0x9eeb('0x3e')]['find'](_0x278769)[_0x9eeb('0x22')](handleEntityNotFound(_0x47bee0,null))[_0x9eeb('0x22')](respondWithResult(_0x47bee0,null))['catch'](handleError(_0x47bee0,null));};exports[_0x9eeb('0x46')]=function(_0x18768f,_0x44f2d9){return db['ZohoField'][_0x9eeb('0x46')](_0x18768f[_0x9eeb('0x47')],{})[_0x9eeb('0x22')](respondWithResult(_0x44f2d9,0xc9))[_0x9eeb('0x48')](handleError(_0x44f2d9,null));};exports[_0x9eeb('0x49')]=function(_0x145943,_0x3c0196){if(_0x145943[_0x9eeb('0x47')]['id']){delete _0x145943[_0x9eeb('0x47')]['id'];}return db[_0x9eeb('0x3e')]['find']({'where':{'id':_0x145943[_0x9eeb('0x43')]['id']}})[_0x9eeb('0x22')](handleEntityNotFound(_0x3c0196,null))['then'](saveUpdates(_0x145943[_0x9eeb('0x47')],null))[_0x9eeb('0x22')](respondWithResult(_0x3c0196,null))['catch'](handleError(_0x3c0196,null));};exports[_0x9eeb('0x23')]=function(_0xf3efbb,_0x14f884){return db['ZohoField']['find']({'where':{'id':_0xf3efbb[_0x9eeb('0x43')]['id']}})[_0x9eeb('0x22')](handleEntityNotFound(_0x14f884,null))[_0x9eeb('0x22')](removeEntity(_0x14f884,null))['catch'](handleError(_0x14f884,null));};