Built motion from commit (unavailable).|2.5.21
[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 _0xf977=['ZohoField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','pick','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','options','find','create','body','params','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','lodash','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','map'];(function(_0x370281,_0x50b615){var _0x33a7ae=function(_0x111586){while(--_0x111586){_0x370281['push'](_0x370281['shift']());}};_0x33a7ae(++_0x50b615);}(_0xf977,0x161));var _0x7f97=function(_0x4feb0f,_0x4ea6f5){_0x4feb0f=_0x4feb0f-0x0;var _0x5b50d6=_0xf977[_0x4feb0f];return _0x5b50d6;};'use strict';var pdf=require(_0x7f97('0x0'));var emlformat=require(_0x7f97('0x1'));var rimraf=require(_0x7f97('0x2'));var zipdir=require(_0x7f97('0x3'));var jsonpatch=require(_0x7f97('0x4'));var rp=require(_0x7f97('0x5'));var moment=require(_0x7f97('0x6'));var BPromise=require(_0x7f97('0x7'));var Mustache=require(_0x7f97('0x8'));var util=require(_0x7f97('0x9'));var path=require(_0x7f97('0xa'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x7f97('0xb'));var squel=require('squel');var crypto=require(_0x7f97('0xc'));var jsforce=require(_0x7f97('0xd'));var deskjs=require(_0x7f97('0xe'));var toCsv=require(_0x7f97('0xf'));var querystring=require(_0x7f97('0x10'));var Papa=require('papaparse');var Redis=require(_0x7f97('0x11'));var authService=require(_0x7f97('0x12'));var qs=require(_0x7f97('0x13'));var as=require(_0x7f97('0x14'));var hardwareService=require(_0x7f97('0x15'));var logger=require('../../config/logger')(_0x7f97('0x16'));var utils=require(_0x7f97('0x17'));var config=require(_0x7f97('0x18'));var licenseUtil=require(_0x7f97('0x19'));var db=require(_0x7f97('0x1a'))['db'];function respondWithStatusCode(_0x58305c,_0x14d25d){_0x14d25d=_0x14d25d||0xcc;return function(_0x20386f){if(_0x20386f){return _0x58305c[_0x7f97('0x1b')](_0x14d25d);}return _0x58305c[_0x7f97('0x1c')](_0x14d25d)[_0x7f97('0x1d')]();};}function respondWithResult(_0x286293,_0x72e7ba){_0x72e7ba=_0x72e7ba||0xc8;return function(_0x854b08){if(_0x854b08){return _0x286293['status'](_0x72e7ba)[_0x7f97('0x1e')](_0x854b08);}};}function respondWithFilteredResult(_0x851c19,_0x101206){return function(_0x1201ee){if(_0x1201ee){var _0x1ebd13=_0x1201ee[_0x7f97('0x1f')],_0x4b8385=_0x101206[_0x7f97('0x20')],_0x588138=_0x101206[_0x7f97('0x20')]+_0x101206['limit'],_0x314c1c;if(_0x588138>=_0x1ebd13){_0x588138=_0x1ebd13;_0x314c1c=0xc8;}else{_0x314c1c=0xce;}_0x851c19['status'](_0x314c1c);return _0x851c19[_0x7f97('0x21')](_0x7f97('0x22'),_0x4b8385+'-'+_0x588138+'/'+_0x1ebd13)[_0x7f97('0x1e')](_0x1201ee);}return null;};}function patchUpdates(_0x107b42){return function(_0x130973){try{jsonpatch[_0x7f97('0x23')](_0x130973,_0x107b42,!![]);}catch(_0x421a6c){return BPromise[_0x7f97('0x24')](_0x421a6c);}return _0x130973[_0x7f97('0x25')]();};}function saveUpdates(_0x37dcac,_0x53e2cc){return function(_0x29d835){if(_0x29d835){return _0x29d835[_0x7f97('0x26')](_0x37dcac)[_0x7f97('0x27')](function(_0x5cc7e6){return _0x5cc7e6;});}return null;};}function removeEntity(_0x1a5f6b,_0x1b645a){return function(_0x282a4c){if(_0x282a4c){return _0x282a4c[_0x7f97('0x28')]()[_0x7f97('0x27')](function(){_0x1a5f6b[_0x7f97('0x1c')](0xcc)[_0x7f97('0x1d')]();});}};}function handleEntityNotFound(_0x594048,_0x223be2){return function(_0x1da87d){if(!_0x1da87d){_0x594048[_0x7f97('0x1b')](0x194);}return _0x1da87d;};}function handleError(_0x470e84,_0x21ec7f){_0x21ec7f=_0x21ec7f||0x1f4;return function(_0x4eade7){logger[_0x7f97('0x29')](_0x4eade7[_0x7f97('0x2a')]);if(_0x4eade7[_0x7f97('0x2b')]){delete _0x4eade7[_0x7f97('0x2b')];}_0x470e84[_0x7f97('0x1c')](_0x21ec7f)[_0x7f97('0x2c')](_0x4eade7);};}exports[_0x7f97('0x2d')]=function(_0xcd942e,_0x21f427){var _0x440fb4={},_0x46f87a={},_0x21a648={'count':0x0,'rows':[]};var _0xea0771=_[_0x7f97('0x2e')](db[_0x7f97('0x2f')][_0x7f97('0x30')],function(_0x1f3d7a){return{'name':_0x1f3d7a[_0x7f97('0x31')],'type':_0x1f3d7a[_0x7f97('0x32')][_0x7f97('0x33')]};});_0x46f87a[_0x7f97('0x34')]=_[_0x7f97('0x2e')](_0xea0771,'name');_0x46f87a[_0x7f97('0x35')]=_[_0x7f97('0x36')](_0xcd942e[_0x7f97('0x35')]);_0x46f87a[_0x7f97('0x37')]=_[_0x7f97('0x38')](_0x46f87a[_0x7f97('0x34')],_0x46f87a['query']);_0x440fb4[_0x7f97('0x39')]=_[_0x7f97('0x38')](_0x46f87a[_0x7f97('0x34')],qs[_0x7f97('0x3a')](_0xcd942e[_0x7f97('0x35')][_0x7f97('0x3a')]));_0x440fb4[_0x7f97('0x39')]=_0x440fb4['attributes'][_0x7f97('0x3b')]?_0x440fb4['attributes']:_0x46f87a[_0x7f97('0x34')];if(!_0xcd942e[_0x7f97('0x35')][_0x7f97('0x3c')]('nolimit')){_0x440fb4[_0x7f97('0x3d')]=qs[_0x7f97('0x3d')](_0xcd942e['query'][_0x7f97('0x3d')]);_0x440fb4[_0x7f97('0x20')]=qs[_0x7f97('0x20')](_0xcd942e[_0x7f97('0x35')][_0x7f97('0x20')]);}_0x440fb4[_0x7f97('0x3e')]=qs[_0x7f97('0x3f')](_0xcd942e[_0x7f97('0x35')][_0x7f97('0x3f')]);_0x440fb4['where']=qs[_0x7f97('0x37')](_[_0x7f97('0x40')](_0xcd942e[_0x7f97('0x35')],_0x46f87a[_0x7f97('0x37')]),_0xea0771);if(_0xcd942e[_0x7f97('0x35')][_0x7f97('0x41')]){_0x440fb4[_0x7f97('0x42')]=_[_0x7f97('0x43')](_0x440fb4[_0x7f97('0x42')],{'$or':_[_0x7f97('0x2e')](_0xea0771,function(_0x3de2c6){if(_0x3de2c6[_0x7f97('0x32')]!==_0x7f97('0x44')){var _0x45a800={};_0x45a800[_0x3de2c6[_0x7f97('0x2b')]]={'$like':'%'+_0xcd942e[_0x7f97('0x35')]['filter']+'%'};return _0x45a800;}})});}_0x440fb4=_['merge']({},_0x440fb4,_0xcd942e['options']);var _0x25047d={'where':_0x440fb4[_0x7f97('0x42')]};return db[_0x7f97('0x2f')][_0x7f97('0x1f')](_0x25047d)[_0x7f97('0x27')](function(_0x25ed32){_0x21a648['count']=_0x25ed32;if(_0xcd942e[_0x7f97('0x35')][_0x7f97('0x45')]){_0x440fb4[_0x7f97('0x46')]=[{'all':!![]}];}return db[_0x7f97('0x2f')][_0x7f97('0x47')](_0x440fb4);})['then'](function(_0x158bc5){_0x21a648[_0x7f97('0x48')]=_0x158bc5;return _0x21a648;})[_0x7f97('0x27')](respondWithFilteredResult(_0x21f427,_0x440fb4))[_0x7f97('0x49')](handleError(_0x21f427,null));};exports[_0x7f97('0x4a')]=function(_0x479844,_0x4a870f){var _0x181d41={'raw':!![],'where':{'id':_0x479844['params']['id']}},_0x219b1a={};_0x219b1a['model']=_[_0x7f97('0x36')](db[_0x7f97('0x2f')][_0x7f97('0x30')]);_0x219b1a[_0x7f97('0x35')]=_[_0x7f97('0x36')](_0x479844[_0x7f97('0x35')]);_0x219b1a[_0x7f97('0x37')]=_[_0x7f97('0x38')](_0x219b1a[_0x7f97('0x34')],_0x219b1a[_0x7f97('0x35')]);_0x181d41[_0x7f97('0x39')]=_['intersection'](_0x219b1a['model'],qs[_0x7f97('0x3a')](_0x479844[_0x7f97('0x35')][_0x7f97('0x3a')]));_0x181d41[_0x7f97('0x39')]=_0x181d41[_0x7f97('0x39')]['length']?_0x181d41[_0x7f97('0x39')]:_0x219b1a[_0x7f97('0x34')];if(_0x479844[_0x7f97('0x35')][_0x7f97('0x45')]){_0x181d41[_0x7f97('0x46')]=[{'all':!![]}];}_0x181d41=_[_0x7f97('0x43')]({},_0x181d41,_0x479844[_0x7f97('0x4b')]);return db[_0x7f97('0x2f')][_0x7f97('0x4c')](_0x181d41)[_0x7f97('0x27')](handleEntityNotFound(_0x4a870f,null))[_0x7f97('0x27')](respondWithResult(_0x4a870f,null))['catch'](handleError(_0x4a870f,null));};exports[_0x7f97('0x4d')]=function(_0x5f1fb6,_0x56a2db){return db[_0x7f97('0x2f')][_0x7f97('0x4d')](_0x5f1fb6[_0x7f97('0x4e')],{})[_0x7f97('0x27')](respondWithResult(_0x56a2db,0xc9))[_0x7f97('0x49')](handleError(_0x56a2db,null));};exports['update']=function(_0x4d41ca,_0x3d365f){if(_0x4d41ca[_0x7f97('0x4e')]['id']){delete _0x4d41ca['body']['id'];}return db['ZohoField'][_0x7f97('0x4c')]({'where':{'id':_0x4d41ca[_0x7f97('0x4f')]['id']}})['then'](handleEntityNotFound(_0x3d365f,null))[_0x7f97('0x27')](saveUpdates(_0x4d41ca['body'],null))['then'](respondWithResult(_0x3d365f,null))[_0x7f97('0x49')](handleError(_0x3d365f,null));};exports['destroy']=function(_0x4f9fe5,_0x326f1e){return db[_0x7f97('0x2f')][_0x7f97('0x4c')]({'where':{'id':_0x4f9fe5['params']['id']}})['then'](handleEntityNotFound(_0x326f1e,null))[_0x7f97('0x27')](removeEntity(_0x326f1e,null))[_0x7f97('0x49')](handleError(_0x326f1e,null));};