41c910ccd38907e58522407ec0060dbdabf067d0
[motion2.git] / server / api / cmHopperHistory / cmHopperHistory.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 _0x9fc6=['find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','reject','save','update','destroy','then','stack','name','send','index','map','CmHopperHistory','fieldName','type','key','model','query','keys','filters','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','intersection','length','create','body','uniqueid'];(function(_0x585d09,_0x1274bc){var _0x7d9a14=function(_0x343d4e){while(--_0x343d4e){_0x585d09['push'](_0x585d09['shift']());}};_0x7d9a14(++_0x1274bc);}(_0x9fc6,0x1d5));var _0x69fc=function(_0x468b0f,_0x408566){_0x468b0f=_0x468b0f-0x0;var _0x3e74d9=_0x9fc6[_0x468b0f];return _0x3e74d9;};'use strict';var emlformat=require(_0x69fc('0x0'));var rimraf=require(_0x69fc('0x1'));var zipdir=require(_0x69fc('0x2'));var jsonpatch=require(_0x69fc('0x3'));var rp=require(_0x69fc('0x4'));var moment=require(_0x69fc('0x5'));var BPromise=require(_0x69fc('0x6'));var Mustache=require(_0x69fc('0x7'));var util=require(_0x69fc('0x8'));var path=require(_0x69fc('0x9'));var sox=require('sox');var csv=require(_0x69fc('0xa'));var ejs=require(_0x69fc('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x69fc('0xc'));var crypto=require(_0x69fc('0xd'));var jsforce=require(_0x69fc('0xe'));var deskjs=require(_0x69fc('0xf'));var toCsv=require(_0x69fc('0xa'));var querystring=require('querystring');var Papa=require(_0x69fc('0x10'));var Redis=require(_0x69fc('0x11'));var authService=require(_0x69fc('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x69fc('0x13'));var logger=require(_0x69fc('0x14'))(_0x69fc('0x15'));var utils=require(_0x69fc('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x69fc('0x17'));var db=require(_0x69fc('0x18'))['db'];function respondWithStatusCode(_0x243c3a,_0x1c1c73){_0x1c1c73=_0x1c1c73||0xcc;return function(_0x1cd5f9){if(_0x1cd5f9){return _0x243c3a[_0x69fc('0x19')](_0x1c1c73);}return _0x243c3a[_0x69fc('0x1a')](_0x1c1c73)[_0x69fc('0x1b')]();};}function respondWithResult(_0x138d0d,_0x1de368){_0x1de368=_0x1de368||0xc8;return function(_0x2e9038){if(_0x2e9038){return _0x138d0d[_0x69fc('0x1a')](_0x1de368)[_0x69fc('0x1c')](_0x2e9038);}};}function respondWithFilteredResult(_0x3466f2,_0x41e0bd){return function(_0x29939f){if(_0x29939f){var _0x3c260a=typeof _0x41e0bd['offset']===_0x69fc('0x1d')&&typeof _0x41e0bd[_0x69fc('0x1e')]==='undefined';var _0x54a94e=_0x29939f[_0x69fc('0x1f')];var _0x126642=_0x3c260a?0x0:_0x41e0bd[_0x69fc('0x20')];var _0x38e8eb=_0x3c260a?_0x29939f[_0x69fc('0x1f')]:_0x41e0bd['offset']+_0x41e0bd[_0x69fc('0x1e')];var _0x3d8378;if(_0x38e8eb>=_0x54a94e){_0x38e8eb=_0x54a94e;_0x3d8378=0xc8;}else{_0x3d8378=0xce;}_0x3466f2[_0x69fc('0x1a')](_0x3d8378);return _0x3466f2[_0x69fc('0x21')](_0x69fc('0x22'),_0x126642+'-'+_0x38e8eb+'/'+_0x54a94e)['json'](_0x29939f);}return null;};}function patchUpdates(_0xffc7e5){return function(_0x5a640b){try{jsonpatch['apply'](_0x5a640b,_0xffc7e5,!![]);}catch(_0x2efa49){return BPromise[_0x69fc('0x23')](_0x2efa49);}return _0x5a640b[_0x69fc('0x24')]();};}function saveUpdates(_0x4fedfc,_0x40cb6b){return function(_0x5ad863){if(_0x5ad863){return _0x5ad863[_0x69fc('0x25')](_0x4fedfc)['then'](function(_0x50321e){return _0x50321e;});}return null;};}function removeEntity(_0x4737f5,_0x642eb5){return function(_0x5c8837){if(_0x5c8837){return _0x5c8837[_0x69fc('0x26')]()[_0x69fc('0x27')](function(){_0x4737f5[_0x69fc('0x1a')](0xcc)[_0x69fc('0x1b')]();});}};}function handleEntityNotFound(_0x2f8270,_0x4e8efb){return function(_0x8f62cd){if(!_0x8f62cd){_0x2f8270[_0x69fc('0x19')](0x194);}return _0x8f62cd;};}function handleError(_0x55d93f,_0x3894d3){_0x3894d3=_0x3894d3||0x1f4;return function(_0x3b7d77){logger['error'](_0x3b7d77[_0x69fc('0x28')]);if(_0x3b7d77['name']){delete _0x3b7d77[_0x69fc('0x29')];}_0x55d93f[_0x69fc('0x1a')](_0x3894d3)[_0x69fc('0x2a')](_0x3b7d77);};}exports[_0x69fc('0x2b')]=function(_0x400b7f,_0xcb3477){var _0x21a335={},_0xf6e372={},_0x4c3617={'count':0x0,'rows':[]};var _0x37fbbf=_[_0x69fc('0x2c')](db[_0x69fc('0x2d')]['rawAttributes'],function(_0x4fbe3c){return{'name':_0x4fbe3c[_0x69fc('0x2e')],'type':_0x4fbe3c[_0x69fc('0x2f')][_0x69fc('0x30')]};});_0xf6e372[_0x69fc('0x31')]=_[_0x69fc('0x2c')](_0x37fbbf,'name');_0xf6e372[_0x69fc('0x32')]=_[_0x69fc('0x33')](_0x400b7f[_0x69fc('0x32')]);_0xf6e372[_0x69fc('0x34')]=_['intersection'](_0xf6e372[_0x69fc('0x31')],_0xf6e372[_0x69fc('0x32')]);_0x21a335[_0x69fc('0x35')]=_['intersection'](_0xf6e372[_0x69fc('0x31')],qs[_0x69fc('0x36')](_0x400b7f[_0x69fc('0x32')][_0x69fc('0x36')]));_0x21a335[_0x69fc('0x35')]=_0x21a335[_0x69fc('0x35')]['length']?_0x21a335[_0x69fc('0x35')]:_0xf6e372['model'];if(!_0x400b7f['query'][_0x69fc('0x37')](_0x69fc('0x38'))){_0x21a335[_0x69fc('0x1e')]=qs[_0x69fc('0x1e')](_0x400b7f[_0x69fc('0x32')]['limit']);_0x21a335[_0x69fc('0x20')]=qs[_0x69fc('0x20')](_0x400b7f[_0x69fc('0x32')]['offset']);}_0x21a335[_0x69fc('0x39')]=qs[_0x69fc('0x3a')](_0x400b7f[_0x69fc('0x32')]['sort']);_0x21a335[_0x69fc('0x3b')]=qs[_0x69fc('0x34')](_[_0x69fc('0x3c')](_0x400b7f[_0x69fc('0x32')],_0xf6e372[_0x69fc('0x34')]),_0x37fbbf);if(_0x400b7f[_0x69fc('0x32')][_0x69fc('0x3d')]){_0x21a335[_0x69fc('0x3b')]=_[_0x69fc('0x3e')](_0x21a335['where'],{'$or':_[_0x69fc('0x2c')](_0x37fbbf,function(_0x166c60){if(_0x166c60[_0x69fc('0x2f')]!==_0x69fc('0x3f')){var _0x406750={};_0x406750[_0x166c60['name']]={'$like':'%'+_0x400b7f['query'][_0x69fc('0x3d')]+'%'};return _0x406750;}})});}_0x21a335=_[_0x69fc('0x3e')]({},_0x21a335,_0x400b7f[_0x69fc('0x40')]);var _0x429f38={'where':_0x21a335['where']};return db[_0x69fc('0x2d')][_0x69fc('0x1f')](_0x429f38)[_0x69fc('0x27')](function(_0x15e9b4){_0x4c3617[_0x69fc('0x1f')]=_0x15e9b4;if(_0x400b7f[_0x69fc('0x32')][_0x69fc('0x41')]){_0x21a335[_0x69fc('0x42')]=[{'all':!![]}];}return db[_0x69fc('0x2d')][_0x69fc('0x43')](_0x21a335);})[_0x69fc('0x27')](function(_0x478c97){_0x4c3617[_0x69fc('0x44')]=_0x478c97;return _0x4c3617;})['then'](respondWithFilteredResult(_0xcb3477,_0x21a335))[_0x69fc('0x45')](handleError(_0xcb3477,null));};exports[_0x69fc('0x46')]=function(_0x321958,_0x5ce37d){var _0x16b139={'raw':!![],'where':{'id':_0x321958[_0x69fc('0x47')]['id']}},_0x1c60fb={};_0x1c60fb[_0x69fc('0x31')]=_[_0x69fc('0x33')](db['CmHopperHistory']['rawAttributes']);_0x1c60fb[_0x69fc('0x32')]=_[_0x69fc('0x33')](_0x321958[_0x69fc('0x32')]);_0x1c60fb[_0x69fc('0x34')]=_[_0x69fc('0x48')](_0x1c60fb[_0x69fc('0x31')],_0x1c60fb[_0x69fc('0x32')]);_0x16b139[_0x69fc('0x35')]=_[_0x69fc('0x48')](_0x1c60fb[_0x69fc('0x31')],qs[_0x69fc('0x36')](_0x321958[_0x69fc('0x32')][_0x69fc('0x36')]));_0x16b139[_0x69fc('0x35')]=_0x16b139['attributes'][_0x69fc('0x49')]?_0x16b139['attributes']:_0x1c60fb[_0x69fc('0x31')];if(_0x321958[_0x69fc('0x32')]['includeAll']){_0x16b139[_0x69fc('0x42')]=[{'all':!![]}];}_0x16b139=_[_0x69fc('0x3e')]({},_0x16b139,_0x321958[_0x69fc('0x40')]);return db[_0x69fc('0x2d')]['find'](_0x16b139)['then'](handleEntityNotFound(_0x5ce37d,null))[_0x69fc('0x27')](respondWithResult(_0x5ce37d,null))[_0x69fc('0x45')](handleError(_0x5ce37d,null));};exports[_0x69fc('0x4a')]=function(_0x534a35,_0x54250){return db[_0x69fc('0x2d')][_0x69fc('0x4a')](_0x534a35[_0x69fc('0x4b')],{})['then'](respondWithResult(_0x54250,0xc9))[_0x69fc('0x45')](handleError(_0x54250,null));};exports['describe']=function(_0x331be0,_0x3e87fe){return db[_0x69fc('0x2d')]['describe']()[_0x69fc('0x27')](respondWithResult(_0x3e87fe,null))[_0x69fc('0x45')](handleError(_0x3e87fe,null));};exports[_0x69fc('0x25')]=function(_0x29488f,_0x4f7eb5){if(_0x29488f[_0x69fc('0x4b')]['uniqueid']){delete _0x29488f[_0x69fc('0x4b')][_0x69fc('0x4c')];}return db[_0x69fc('0x2d')][_0x69fc('0x4d')]({'where':{'uniqueid':_0x29488f[_0x69fc('0x47')]['id']}})[_0x69fc('0x27')](handleEntityNotFound(_0x4f7eb5,null))[_0x69fc('0x27')](saveUpdates(_0x29488f[_0x69fc('0x4b')],null))[_0x69fc('0x27')](respondWithResult(_0x4f7eb5,null))[_0x69fc('0x45')](handleError(_0x4f7eb5,null));};