Built motion from commit 10af8726.|2.6.34
[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 _0x2baf=['undefined','count','offset','Content-Range','apply','reject','save','update','then','destroy','end','error','name','send','index','map','fieldName','type','key','model','keys','intersection','query','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort','filters','filter','where','VIRTUAL','merge','options','ZohoField','includeAll','include','findAll','catch','show','rawAttributes','find','create','body','params','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','json'];(function(_0x3f15c7,_0x1dbf1c){var _0x413706=function(_0x3b31c0){while(--_0x3b31c0){_0x3f15c7['push'](_0x3f15c7['shift']());}};_0x413706(++_0x1dbf1c);}(_0x2baf,0xc8));var _0xf2ba=function(_0x2afbb0,_0x44f16d){_0x2afbb0=_0x2afbb0-0x0;var _0x411ff2=_0x2baf[_0x2afbb0];return _0x411ff2;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf2ba('0x0'));var zipdir=require(_0xf2ba('0x1'));var jsonpatch=require(_0xf2ba('0x2'));var rp=require(_0xf2ba('0x3'));var moment=require(_0xf2ba('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf2ba('0x5'));var util=require('util');var path=require('path');var sox=require(_0xf2ba('0x6'));var csv=require(_0xf2ba('0x7'));var ejs=require(_0xf2ba('0x8'));var fs=require('fs');var fs_extra=require(_0xf2ba('0x9'));var _=require(_0xf2ba('0xa'));var squel=require('squel');var crypto=require(_0xf2ba('0xb'));var jsforce=require(_0xf2ba('0xc'));var deskjs=require(_0xf2ba('0xd'));var toCsv=require(_0xf2ba('0x7'));var querystring=require(_0xf2ba('0xe'));var Papa=require(_0xf2ba('0xf'));var Redis=require(_0xf2ba('0x10'));var authService=require(_0xf2ba('0x11'));var qs=require(_0xf2ba('0x12'));var as=require(_0xf2ba('0x13'));var hardwareService=require(_0xf2ba('0x14'));var logger=require(_0xf2ba('0x15'))(_0xf2ba('0x16'));var utils=require(_0xf2ba('0x17'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xf2ba('0x18'))['db'];function respondWithStatusCode(_0x101e81,_0x5c6307){_0x5c6307=_0x5c6307||0xcc;return function(_0x34006e){if(_0x34006e){return _0x101e81[_0xf2ba('0x19')](_0x5c6307);}return _0x101e81[_0xf2ba('0x1a')](_0x5c6307)['end']();};}function respondWithResult(_0x3ee056,_0x214430){_0x214430=_0x214430||0xc8;return function(_0x12e446){if(_0x12e446){return _0x3ee056[_0xf2ba('0x1a')](_0x214430)[_0xf2ba('0x1b')](_0x12e446);}};}function respondWithFilteredResult(_0x3499c2,_0x379e42){return function(_0x197ae6){if(_0x197ae6){var _0x16b094=typeof _0x379e42['offset']==='undefined'&&typeof _0x379e42['limit']===_0xf2ba('0x1c');var _0x465e2f=_0x197ae6[_0xf2ba('0x1d')];var _0x2c0bc4=_0x16b094?0x0:_0x379e42[_0xf2ba('0x1e')];var _0x52f53f=_0x16b094?_0x197ae6[_0xf2ba('0x1d')]:_0x379e42[_0xf2ba('0x1e')]+_0x379e42['limit'];var _0x226276;if(_0x52f53f>=_0x465e2f){_0x52f53f=_0x465e2f;_0x226276=0xc8;}else{_0x226276=0xce;}_0x3499c2[_0xf2ba('0x1a')](_0x226276);return _0x3499c2['set'](_0xf2ba('0x1f'),_0x2c0bc4+'-'+_0x52f53f+'/'+_0x465e2f)[_0xf2ba('0x1b')](_0x197ae6);}return null;};}function patchUpdates(_0x5b2724){return function(_0x21ca7e){try{jsonpatch[_0xf2ba('0x20')](_0x21ca7e,_0x5b2724,!![]);}catch(_0x432e80){return BPromise[_0xf2ba('0x21')](_0x432e80);}return _0x21ca7e[_0xf2ba('0x22')]();};}function saveUpdates(_0x505211,_0x3d082){return function(_0x5b8ae6){if(_0x5b8ae6){return _0x5b8ae6[_0xf2ba('0x23')](_0x505211)[_0xf2ba('0x24')](function(_0x599072){return _0x599072;});}return null;};}function removeEntity(_0x5ada32,_0x3de21b){return function(_0x368ffa){if(_0x368ffa){return _0x368ffa[_0xf2ba('0x25')]()[_0xf2ba('0x24')](function(){_0x5ada32[_0xf2ba('0x1a')](0xcc)[_0xf2ba('0x26')]();});}};}function handleEntityNotFound(_0x52f6b1,_0xab07bb){return function(_0x14e2d1){if(!_0x14e2d1){_0x52f6b1[_0xf2ba('0x19')](0x194);}return _0x14e2d1;};}function handleError(_0x50bc4a,_0x486064){_0x486064=_0x486064||0x1f4;return function(_0x151c24){logger[_0xf2ba('0x27')](_0x151c24['stack']);if(_0x151c24[_0xf2ba('0x28')]){delete _0x151c24[_0xf2ba('0x28')];}_0x50bc4a[_0xf2ba('0x1a')](_0x486064)[_0xf2ba('0x29')](_0x151c24);};}exports[_0xf2ba('0x2a')]=function(_0x15d237,_0x24c161){var _0x33adb5={},_0x30164b={},_0x1cd5bd={'count':0x0,'rows':[]};var _0x2b3cc0=_[_0xf2ba('0x2b')](db['ZohoField']['rawAttributes'],function(_0x5bfa95){return{'name':_0x5bfa95[_0xf2ba('0x2c')],'type':_0x5bfa95[_0xf2ba('0x2d')][_0xf2ba('0x2e')]};});_0x30164b[_0xf2ba('0x2f')]=_[_0xf2ba('0x2b')](_0x2b3cc0,'name');_0x30164b['query']=_[_0xf2ba('0x30')](_0x15d237['query']);_0x30164b['filters']=_[_0xf2ba('0x31')](_0x30164b[_0xf2ba('0x2f')],_0x30164b[_0xf2ba('0x32')]);_0x33adb5['attributes']=_[_0xf2ba('0x31')](_0x30164b[_0xf2ba('0x2f')],qs[_0xf2ba('0x33')](_0x15d237[_0xf2ba('0x32')]['fields']));_0x33adb5[_0xf2ba('0x34')]=_0x33adb5['attributes'][_0xf2ba('0x35')]?_0x33adb5[_0xf2ba('0x34')]:_0x30164b[_0xf2ba('0x2f')];if(!_0x15d237[_0xf2ba('0x32')][_0xf2ba('0x36')](_0xf2ba('0x37'))){_0x33adb5[_0xf2ba('0x38')]=qs[_0xf2ba('0x38')](_0x15d237[_0xf2ba('0x32')][_0xf2ba('0x38')]);_0x33adb5[_0xf2ba('0x1e')]=qs[_0xf2ba('0x1e')](_0x15d237[_0xf2ba('0x32')][_0xf2ba('0x1e')]);}_0x33adb5[_0xf2ba('0x39')]=qs[_0xf2ba('0x3a')](_0x15d237[_0xf2ba('0x32')][_0xf2ba('0x3a')]);_0x33adb5['where']=qs[_0xf2ba('0x3b')](_['pick'](_0x15d237[_0xf2ba('0x32')],_0x30164b[_0xf2ba('0x3b')]),_0x2b3cc0);if(_0x15d237['query'][_0xf2ba('0x3c')]){_0x33adb5[_0xf2ba('0x3d')]=_['merge'](_0x33adb5['where'],{'$or':_[_0xf2ba('0x2b')](_0x2b3cc0,function(_0x308210){if(_0x308210['type']!==_0xf2ba('0x3e')){var _0x23d214={};_0x23d214[_0x308210[_0xf2ba('0x28')]]={'$like':'%'+_0x15d237[_0xf2ba('0x32')][_0xf2ba('0x3c')]+'%'};return _0x23d214;}})});}_0x33adb5=_[_0xf2ba('0x3f')]({},_0x33adb5,_0x15d237[_0xf2ba('0x40')]);var _0xe84c42={'where':_0x33adb5[_0xf2ba('0x3d')]};return db[_0xf2ba('0x41')][_0xf2ba('0x1d')](_0xe84c42)[_0xf2ba('0x24')](function(_0x548a81){_0x1cd5bd[_0xf2ba('0x1d')]=_0x548a81;if(_0x15d237[_0xf2ba('0x32')][_0xf2ba('0x42')]){_0x33adb5[_0xf2ba('0x43')]=[{'all':!![]}];}return db[_0xf2ba('0x41')][_0xf2ba('0x44')](_0x33adb5);})[_0xf2ba('0x24')](function(_0x3da6d4){_0x1cd5bd['rows']=_0x3da6d4;return _0x1cd5bd;})[_0xf2ba('0x24')](respondWithFilteredResult(_0x24c161,_0x33adb5))[_0xf2ba('0x45')](handleError(_0x24c161,null));};exports[_0xf2ba('0x46')]=function(_0x461348,_0x4889d3){var _0x1b9999={'raw':!![],'where':{'id':_0x461348['params']['id']}},_0x3252c5={};_0x3252c5[_0xf2ba('0x2f')]=_[_0xf2ba('0x30')](db[_0xf2ba('0x41')][_0xf2ba('0x47')]);_0x3252c5[_0xf2ba('0x32')]=_[_0xf2ba('0x30')](_0x461348['query']);_0x3252c5[_0xf2ba('0x3b')]=_[_0xf2ba('0x31')](_0x3252c5[_0xf2ba('0x2f')],_0x3252c5[_0xf2ba('0x32')]);_0x1b9999[_0xf2ba('0x34')]=_[_0xf2ba('0x31')](_0x3252c5[_0xf2ba('0x2f')],qs[_0xf2ba('0x33')](_0x461348[_0xf2ba('0x32')][_0xf2ba('0x33')]));_0x1b9999[_0xf2ba('0x34')]=_0x1b9999['attributes'][_0xf2ba('0x35')]?_0x1b9999[_0xf2ba('0x34')]:_0x3252c5[_0xf2ba('0x2f')];if(_0x461348['query'][_0xf2ba('0x42')]){_0x1b9999[_0xf2ba('0x43')]=[{'all':!![]}];}_0x1b9999=_['merge']({},_0x1b9999,_0x461348['options']);return db['ZohoField'][_0xf2ba('0x48')](_0x1b9999)[_0xf2ba('0x24')](handleEntityNotFound(_0x4889d3,null))[_0xf2ba('0x24')](respondWithResult(_0x4889d3,null))[_0xf2ba('0x45')](handleError(_0x4889d3,null));};exports['create']=function(_0x55a9d7,_0x2d5ea7){return db['ZohoField'][_0xf2ba('0x49')](_0x55a9d7['body'],{})['then'](respondWithResult(_0x2d5ea7,0xc9))['catch'](handleError(_0x2d5ea7,null));};exports[_0xf2ba('0x23')]=function(_0x493d54,_0x5a3180){if(_0x493d54['body']['id']){delete _0x493d54[_0xf2ba('0x4a')]['id'];}return db[_0xf2ba('0x41')][_0xf2ba('0x48')]({'where':{'id':_0x493d54[_0xf2ba('0x4b')]['id']}})[_0xf2ba('0x24')](handleEntityNotFound(_0x5a3180,null))[_0xf2ba('0x24')](saveUpdates(_0x493d54[_0xf2ba('0x4a')],null))[_0xf2ba('0x24')](respondWithResult(_0x5a3180,null))['catch'](handleError(_0x5a3180,null));};exports[_0xf2ba('0x25')]=function(_0x1f4e4e,_0x139ffd){return db[_0xf2ba('0x41')][_0xf2ba('0x48')]({'where':{'id':_0x1f4e4e[_0xf2ba('0x4b')]['id']}})['then'](handleEntityNotFound(_0x139ffd,null))[_0xf2ba('0x24')](removeEntity(_0x139ffd,null))[_0xf2ba('0x45')](handleError(_0x139ffd,null));};