b7b187bf2cdb2ddb1902d253ee96c8bf2f14dfc4
[motion2.git] / server / api / cmHopperBlack / cmHopperBlack.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 _0x608f=['fs-extra','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','end','json','offset','undefined','limit','count','status','set','reject','update','then','destroy','error','stack','name','send','map','CmHopperBlack','rawAttributes','fieldName','type','key','model','filters','intersection','query','fields','attributes','nolimit','sort','where','pick','merge','VIRTUAL','filter','options','include','findAll','rows','catch','params','keys','length','includeAll','body','find','describe','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs'];(function(_0x1d558c,_0x1e497c){var _0x15767d=function(_0x26326d){while(--_0x26326d){_0x1d558c['push'](_0x1d558c['shift']());}};_0x15767d(++_0x1e497c);}(_0x608f,0x115));var _0xf608=function(_0x5c1add,_0x552603){_0x5c1add=_0x5c1add-0x0;var _0x3f35c5=_0x608f[_0x5c1add];return _0x3f35c5;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf608('0x0'));var zipdir=require(_0xf608('0x1'));var jsonpatch=require(_0xf608('0x2'));var rp=require('request-promise');var moment=require(_0xf608('0x3'));var BPromise=require(_0xf608('0x4'));var Mustache=require(_0xf608('0x5'));var util=require(_0xf608('0x6'));var path=require(_0xf608('0x7'));var sox=require(_0xf608('0x8'));var csv=require(_0xf608('0x9'));var ejs=require(_0xf608('0xa'));var fs=require('fs');var fs_extra=require(_0xf608('0xb'));var _=require('lodash');var squel=require(_0xf608('0xc'));var crypto=require(_0xf608('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xf608('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf608('0xf'));var Redis=require(_0xf608('0x10'));var authService=require(_0xf608('0x11'));var qs=require(_0xf608('0x12'));var as=require(_0xf608('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf608('0x14'))(_0xf608('0x15'));var utils=require(_0xf608('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xf608('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4acde1,_0x5c69b1){_0x5c69b1=_0x5c69b1||0xcc;return function(_0x6ef29){if(_0x6ef29){return _0x4acde1[_0xf608('0x18')](_0x5c69b1);}return _0x4acde1['status'](_0x5c69b1)[_0xf608('0x19')]();};}function respondWithResult(_0x721b02,_0x2356b8){_0x2356b8=_0x2356b8||0xc8;return function(_0x2a6dfc){if(_0x2a6dfc){return _0x721b02['status'](_0x2356b8)[_0xf608('0x1a')](_0x2a6dfc);}};}function respondWithFilteredResult(_0x5023fc,_0x15c751){return function(_0xbbc7fa){if(_0xbbc7fa){var _0x2872fc=typeof _0x15c751[_0xf608('0x1b')]===_0xf608('0x1c')&&typeof _0x15c751[_0xf608('0x1d')]==='undefined';var _0x29cde8=_0xbbc7fa[_0xf608('0x1e')];var _0x3ecf59=_0x2872fc?0x0:_0x15c751[_0xf608('0x1b')];var _0x430335=_0x2872fc?_0xbbc7fa[_0xf608('0x1e')]:_0x15c751[_0xf608('0x1b')]+_0x15c751['limit'];var _0x2b0284;if(_0x430335>=_0x29cde8){_0x430335=_0x29cde8;_0x2b0284=0xc8;}else{_0x2b0284=0xce;}_0x5023fc[_0xf608('0x1f')](_0x2b0284);return _0x5023fc[_0xf608('0x20')]('Content-Range',_0x3ecf59+'-'+_0x430335+'/'+_0x29cde8)[_0xf608('0x1a')](_0xbbc7fa);}return null;};}function patchUpdates(_0x3a33aa){return function(_0x4d33e2){try{jsonpatch['apply'](_0x4d33e2,_0x3a33aa,!![]);}catch(_0x5f10ff){return BPromise[_0xf608('0x21')](_0x5f10ff);}return _0x4d33e2['save']();};}function saveUpdates(_0x241d1c,_0xab660e){return function(_0x13b852){if(_0x13b852){return _0x13b852[_0xf608('0x22')](_0x241d1c)[_0xf608('0x23')](function(_0x9fcc1a){return _0x9fcc1a;});}return null;};}function removeEntity(_0xc5f005,_0x57503a){return function(_0x33733a){if(_0x33733a){return _0x33733a[_0xf608('0x24')]()[_0xf608('0x23')](function(){_0xc5f005[_0xf608('0x1f')](0xcc)[_0xf608('0x19')]();});}};}function handleEntityNotFound(_0xfe13ff,_0x13d403){return function(_0x1cfadf){if(!_0x1cfadf){_0xfe13ff[_0xf608('0x18')](0x194);}return _0x1cfadf;};}function handleError(_0xbf8b95,_0x4a56d2){_0x4a56d2=_0x4a56d2||0x1f4;return function(_0x5dc59a){logger[_0xf608('0x25')](_0x5dc59a[_0xf608('0x26')]);if(_0x5dc59a[_0xf608('0x27')]){delete _0x5dc59a[_0xf608('0x27')];}_0xbf8b95['status'](_0x4a56d2)[_0xf608('0x28')](_0x5dc59a);};}exports['index']=function(_0x4223be,_0x39a204){var _0x4c8bc7={},_0x6574fe={},_0x3cfc61={'count':0x0,'rows':[]};var _0x360904=_[_0xf608('0x29')](db[_0xf608('0x2a')][_0xf608('0x2b')],function(_0x246f5f){return{'name':_0x246f5f[_0xf608('0x2c')],'type':_0x246f5f[_0xf608('0x2d')][_0xf608('0x2e')]};});_0x6574fe[_0xf608('0x2f')]=_[_0xf608('0x29')](_0x360904,_0xf608('0x27'));_0x6574fe['query']=_['keys'](_0x4223be['query']);_0x6574fe[_0xf608('0x30')]=_[_0xf608('0x31')](_0x6574fe[_0xf608('0x2f')],_0x6574fe[_0xf608('0x32')]);_0x4c8bc7['attributes']=_[_0xf608('0x31')](_0x6574fe[_0xf608('0x2f')],qs[_0xf608('0x33')](_0x4223be['query']['fields']));_0x4c8bc7['attributes']=_0x4c8bc7['attributes']['length']?_0x4c8bc7[_0xf608('0x34')]:_0x6574fe[_0xf608('0x2f')];if(!_0x4223be[_0xf608('0x32')]['hasOwnProperty'](_0xf608('0x35'))){_0x4c8bc7[_0xf608('0x1d')]=qs[_0xf608('0x1d')](_0x4223be[_0xf608('0x32')][_0xf608('0x1d')]);_0x4c8bc7[_0xf608('0x1b')]=qs[_0xf608('0x1b')](_0x4223be[_0xf608('0x32')][_0xf608('0x1b')]);}_0x4c8bc7['order']=qs[_0xf608('0x36')](_0x4223be['query'][_0xf608('0x36')]);_0x4c8bc7[_0xf608('0x37')]=qs['filters'](_[_0xf608('0x38')](_0x4223be[_0xf608('0x32')],_0x6574fe[_0xf608('0x30')]),_0x360904);if(_0x4223be[_0xf608('0x32')]['filter']){_0x4c8bc7[_0xf608('0x37')]=_[_0xf608('0x39')](_0x4c8bc7['where'],{'$or':_[_0xf608('0x29')](_0x360904,function(_0xcf5bc){if(_0xcf5bc[_0xf608('0x2d')]!==_0xf608('0x3a')){var _0x51d686={};_0x51d686[_0xcf5bc[_0xf608('0x27')]]={'$like':'%'+_0x4223be[_0xf608('0x32')][_0xf608('0x3b')]+'%'};return _0x51d686;}})});}_0x4c8bc7=_[_0xf608('0x39')]({},_0x4c8bc7,_0x4223be[_0xf608('0x3c')]);var _0x172457={'where':_0x4c8bc7[_0xf608('0x37')]};return db[_0xf608('0x2a')][_0xf608('0x1e')](_0x172457)[_0xf608('0x23')](function(_0x2a6b8b){_0x3cfc61[_0xf608('0x1e')]=_0x2a6b8b;if(_0x4223be[_0xf608('0x32')]['includeAll']){_0x4c8bc7[_0xf608('0x3d')]=[{'all':!![]}];}return db['CmHopperBlack'][_0xf608('0x3e')](_0x4c8bc7);})[_0xf608('0x23')](function(_0x40b8f2){_0x3cfc61[_0xf608('0x3f')]=_0x40b8f2;return _0x3cfc61;})[_0xf608('0x23')](respondWithFilteredResult(_0x39a204,_0x4c8bc7))[_0xf608('0x40')](handleError(_0x39a204,null));};exports['show']=function(_0x6ba7dc,_0x5f290f){var _0x520fe7={'raw':!![],'where':{'id':_0x6ba7dc[_0xf608('0x41')]['id']}},_0x8e7048={};_0x8e7048[_0xf608('0x2f')]=_[_0xf608('0x42')](db[_0xf608('0x2a')][_0xf608('0x2b')]);_0x8e7048[_0xf608('0x32')]=_['keys'](_0x6ba7dc[_0xf608('0x32')]);_0x8e7048[_0xf608('0x30')]=_['intersection'](_0x8e7048[_0xf608('0x2f')],_0x8e7048[_0xf608('0x32')]);_0x520fe7[_0xf608('0x34')]=_[_0xf608('0x31')](_0x8e7048[_0xf608('0x2f')],qs['fields'](_0x6ba7dc[_0xf608('0x32')][_0xf608('0x33')]));_0x520fe7['attributes']=_0x520fe7[_0xf608('0x34')][_0xf608('0x43')]?_0x520fe7['attributes']:_0x8e7048[_0xf608('0x2f')];if(_0x6ba7dc['query'][_0xf608('0x44')]){_0x520fe7[_0xf608('0x3d')]=[{'all':!![]}];}_0x520fe7=_[_0xf608('0x39')]({},_0x520fe7,_0x6ba7dc[_0xf608('0x3c')]);return db[_0xf608('0x2a')]['find'](_0x520fe7)[_0xf608('0x23')](handleEntityNotFound(_0x5f290f,null))[_0xf608('0x23')](respondWithResult(_0x5f290f,null))[_0xf608('0x40')](handleError(_0x5f290f,null));};exports[_0xf608('0x22')]=function(_0xe8fcf5,_0x487986){if(_0xe8fcf5[_0xf608('0x45')]['id']){delete _0xe8fcf5['body']['id'];}return db['CmHopperBlack']['find']({'where':{'id':_0xe8fcf5['params']['id']}})[_0xf608('0x23')](handleEntityNotFound(_0x487986,null))['then'](saveUpdates(_0xe8fcf5[_0xf608('0x45')],null))[_0xf608('0x23')](respondWithResult(_0x487986,null))[_0xf608('0x40')](handleError(_0x487986,null));};exports['destroy']=function(_0x28a978,_0x51889e){return db[_0xf608('0x2a')][_0xf608('0x46')]({'where':{'id':_0x28a978[_0xf608('0x41')]['id']}})[_0xf608('0x23')](handleEntityNotFound(_0x51889e,null))[_0xf608('0x23')](removeEntity(_0x51889e,null))[_0xf608('0x40')](handleError(_0x51889e,null));};exports[_0xf608('0x47')]=function(_0x41555e,_0x5b7a2b){return db[_0xf608('0x2a')][_0xf608('0x47')]()[_0xf608('0x23')](respondWithResult(_0x5b7a2b,null))[_0xf608('0x40')](handleError(_0x5b7a2b,null));};