da2aa640daec14cc267220badb09144d67308d4c
[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 _0x8f08=['then','destroy','name','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','CmHopperBlack','includeAll','findAll','rows','params','include','find','update','body','catch','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','apply','reject','save'];(function(_0x49b207,_0x408ade){var _0x2dc8fa=function(_0x150975){while(--_0x150975){_0x49b207['push'](_0x49b207['shift']());}};_0x2dc8fa(++_0x408ade);}(_0x8f08,0x187));var _0x88f0=function(_0x2fb87c,_0x2dee49){_0x2fb87c=_0x2fb87c-0x0;var _0x43038b=_0x8f08[_0x2fb87c];return _0x43038b;};'use strict';var emlformat=require(_0x88f0('0x0'));var rimraf=require(_0x88f0('0x1'));var zipdir=require(_0x88f0('0x2'));var jsonpatch=require(_0x88f0('0x3'));var rp=require(_0x88f0('0x4'));var moment=require(_0x88f0('0x5'));var BPromise=require(_0x88f0('0x6'));var Mustache=require(_0x88f0('0x7'));var util=require(_0x88f0('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0x88f0('0x9'));var ejs=require(_0x88f0('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x88f0('0xb'));var crypto=require(_0x88f0('0xc'));var jsforce=require(_0x88f0('0xd'));var deskjs=require(_0x88f0('0xe'));var toCsv=require(_0x88f0('0x9'));var querystring=require(_0x88f0('0xf'));var Papa=require('papaparse');var Redis=require(_0x88f0('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x88f0('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x88f0('0x12'));var logger=require(_0x88f0('0x13'))('api');var utils=require(_0x88f0('0x14'));var config=require(_0x88f0('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x88f0('0x16'))['db'];function respondWithStatusCode(_0x3dff7e,_0x5b365c){_0x5b365c=_0x5b365c||0xcc;return function(_0x33269f){if(_0x33269f){return _0x3dff7e[_0x88f0('0x17')](_0x5b365c);}return _0x3dff7e['status'](_0x5b365c)[_0x88f0('0x18')]();};}function respondWithResult(_0x1dd667,_0x4be17c){_0x4be17c=_0x4be17c||0xc8;return function(_0x5f3b43){if(_0x5f3b43){return _0x1dd667[_0x88f0('0x19')](_0x4be17c)[_0x88f0('0x1a')](_0x5f3b43);}};}function respondWithFilteredResult(_0x138136,_0x569221){return function(_0x44731c){if(_0x44731c){var _0x304c36=typeof _0x569221[_0x88f0('0x1b')]===_0x88f0('0x1c')&&typeof _0x569221[_0x88f0('0x1d')]===_0x88f0('0x1c');var _0x335447=_0x44731c[_0x88f0('0x1e')];var _0x1305fa=_0x304c36?0x0:_0x569221['offset'];var _0x595c65=_0x304c36?_0x44731c['count']:_0x569221[_0x88f0('0x1b')]+_0x569221['limit'];var _0x493b32;if(_0x595c65>=_0x335447){_0x595c65=_0x335447;_0x493b32=0xc8;}else{_0x493b32=0xce;}_0x138136['status'](_0x493b32);return _0x138136['set'](_0x88f0('0x1f'),_0x1305fa+'-'+_0x595c65+'/'+_0x335447)['json'](_0x44731c);}return null;};}function patchUpdates(_0x3fc6c8){return function(_0x12707a){try{jsonpatch[_0x88f0('0x20')](_0x12707a,_0x3fc6c8,!![]);}catch(_0x7cd639){return BPromise[_0x88f0('0x21')](_0x7cd639);}return _0x12707a[_0x88f0('0x22')]();};}function saveUpdates(_0x495c8a,_0x21579c){return function(_0xebffdd){if(_0xebffdd){return _0xebffdd['update'](_0x495c8a)[_0x88f0('0x23')](function(_0x442000){return _0x442000;});}return null;};}function removeEntity(_0x39ad73,_0x38fa82){return function(_0x150e2a){if(_0x150e2a){return _0x150e2a[_0x88f0('0x24')]()[_0x88f0('0x23')](function(){_0x39ad73['status'](0xcc)[_0x88f0('0x18')]();});}};}function handleEntityNotFound(_0x2cda71,_0x3ed9d7){return function(_0x546b02){if(!_0x546b02){_0x2cda71[_0x88f0('0x17')](0x194);}return _0x546b02;};}function handleError(_0x208999,_0x2080a5){_0x2080a5=_0x2080a5||0x1f4;return function(_0xb7f10){logger['error'](_0xb7f10['stack']);if(_0xb7f10[_0x88f0('0x25')]){delete _0xb7f10['name'];}_0x208999[_0x88f0('0x19')](_0x2080a5)['send'](_0xb7f10);};}exports['index']=function(_0x1d4280,_0x3ccdc9){var _0xadfca={},_0x1005a1={},_0x1f0288={'count':0x0,'rows':[]};var _0x687958=_['map'](db['CmHopperBlack'][_0x88f0('0x26')],function(_0x474b54){return{'name':_0x474b54[_0x88f0('0x27')],'type':_0x474b54[_0x88f0('0x28')][_0x88f0('0x29')]};});_0x1005a1[_0x88f0('0x2a')]=_[_0x88f0('0x2b')](_0x687958,_0x88f0('0x25'));_0x1005a1[_0x88f0('0x2c')]=_[_0x88f0('0x2d')](_0x1d4280[_0x88f0('0x2c')]);_0x1005a1[_0x88f0('0x2e')]=_[_0x88f0('0x2f')](_0x1005a1[_0x88f0('0x2a')],_0x1005a1[_0x88f0('0x2c')]);_0xadfca[_0x88f0('0x30')]=_[_0x88f0('0x2f')](_0x1005a1['model'],qs[_0x88f0('0x31')](_0x1d4280[_0x88f0('0x2c')]['fields']));_0xadfca[_0x88f0('0x30')]=_0xadfca[_0x88f0('0x30')][_0x88f0('0x32')]?_0xadfca['attributes']:_0x1005a1['model'];if(!_0x1d4280['query'][_0x88f0('0x33')](_0x88f0('0x34'))){_0xadfca['limit']=qs['limit'](_0x1d4280[_0x88f0('0x2c')][_0x88f0('0x1d')]);_0xadfca[_0x88f0('0x1b')]=qs['offset'](_0x1d4280[_0x88f0('0x2c')][_0x88f0('0x1b')]);}_0xadfca['order']=qs[_0x88f0('0x35')](_0x1d4280['query'][_0x88f0('0x35')]);_0xadfca[_0x88f0('0x36')]=qs[_0x88f0('0x2e')](_[_0x88f0('0x37')](_0x1d4280[_0x88f0('0x2c')],_0x1005a1[_0x88f0('0x2e')]),_0x687958);if(_0x1d4280[_0x88f0('0x2c')][_0x88f0('0x38')]){_0xadfca[_0x88f0('0x36')]=_[_0x88f0('0x39')](_0xadfca['where'],{'$or':_['map'](_0x687958,function(_0x57ac07){if(_0x57ac07[_0x88f0('0x28')]!==_0x88f0('0x3a')){var _0x353de7={};_0x353de7[_0x57ac07[_0x88f0('0x25')]]={'$like':'%'+_0x1d4280['query']['filter']+'%'};return _0x353de7;}})});}_0xadfca=_[_0x88f0('0x39')]({},_0xadfca,_0x1d4280[_0x88f0('0x3b')]);var _0x81868f={'where':_0xadfca[_0x88f0('0x36')]};return db[_0x88f0('0x3c')][_0x88f0('0x1e')](_0x81868f)[_0x88f0('0x23')](function(_0x3fc4af){_0x1f0288[_0x88f0('0x1e')]=_0x3fc4af;if(_0x1d4280['query'][_0x88f0('0x3d')]){_0xadfca['include']=[{'all':!![]}];}return db[_0x88f0('0x3c')][_0x88f0('0x3e')](_0xadfca);})['then'](function(_0x275399){_0x1f0288[_0x88f0('0x3f')]=_0x275399;return _0x1f0288;})[_0x88f0('0x23')](respondWithFilteredResult(_0x3ccdc9,_0xadfca))['catch'](handleError(_0x3ccdc9,null));};exports['show']=function(_0x2b147d,_0x5573cf){var _0x24ec13={'raw':!![],'where':{'id':_0x2b147d[_0x88f0('0x40')]['id']}},_0x1ed0b5={};_0x1ed0b5['model']=_[_0x88f0('0x2d')](db[_0x88f0('0x3c')]['rawAttributes']);_0x1ed0b5[_0x88f0('0x2c')]=_[_0x88f0('0x2d')](_0x2b147d['query']);_0x1ed0b5['filters']=_[_0x88f0('0x2f')](_0x1ed0b5[_0x88f0('0x2a')],_0x1ed0b5[_0x88f0('0x2c')]);_0x24ec13[_0x88f0('0x30')]=_[_0x88f0('0x2f')](_0x1ed0b5[_0x88f0('0x2a')],qs[_0x88f0('0x31')](_0x2b147d['query'][_0x88f0('0x31')]));_0x24ec13[_0x88f0('0x30')]=_0x24ec13[_0x88f0('0x30')][_0x88f0('0x32')]?_0x24ec13[_0x88f0('0x30')]:_0x1ed0b5[_0x88f0('0x2a')];if(_0x2b147d['query'][_0x88f0('0x3d')]){_0x24ec13[_0x88f0('0x41')]=[{'all':!![]}];}_0x24ec13=_['merge']({},_0x24ec13,_0x2b147d['options']);return db[_0x88f0('0x3c')][_0x88f0('0x42')](_0x24ec13)[_0x88f0('0x23')](handleEntityNotFound(_0x5573cf,null))[_0x88f0('0x23')](respondWithResult(_0x5573cf,null))['catch'](handleError(_0x5573cf,null));};exports[_0x88f0('0x43')]=function(_0x2a94a2,_0x308c82){if(_0x2a94a2[_0x88f0('0x44')]['id']){delete _0x2a94a2[_0x88f0('0x44')]['id'];}return db[_0x88f0('0x3c')][_0x88f0('0x42')]({'where':{'id':_0x2a94a2[_0x88f0('0x40')]['id']}})[_0x88f0('0x23')](handleEntityNotFound(_0x308c82,null))['then'](saveUpdates(_0x2a94a2[_0x88f0('0x44')],null))['then'](respondWithResult(_0x308c82,null))[_0x88f0('0x45')](handleError(_0x308c82,null));};exports['destroy']=function(_0x48f66a,_0x51294e){return db['CmHopperBlack'][_0x88f0('0x42')]({'where':{'id':_0x48f66a[_0x88f0('0x40')]['id']}})[_0x88f0('0x23')](handleEntityNotFound(_0x51294e,null))[_0x88f0('0x23')](removeEntity(_0x51294e,null))[_0x88f0('0x45')](handleError(_0x51294e,null));};exports['describe']=function(_0x268763,_0x69135c){return db['CmHopperBlack'][_0x88f0('0x46')]()[_0x88f0('0x23')](respondWithResult(_0x69135c,null))['catch'](handleError(_0x69135c,null));};