4c4aaa9ee45d09479b267f03acfc1774677e37c1
[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 _0xf162=['to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','offset','undefined','count','Content-Range','json','apply','reject','save','then','end','stack','name','send','index','rawAttributes','fieldName','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','CmHopperBlack','includeAll','include','findAll','rows','catch','show','options','find','update','body','params','destroy','describe','zip-dir','fast-json-patch','moment','mustache','path','sox'];(function(_0x43ae33,_0x87a6f7){var _0x493db8=function(_0x1ebbcf){while(--_0x1ebbcf){_0x43ae33['push'](_0x43ae33['shift']());}};_0x493db8(++_0x87a6f7);}(_0xf162,0x8e));var _0x2f16=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0xf162[_0x57b54c];return _0x59cc19;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x2f16('0x0'));var jsonpatch=require(_0x2f16('0x1'));var rp=require('request-promise');var moment=require(_0x2f16('0x2'));var BPromise=require('bluebird');var Mustache=require(_0x2f16('0x3'));var util=require('util');var path=require(_0x2f16('0x4'));var sox=require(_0x2f16('0x5'));var csv=require(_0x2f16('0x6'));var ejs=require(_0x2f16('0x7'));var fs=require('fs');var fs_extra=require(_0x2f16('0x8'));var _=require(_0x2f16('0x9'));var squel=require(_0x2f16('0xa'));var crypto=require(_0x2f16('0xb'));var jsforce=require(_0x2f16('0xc'));var deskjs=require(_0x2f16('0xd'));var toCsv=require(_0x2f16('0x6'));var querystring=require(_0x2f16('0xe'));var Papa=require(_0x2f16('0xf'));var Redis=require(_0x2f16('0x10'));var authService=require(_0x2f16('0x11'));var qs=require(_0x2f16('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x2f16('0x13'));var logger=require('../../config/logger')(_0x2f16('0x14'));var utils=require(_0x2f16('0x15'));var config=require(_0x2f16('0x16'));var licenseUtil=require(_0x2f16('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x989102,_0x235fbb){_0x235fbb=_0x235fbb||0xcc;return function(_0x405783){if(_0x405783){return _0x989102[_0x2f16('0x18')](_0x235fbb);}return _0x989102[_0x2f16('0x19')](_0x235fbb)['end']();};}function respondWithResult(_0x50fcbb,_0x1f0120){_0x1f0120=_0x1f0120||0xc8;return function(_0x33aef9){if(_0x33aef9){return _0x50fcbb[_0x2f16('0x19')](_0x1f0120)['json'](_0x33aef9);}};}function respondWithFilteredResult(_0x5d595e,_0x46dcf4){return function(_0x2db97f){if(_0x2db97f){var _0x224b21=typeof _0x46dcf4[_0x2f16('0x1a')]===_0x2f16('0x1b')&&typeof _0x46dcf4['limit']===_0x2f16('0x1b');var _0x547161=_0x2db97f[_0x2f16('0x1c')];var _0x529e35=_0x224b21?0x0:_0x46dcf4[_0x2f16('0x1a')];var _0x1135bc=_0x224b21?_0x2db97f[_0x2f16('0x1c')]:_0x46dcf4[_0x2f16('0x1a')]+_0x46dcf4['limit'];var _0x28c05a;if(_0x1135bc>=_0x547161){_0x1135bc=_0x547161;_0x28c05a=0xc8;}else{_0x28c05a=0xce;}_0x5d595e[_0x2f16('0x19')](_0x28c05a);return _0x5d595e['set'](_0x2f16('0x1d'),_0x529e35+'-'+_0x1135bc+'/'+_0x547161)[_0x2f16('0x1e')](_0x2db97f);}return null;};}function patchUpdates(_0x3ed6a7){return function(_0xb81983){try{jsonpatch[_0x2f16('0x1f')](_0xb81983,_0x3ed6a7,!![]);}catch(_0x4af3bb){return BPromise[_0x2f16('0x20')](_0x4af3bb);}return _0xb81983[_0x2f16('0x21')]();};}function saveUpdates(_0x4ec5d7,_0x32d2f6){return function(_0xd6b11a){if(_0xd6b11a){return _0xd6b11a['update'](_0x4ec5d7)[_0x2f16('0x22')](function(_0x2750a2){return _0x2750a2;});}return null;};}function removeEntity(_0x452424,_0x40f87a){return function(_0x48eb34){if(_0x48eb34){return _0x48eb34['destroy']()['then'](function(){_0x452424[_0x2f16('0x19')](0xcc)[_0x2f16('0x23')]();});}};}function handleEntityNotFound(_0x3d2aee,_0x43ae67){return function(_0x120c91){if(!_0x120c91){_0x3d2aee['sendStatus'](0x194);}return _0x120c91;};}function handleError(_0x257be2,_0x30904c){_0x30904c=_0x30904c||0x1f4;return function(_0x4d1cb8){logger['error'](_0x4d1cb8[_0x2f16('0x24')]);if(_0x4d1cb8['name']){delete _0x4d1cb8[_0x2f16('0x25')];}_0x257be2[_0x2f16('0x19')](_0x30904c)[_0x2f16('0x26')](_0x4d1cb8);};}exports[_0x2f16('0x27')]=function(_0x40e3b7,_0x6ad65c){var _0x47bae8={},_0x1b84d7={},_0x2cae28={'count':0x0,'rows':[]};var _0x158d40=_['map'](db['CmHopperBlack'][_0x2f16('0x28')],function(_0x23f393){return{'name':_0x23f393[_0x2f16('0x29')],'type':_0x23f393['type']['key']};});_0x1b84d7[_0x2f16('0x2a')]=_[_0x2f16('0x2b')](_0x158d40,_0x2f16('0x25'));_0x1b84d7[_0x2f16('0x2c')]=_[_0x2f16('0x2d')](_0x40e3b7['query']);_0x1b84d7[_0x2f16('0x2e')]=_[_0x2f16('0x2f')](_0x1b84d7['model'],_0x1b84d7[_0x2f16('0x2c')]);_0x47bae8[_0x2f16('0x30')]=_[_0x2f16('0x2f')](_0x1b84d7[_0x2f16('0x2a')],qs['fields'](_0x40e3b7[_0x2f16('0x2c')][_0x2f16('0x31')]));_0x47bae8[_0x2f16('0x30')]=_0x47bae8[_0x2f16('0x30')][_0x2f16('0x32')]?_0x47bae8[_0x2f16('0x30')]:_0x1b84d7[_0x2f16('0x2a')];if(!_0x40e3b7[_0x2f16('0x2c')][_0x2f16('0x33')](_0x2f16('0x34'))){_0x47bae8[_0x2f16('0x35')]=qs[_0x2f16('0x35')](_0x40e3b7[_0x2f16('0x2c')]['limit']);_0x47bae8[_0x2f16('0x1a')]=qs[_0x2f16('0x1a')](_0x40e3b7[_0x2f16('0x2c')][_0x2f16('0x1a')]);}_0x47bae8[_0x2f16('0x36')]=qs[_0x2f16('0x37')](_0x40e3b7['query']['sort']);_0x47bae8[_0x2f16('0x38')]=qs[_0x2f16('0x2e')](_[_0x2f16('0x39')](_0x40e3b7[_0x2f16('0x2c')],_0x1b84d7[_0x2f16('0x2e')]),_0x158d40);if(_0x40e3b7[_0x2f16('0x2c')][_0x2f16('0x3a')]){_0x47bae8[_0x2f16('0x38')]=_['merge'](_0x47bae8['where'],{'$or':_['map'](_0x158d40,function(_0x23301f){if(_0x23301f['type']!=='VIRTUAL'){var _0x21ba7b={};_0x21ba7b[_0x23301f[_0x2f16('0x25')]]={'$like':'%'+_0x40e3b7[_0x2f16('0x2c')]['filter']+'%'};return _0x21ba7b;}})});}_0x47bae8=_[_0x2f16('0x3b')]({},_0x47bae8,_0x40e3b7['options']);var _0x3cacc2={'where':_0x47bae8[_0x2f16('0x38')]};return db[_0x2f16('0x3c')]['count'](_0x3cacc2)[_0x2f16('0x22')](function(_0x444c81){_0x2cae28[_0x2f16('0x1c')]=_0x444c81;if(_0x40e3b7['query'][_0x2f16('0x3d')]){_0x47bae8[_0x2f16('0x3e')]=[{'all':!![]}];}return db[_0x2f16('0x3c')][_0x2f16('0x3f')](_0x47bae8);})['then'](function(_0x3a1c69){_0x2cae28[_0x2f16('0x40')]=_0x3a1c69;return _0x2cae28;})['then'](respondWithFilteredResult(_0x6ad65c,_0x47bae8))[_0x2f16('0x41')](handleError(_0x6ad65c,null));};exports[_0x2f16('0x42')]=function(_0x43a4e4,_0x245003){var _0x3e6e42={'raw':!![],'where':{'id':_0x43a4e4['params']['id']}},_0x1d406b={};_0x1d406b[_0x2f16('0x2a')]=_[_0x2f16('0x2d')](db['CmHopperBlack']['rawAttributes']);_0x1d406b[_0x2f16('0x2c')]=_['keys'](_0x43a4e4['query']);_0x1d406b[_0x2f16('0x2e')]=_['intersection'](_0x1d406b['model'],_0x1d406b['query']);_0x3e6e42[_0x2f16('0x30')]=_[_0x2f16('0x2f')](_0x1d406b[_0x2f16('0x2a')],qs[_0x2f16('0x31')](_0x43a4e4[_0x2f16('0x2c')][_0x2f16('0x31')]));_0x3e6e42[_0x2f16('0x30')]=_0x3e6e42[_0x2f16('0x30')][_0x2f16('0x32')]?_0x3e6e42['attributes']:_0x1d406b[_0x2f16('0x2a')];if(_0x43a4e4[_0x2f16('0x2c')][_0x2f16('0x3d')]){_0x3e6e42[_0x2f16('0x3e')]=[{'all':!![]}];}_0x3e6e42=_[_0x2f16('0x3b')]({},_0x3e6e42,_0x43a4e4[_0x2f16('0x43')]);return db[_0x2f16('0x3c')][_0x2f16('0x44')](_0x3e6e42)[_0x2f16('0x22')](handleEntityNotFound(_0x245003,null))[_0x2f16('0x22')](respondWithResult(_0x245003,null))[_0x2f16('0x41')](handleError(_0x245003,null));};exports[_0x2f16('0x45')]=function(_0x381ac7,_0x5a6cf7){if(_0x381ac7[_0x2f16('0x46')]['id']){delete _0x381ac7[_0x2f16('0x46')]['id'];}return db[_0x2f16('0x3c')][_0x2f16('0x44')]({'where':{'id':_0x381ac7[_0x2f16('0x47')]['id']}})[_0x2f16('0x22')](handleEntityNotFound(_0x5a6cf7,null))['then'](saveUpdates(_0x381ac7[_0x2f16('0x46')],null))[_0x2f16('0x22')](respondWithResult(_0x5a6cf7,null))['catch'](handleError(_0x5a6cf7,null));};exports[_0x2f16('0x48')]=function(_0x1c8d9e,_0x3611a3){return db[_0x2f16('0x3c')]['find']({'where':{'id':_0x1c8d9e['params']['id']}})[_0x2f16('0x22')](handleEntityNotFound(_0x3611a3,null))['then'](removeEntity(_0x3611a3,null))[_0x2f16('0x41')](handleError(_0x3611a3,null));};exports[_0x2f16('0x49')]=function(_0x39d007,_0x5916fa){return db[_0x2f16('0x3c')][_0x2f16('0x49')]()[_0x2f16('0x22')](respondWithResult(_0x5916fa,null))['catch'](handleError(_0x5916fa,null));};