Built motion from commit 9d0783e6.|2.6.13
[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 _0xf8fb=['rows','catch','show','find','create','body','params','destroy','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','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','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','undefined','limit','count','set','apply','reject','update','then','error','stack','name','send','index','map','ZohoField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','offset','sort','where','pick','filter','merge','options','includeAll','include','findAll'];(function(_0x285c6c,_0xdfbed9){var _0x5a195c=function(_0x51f414){while(--_0x51f414){_0x285c6c['push'](_0x285c6c['shift']());}};_0x5a195c(++_0xdfbed9);}(_0xf8fb,0x184));var _0xbf8f=function(_0x199572,_0x33e667){_0x199572=_0x199572-0x0;var _0x13cfa3=_0xf8fb[_0x199572];return _0x13cfa3;};'use strict';var emlformat=require(_0xbf8f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbf8f('0x1'));var jsonpatch=require(_0xbf8f('0x2'));var rp=require(_0xbf8f('0x3'));var moment=require(_0xbf8f('0x4'));var BPromise=require(_0xbf8f('0x5'));var Mustache=require('mustache');var util=require(_0xbf8f('0x6'));var path=require(_0xbf8f('0x7'));var sox=require(_0xbf8f('0x8'));var csv=require(_0xbf8f('0x9'));var ejs=require(_0xbf8f('0xa'));var fs=require('fs');var fs_extra=require(_0xbf8f('0xb'));var _=require(_0xbf8f('0xc'));var squel=require('squel');var crypto=require(_0xbf8f('0xd'));var jsforce=require(_0xbf8f('0xe'));var deskjs=require(_0xbf8f('0xf'));var toCsv=require(_0xbf8f('0x9'));var querystring=require(_0xbf8f('0x10'));var Papa=require(_0xbf8f('0x11'));var Redis=require(_0xbf8f('0x12'));var authService=require(_0xbf8f('0x13'));var qs=require(_0xbf8f('0x14'));var as=require(_0xbf8f('0x15'));var hardwareService=require(_0xbf8f('0x16'));var logger=require(_0xbf8f('0x17'))('api');var utils=require('../../config/utils');var config=require(_0xbf8f('0x18'));var licenseUtil=require(_0xbf8f('0x19'));var db=require(_0xbf8f('0x1a'))['db'];function respondWithStatusCode(_0x23d11,_0x26a100){_0x26a100=_0x26a100||0xcc;return function(_0x5dfa29){if(_0x5dfa29){return _0x23d11[_0xbf8f('0x1b')](_0x26a100);}return _0x23d11['status'](_0x26a100)[_0xbf8f('0x1c')]();};}function respondWithResult(_0x108fb7,_0x3b242c){_0x3b242c=_0x3b242c||0xc8;return function(_0x7ec369){if(_0x7ec369){return _0x108fb7[_0xbf8f('0x1d')](_0x3b242c)[_0xbf8f('0x1e')](_0x7ec369);}};}function respondWithFilteredResult(_0x212ee1,_0x18e9ef){return function(_0x3c36e1){if(_0x3c36e1){var _0x27d2fd=typeof _0x18e9ef['offset']===_0xbf8f('0x1f')&&typeof _0x18e9ef[_0xbf8f('0x20')]===_0xbf8f('0x1f');var _0x46f5ac=_0x3c36e1['count'];var _0x1fbe1e=_0x27d2fd?0x0:_0x18e9ef['offset'];var _0x3a2111=_0x27d2fd?_0x3c36e1[_0xbf8f('0x21')]:_0x18e9ef['offset']+_0x18e9ef[_0xbf8f('0x20')];var _0xa91e60;if(_0x3a2111>=_0x46f5ac){_0x3a2111=_0x46f5ac;_0xa91e60=0xc8;}else{_0xa91e60=0xce;}_0x212ee1[_0xbf8f('0x1d')](_0xa91e60);return _0x212ee1[_0xbf8f('0x22')]('Content-Range',_0x1fbe1e+'-'+_0x3a2111+'/'+_0x46f5ac)[_0xbf8f('0x1e')](_0x3c36e1);}return null;};}function patchUpdates(_0x1e89a8){return function(_0x2615d6){try{jsonpatch[_0xbf8f('0x23')](_0x2615d6,_0x1e89a8,!![]);}catch(_0x12ad97){return BPromise[_0xbf8f('0x24')](_0x12ad97);}return _0x2615d6['save']();};}function saveUpdates(_0x3fdc0a,_0x3135f4){return function(_0x8f79c0){if(_0x8f79c0){return _0x8f79c0[_0xbf8f('0x25')](_0x3fdc0a)[_0xbf8f('0x26')](function(_0x4ddbdd){return _0x4ddbdd;});}return null;};}function removeEntity(_0x3cfb0c,_0x432cee){return function(_0x3b1f35){if(_0x3b1f35){return _0x3b1f35['destroy']()[_0xbf8f('0x26')](function(){_0x3cfb0c['status'](0xcc)[_0xbf8f('0x1c')]();});}};}function handleEntityNotFound(_0x1f676f,_0x487ee8){return function(_0x35ce5d){if(!_0x35ce5d){_0x1f676f[_0xbf8f('0x1b')](0x194);}return _0x35ce5d;};}function handleError(_0x135f91,_0x448eb1){_0x448eb1=_0x448eb1||0x1f4;return function(_0x430847){logger[_0xbf8f('0x27')](_0x430847[_0xbf8f('0x28')]);if(_0x430847['name']){delete _0x430847[_0xbf8f('0x29')];}_0x135f91[_0xbf8f('0x1d')](_0x448eb1)[_0xbf8f('0x2a')](_0x430847);};}exports[_0xbf8f('0x2b')]=function(_0x5654b4,_0x29871c){var _0x464e6a={},_0x28202c={},_0x1b692c={'count':0x0,'rows':[]};var _0xb2a1b7=_[_0xbf8f('0x2c')](db[_0xbf8f('0x2d')][_0xbf8f('0x2e')],function(_0x35b299){return{'name':_0x35b299[_0xbf8f('0x2f')],'type':_0x35b299[_0xbf8f('0x30')][_0xbf8f('0x31')]};});_0x28202c[_0xbf8f('0x32')]=_['map'](_0xb2a1b7,_0xbf8f('0x29'));_0x28202c[_0xbf8f('0x33')]=_[_0xbf8f('0x34')](_0x5654b4[_0xbf8f('0x33')]);_0x28202c[_0xbf8f('0x35')]=_[_0xbf8f('0x36')](_0x28202c[_0xbf8f('0x32')],_0x28202c[_0xbf8f('0x33')]);_0x464e6a[_0xbf8f('0x37')]=_[_0xbf8f('0x36')](_0x28202c[_0xbf8f('0x32')],qs[_0xbf8f('0x38')](_0x5654b4[_0xbf8f('0x33')][_0xbf8f('0x38')]));_0x464e6a['attributes']=_0x464e6a[_0xbf8f('0x37')][_0xbf8f('0x39')]?_0x464e6a[_0xbf8f('0x37')]:_0x28202c[_0xbf8f('0x32')];if(!_0x5654b4[_0xbf8f('0x33')]['hasOwnProperty']('nolimit')){_0x464e6a[_0xbf8f('0x20')]=qs[_0xbf8f('0x20')](_0x5654b4['query'][_0xbf8f('0x20')]);_0x464e6a[_0xbf8f('0x3a')]=qs[_0xbf8f('0x3a')](_0x5654b4[_0xbf8f('0x33')]['offset']);}_0x464e6a['order']=qs['sort'](_0x5654b4['query'][_0xbf8f('0x3b')]);_0x464e6a[_0xbf8f('0x3c')]=qs[_0xbf8f('0x35')](_[_0xbf8f('0x3d')](_0x5654b4[_0xbf8f('0x33')],_0x28202c[_0xbf8f('0x35')]),_0xb2a1b7);if(_0x5654b4[_0xbf8f('0x33')][_0xbf8f('0x3e')]){_0x464e6a[_0xbf8f('0x3c')]=_['merge'](_0x464e6a[_0xbf8f('0x3c')],{'$or':_[_0xbf8f('0x2c')](_0xb2a1b7,function(_0x1390d2){if(_0x1390d2[_0xbf8f('0x30')]!=='VIRTUAL'){var _0x545fcb={};_0x545fcb[_0x1390d2[_0xbf8f('0x29')]]={'$like':'%'+_0x5654b4[_0xbf8f('0x33')][_0xbf8f('0x3e')]+'%'};return _0x545fcb;}})});}_0x464e6a=_[_0xbf8f('0x3f')]({},_0x464e6a,_0x5654b4[_0xbf8f('0x40')]);var _0x4806d5={'where':_0x464e6a['where']};return db['ZohoField']['count'](_0x4806d5)['then'](function(_0x10a753){_0x1b692c[_0xbf8f('0x21')]=_0x10a753;if(_0x5654b4[_0xbf8f('0x33')][_0xbf8f('0x41')]){_0x464e6a[_0xbf8f('0x42')]=[{'all':!![]}];}return db[_0xbf8f('0x2d')][_0xbf8f('0x43')](_0x464e6a);})[_0xbf8f('0x26')](function(_0x52a240){_0x1b692c[_0xbf8f('0x44')]=_0x52a240;return _0x1b692c;})[_0xbf8f('0x26')](respondWithFilteredResult(_0x29871c,_0x464e6a))[_0xbf8f('0x45')](handleError(_0x29871c,null));};exports[_0xbf8f('0x46')]=function(_0x5d6a99,_0x351616){var _0x259ce9={'raw':!![],'where':{'id':_0x5d6a99['params']['id']}},_0x3e112b={};_0x3e112b[_0xbf8f('0x32')]=_['keys'](db['ZohoField'][_0xbf8f('0x2e')]);_0x3e112b[_0xbf8f('0x33')]=_[_0xbf8f('0x34')](_0x5d6a99[_0xbf8f('0x33')]);_0x3e112b[_0xbf8f('0x35')]=_[_0xbf8f('0x36')](_0x3e112b[_0xbf8f('0x32')],_0x3e112b['query']);_0x259ce9[_0xbf8f('0x37')]=_[_0xbf8f('0x36')](_0x3e112b[_0xbf8f('0x32')],qs['fields'](_0x5d6a99[_0xbf8f('0x33')]['fields']));_0x259ce9['attributes']=_0x259ce9[_0xbf8f('0x37')][_0xbf8f('0x39')]?_0x259ce9['attributes']:_0x3e112b['model'];if(_0x5d6a99['query'][_0xbf8f('0x41')]){_0x259ce9[_0xbf8f('0x42')]=[{'all':!![]}];}_0x259ce9=_[_0xbf8f('0x3f')]({},_0x259ce9,_0x5d6a99['options']);return db[_0xbf8f('0x2d')][_0xbf8f('0x47')](_0x259ce9)['then'](handleEntityNotFound(_0x351616,null))['then'](respondWithResult(_0x351616,null))['catch'](handleError(_0x351616,null));};exports[_0xbf8f('0x48')]=function(_0x2ddf81,_0x205f9e){return db['ZohoField'][_0xbf8f('0x48')](_0x2ddf81[_0xbf8f('0x49')],{})[_0xbf8f('0x26')](respondWithResult(_0x205f9e,0xc9))[_0xbf8f('0x45')](handleError(_0x205f9e,null));};exports['update']=function(_0x13904c,_0x24ddee){if(_0x13904c[_0xbf8f('0x49')]['id']){delete _0x13904c['body']['id'];}return db[_0xbf8f('0x2d')][_0xbf8f('0x47')]({'where':{'id':_0x13904c[_0xbf8f('0x4a')]['id']}})['then'](handleEntityNotFound(_0x24ddee,null))[_0xbf8f('0x26')](saveUpdates(_0x13904c[_0xbf8f('0x49')],null))[_0xbf8f('0x26')](respondWithResult(_0x24ddee,null))[_0xbf8f('0x45')](handleError(_0x24ddee,null));};exports[_0xbf8f('0x4b')]=function(_0x42936e,_0x1c9f78){return db[_0xbf8f('0x2d')][_0xbf8f('0x47')]({'where':{'id':_0x42936e[_0xbf8f('0x4a')]['id']}})['then'](handleEntityNotFound(_0x1c9f78,null))[_0xbf8f('0x26')](removeEntity(_0x1c9f78,null))['catch'](handleError(_0x1c9f78,null));};