Built motion from commit f94df7f0.|2.5.48
[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 _0x83f6=['save','update','then','destroy','end','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','filter','VIRTUAL','options','ZohoField','include','findAll','rows','catch','show','params','merge','find','create','body','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','json','undefined','limit','count','offset','Content-Range','reject'];(function(_0x3bf83f,_0x181cac){var _0x22c4a9=function(_0xb3ff0d){while(--_0xb3ff0d){_0x3bf83f['push'](_0x3bf83f['shift']());}};_0x22c4a9(++_0x181cac);}(_0x83f6,0x1dd));var _0x683f=function(_0x4dbaad,_0x730318){_0x4dbaad=_0x4dbaad-0x0;var _0x226c72=_0x83f6[_0x4dbaad];return _0x226c72;};'use strict';var emlformat=require(_0x683f('0x0'));var rimraf=require(_0x683f('0x1'));var zipdir=require(_0x683f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x683f('0x3'));var moment=require(_0x683f('0x4'));var BPromise=require(_0x683f('0x5'));var Mustache=require(_0x683f('0x6'));var util=require(_0x683f('0x7'));var path=require('path');var sox=require(_0x683f('0x8'));var csv=require(_0x683f('0x9'));var ejs=require(_0x683f('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x683f('0xb'));var squel=require('squel');var crypto=require(_0x683f('0xc'));var jsforce=require(_0x683f('0xd'));var deskjs=require(_0x683f('0xe'));var toCsv=require(_0x683f('0x9'));var querystring=require(_0x683f('0xf'));var Papa=require('papaparse');var Redis=require(_0x683f('0x10'));var authService=require(_0x683f('0x11'));var qs=require(_0x683f('0x12'));var as=require(_0x683f('0x13'));var hardwareService=require(_0x683f('0x14'));var logger=require(_0x683f('0x15'))(_0x683f('0x16'));var utils=require(_0x683f('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x683f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1d0e01,_0x34027a){_0x34027a=_0x34027a||0xcc;return function(_0x876c62){if(_0x876c62){return _0x1d0e01[_0x683f('0x19')](_0x34027a);}return _0x1d0e01[_0x683f('0x1a')](_0x34027a)['end']();};}function respondWithResult(_0x5973d4,_0x120079){_0x120079=_0x120079||0xc8;return function(_0x1fceeb){if(_0x1fceeb){return _0x5973d4[_0x683f('0x1a')](_0x120079)[_0x683f('0x1b')](_0x1fceeb);}};}function respondWithFilteredResult(_0x4c0df5,_0x5a30c6){return function(_0x2a245b){if(_0x2a245b){var _0x523166=typeof _0x5a30c6['offset']===_0x683f('0x1c')&&typeof _0x5a30c6[_0x683f('0x1d')]===_0x683f('0x1c');var _0x4429db=_0x2a245b[_0x683f('0x1e')];var _0x1df1d0=_0x523166?0x0:_0x5a30c6[_0x683f('0x1f')];var _0x1faa09=_0x523166?_0x2a245b['count']:_0x5a30c6['offset']+_0x5a30c6['limit'];var _0x2004f6;if(_0x1faa09>=_0x4429db){_0x1faa09=_0x4429db;_0x2004f6=0xc8;}else{_0x2004f6=0xce;}_0x4c0df5[_0x683f('0x1a')](_0x2004f6);return _0x4c0df5['set'](_0x683f('0x20'),_0x1df1d0+'-'+_0x1faa09+'/'+_0x4429db)['json'](_0x2a245b);}return null;};}function patchUpdates(_0x374eff){return function(_0x5335d8){try{jsonpatch['apply'](_0x5335d8,_0x374eff,!![]);}catch(_0x418721){return BPromise[_0x683f('0x21')](_0x418721);}return _0x5335d8[_0x683f('0x22')]();};}function saveUpdates(_0x404819,_0x511cbe){return function(_0x48492b){if(_0x48492b){return _0x48492b[_0x683f('0x23')](_0x404819)[_0x683f('0x24')](function(_0x410b90){return _0x410b90;});}return null;};}function removeEntity(_0x36d34b,_0x2a68ef){return function(_0x1f1bf9){if(_0x1f1bf9){return _0x1f1bf9[_0x683f('0x25')]()[_0x683f('0x24')](function(){_0x36d34b[_0x683f('0x1a')](0xcc)[_0x683f('0x26')]();});}};}function handleEntityNotFound(_0x24be1c,_0x4e73dc){return function(_0x3d7b0f){if(!_0x3d7b0f){_0x24be1c['sendStatus'](0x194);}return _0x3d7b0f;};}function handleError(_0x1e7a50,_0x5c6591){_0x5c6591=_0x5c6591||0x1f4;return function(_0x3ed5fe){logger['error'](_0x3ed5fe[_0x683f('0x27')]);if(_0x3ed5fe[_0x683f('0x28')]){delete _0x3ed5fe[_0x683f('0x28')];}_0x1e7a50[_0x683f('0x1a')](_0x5c6591)['send'](_0x3ed5fe);};}exports[_0x683f('0x29')]=function(_0x442cae,_0x406dcc){var _0x2b99bc={},_0x57df2d={},_0x358283={'count':0x0,'rows':[]};var _0x5a986f=_[_0x683f('0x2a')](db['ZohoField'][_0x683f('0x2b')],function(_0x582a70){return{'name':_0x582a70[_0x683f('0x2c')],'type':_0x582a70[_0x683f('0x2d')][_0x683f('0x2e')]};});_0x57df2d[_0x683f('0x2f')]=_[_0x683f('0x2a')](_0x5a986f,_0x683f('0x28'));_0x57df2d[_0x683f('0x30')]=_[_0x683f('0x31')](_0x442cae['query']);_0x57df2d[_0x683f('0x32')]=_['intersection'](_0x57df2d[_0x683f('0x2f')],_0x57df2d['query']);_0x2b99bc['attributes']=_[_0x683f('0x33')](_0x57df2d[_0x683f('0x2f')],qs[_0x683f('0x34')](_0x442cae[_0x683f('0x30')][_0x683f('0x34')]));_0x2b99bc[_0x683f('0x35')]=_0x2b99bc[_0x683f('0x35')][_0x683f('0x36')]?_0x2b99bc[_0x683f('0x35')]:_0x57df2d['model'];if(!_0x442cae[_0x683f('0x30')][_0x683f('0x37')]('nolimit')){_0x2b99bc['limit']=qs[_0x683f('0x1d')](_0x442cae['query'][_0x683f('0x1d')]);_0x2b99bc['offset']=qs[_0x683f('0x1f')](_0x442cae['query']['offset']);}_0x2b99bc[_0x683f('0x38')]=qs['sort'](_0x442cae[_0x683f('0x30')][_0x683f('0x39')]);_0x2b99bc[_0x683f('0x3a')]=qs[_0x683f('0x32')](_['pick'](_0x442cae[_0x683f('0x30')],_0x57df2d[_0x683f('0x32')]),_0x5a986f);if(_0x442cae[_0x683f('0x30')][_0x683f('0x3b')]){_0x2b99bc[_0x683f('0x3a')]=_['merge'](_0x2b99bc['where'],{'$or':_[_0x683f('0x2a')](_0x5a986f,function(_0x2a309a){if(_0x2a309a[_0x683f('0x2d')]!==_0x683f('0x3c')){var _0x3df801={};_0x3df801[_0x2a309a['name']]={'$like':'%'+_0x442cae[_0x683f('0x30')][_0x683f('0x3b')]+'%'};return _0x3df801;}})});}_0x2b99bc=_['merge']({},_0x2b99bc,_0x442cae[_0x683f('0x3d')]);var _0x2c6d84={'where':_0x2b99bc[_0x683f('0x3a')]};return db[_0x683f('0x3e')][_0x683f('0x1e')](_0x2c6d84)[_0x683f('0x24')](function(_0x13b6f2){_0x358283[_0x683f('0x1e')]=_0x13b6f2;if(_0x442cae[_0x683f('0x30')]['includeAll']){_0x2b99bc[_0x683f('0x3f')]=[{'all':!![]}];}return db['ZohoField'][_0x683f('0x40')](_0x2b99bc);})[_0x683f('0x24')](function(_0x1bb657){_0x358283[_0x683f('0x41')]=_0x1bb657;return _0x358283;})['then'](respondWithFilteredResult(_0x406dcc,_0x2b99bc))[_0x683f('0x42')](handleError(_0x406dcc,null));};exports[_0x683f('0x43')]=function(_0x563e8e,_0xbb832b){var _0x1e70a7={'raw':!![],'where':{'id':_0x563e8e[_0x683f('0x44')]['id']}},_0x2acc06={};_0x2acc06[_0x683f('0x2f')]=_[_0x683f('0x31')](db[_0x683f('0x3e')][_0x683f('0x2b')]);_0x2acc06['query']=_[_0x683f('0x31')](_0x563e8e['query']);_0x2acc06['filters']=_[_0x683f('0x33')](_0x2acc06[_0x683f('0x2f')],_0x2acc06[_0x683f('0x30')]);_0x1e70a7[_0x683f('0x35')]=_[_0x683f('0x33')](_0x2acc06[_0x683f('0x2f')],qs[_0x683f('0x34')](_0x563e8e['query']['fields']));_0x1e70a7[_0x683f('0x35')]=_0x1e70a7[_0x683f('0x35')][_0x683f('0x36')]?_0x1e70a7[_0x683f('0x35')]:_0x2acc06['model'];if(_0x563e8e[_0x683f('0x30')]['includeAll']){_0x1e70a7['include']=[{'all':!![]}];}_0x1e70a7=_[_0x683f('0x45')]({},_0x1e70a7,_0x563e8e[_0x683f('0x3d')]);return db['ZohoField'][_0x683f('0x46')](_0x1e70a7)[_0x683f('0x24')](handleEntityNotFound(_0xbb832b,null))[_0x683f('0x24')](respondWithResult(_0xbb832b,null))['catch'](handleError(_0xbb832b,null));};exports[_0x683f('0x47')]=function(_0x4ccf90,_0xf19420){return db[_0x683f('0x3e')]['create'](_0x4ccf90[_0x683f('0x48')],{})['then'](respondWithResult(_0xf19420,0xc9))[_0x683f('0x42')](handleError(_0xf19420,null));};exports['update']=function(_0x57b49e,_0x52cc64){if(_0x57b49e[_0x683f('0x48')]['id']){delete _0x57b49e[_0x683f('0x48')]['id'];}return db['ZohoField'][_0x683f('0x46')]({'where':{'id':_0x57b49e[_0x683f('0x44')]['id']}})[_0x683f('0x24')](handleEntityNotFound(_0x52cc64,null))['then'](saveUpdates(_0x57b49e[_0x683f('0x48')],null))[_0x683f('0x24')](respondWithResult(_0x52cc64,null))[_0x683f('0x42')](handleError(_0x52cc64,null));};exports[_0x683f('0x25')]=function(_0x389fd8,_0x26bb99){return db[_0x683f('0x3e')][_0x683f('0x46')]({'where':{'id':_0x389fd8[_0x683f('0x44')]['id']}})[_0x683f('0x24')](handleEntityNotFound(_0x26bb99,null))[_0x683f('0x24')](removeEntity(_0x26bb99,null))[_0x683f('0x42')](handleError(_0x26bb99,null));};