9786022e67ba98f46928909734ea1876a3d880b5
[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 _0x13dd=['save','update','destroy','then','stack','name','send','map','CmHopperHistory','fieldName','type','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','rows','catch','show','params','keys','rawAttributes','options','find','describe','body','uniqueid','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','reject'];(function(_0x1cb279,_0x5481b8){var _0x592903=function(_0x3f2e07){while(--_0x3f2e07){_0x1cb279['push'](_0x1cb279['shift']());}};_0x592903(++_0x5481b8);}(_0x13dd,0x1f1));var _0xd13d=function(_0x3c08b4,_0x52318d){_0x3c08b4=_0x3c08b4-0x0;var _0x5c200f=_0x13dd[_0x3c08b4];return _0x5c200f;};'use strict';var pdf=require(_0xd13d('0x0'));var emlformat=require(_0xd13d('0x1'));var rimraf=require(_0xd13d('0x2'));var zipdir=require(_0xd13d('0x3'));var jsonpatch=require(_0xd13d('0x4'));var rp=require('request-promise');var moment=require(_0xd13d('0x5'));var BPromise=require(_0xd13d('0x6'));var Mustache=require(_0xd13d('0x7'));var util=require(_0xd13d('0x8'));var path=require(_0xd13d('0x9'));var sox=require(_0xd13d('0xa'));var csv=require(_0xd13d('0xb'));var ejs=require(_0xd13d('0xc'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xd13d('0xd'));var jsforce=require(_0xd13d('0xe'));var deskjs=require(_0xd13d('0xf'));var toCsv=require(_0xd13d('0xb'));var querystring=require(_0xd13d('0x10'));var Papa=require('papaparse');var Redis=require(_0xd13d('0x11'));var authService=require(_0xd13d('0x12'));var qs=require(_0xd13d('0x13'));var as=require(_0xd13d('0x14'));var hardwareService=require(_0xd13d('0x15'));var logger=require(_0xd13d('0x16'))(_0xd13d('0x17'));var utils=require(_0xd13d('0x18'));var config=require(_0xd13d('0x19'));var licenseUtil=require(_0xd13d('0x1a'));var db=require(_0xd13d('0x1b'))['db'];function respondWithStatusCode(_0x561e84,_0x435b8b){_0x435b8b=_0x435b8b||0xcc;return function(_0x361d78){if(_0x361d78){return _0x561e84[_0xd13d('0x1c')](_0x435b8b);}return _0x561e84[_0xd13d('0x1d')](_0x435b8b)[_0xd13d('0x1e')]();};}function respondWithResult(_0xff4f51,_0x4b1b6a){_0x4b1b6a=_0x4b1b6a||0xc8;return function(_0x2b6add){if(_0x2b6add){return _0xff4f51[_0xd13d('0x1d')](_0x4b1b6a)[_0xd13d('0x1f')](_0x2b6add);}};}function respondWithFilteredResult(_0x234d86,_0x46bb20){return function(_0x3274ff){if(_0x3274ff){var _0x47c746=_0x3274ff[_0xd13d('0x20')],_0xa239f2=_0x46bb20[_0xd13d('0x21')],_0x288ca3=_0x46bb20['offset']+_0x46bb20['limit'],_0x3d3760;if(_0x288ca3>=_0x47c746){_0x288ca3=_0x47c746;_0x3d3760=0xc8;}else{_0x3d3760=0xce;}_0x234d86[_0xd13d('0x1d')](_0x3d3760);return _0x234d86['set']('Content-Range',_0xa239f2+'-'+_0x288ca3+'/'+_0x47c746)[_0xd13d('0x1f')](_0x3274ff);}return null;};}function patchUpdates(_0x140002){return function(_0xaac51c){try{jsonpatch['apply'](_0xaac51c,_0x140002,!![]);}catch(_0x4db44c){return BPromise[_0xd13d('0x22')](_0x4db44c);}return _0xaac51c[_0xd13d('0x23')]();};}function saveUpdates(_0x11817b,_0x40ee2d){return function(_0xffbc85){if(_0xffbc85){return _0xffbc85[_0xd13d('0x24')](_0x11817b)['then'](function(_0x3fe61c){return _0x3fe61c;});}return null;};}function removeEntity(_0xa4344f,_0x2116e9){return function(_0x227ef1){if(_0x227ef1){return _0x227ef1[_0xd13d('0x25')]()[_0xd13d('0x26')](function(){_0xa4344f[_0xd13d('0x1d')](0xcc)[_0xd13d('0x1e')]();});}};}function handleEntityNotFound(_0x498308,_0x58d5af){return function(_0x18bd68){if(!_0x18bd68){_0x498308['sendStatus'](0x194);}return _0x18bd68;};}function handleError(_0x4e0676,_0x3385d6){_0x3385d6=_0x3385d6||0x1f4;return function(_0x45903a){logger['error'](_0x45903a[_0xd13d('0x27')]);if(_0x45903a[_0xd13d('0x28')]){delete _0x45903a[_0xd13d('0x28')];}_0x4e0676[_0xd13d('0x1d')](_0x3385d6)[_0xd13d('0x29')](_0x45903a);};}exports['index']=function(_0x485f36,_0x24a30c){var _0x110a3a={},_0x26a4ad={},_0x6f627b={'count':0x0,'rows':[]};var _0x426e27=_[_0xd13d('0x2a')](db[_0xd13d('0x2b')]['rawAttributes'],function(_0x3eb96f){return{'name':_0x3eb96f[_0xd13d('0x2c')],'type':_0x3eb96f[_0xd13d('0x2d')]['key']};});_0x26a4ad['model']=_[_0xd13d('0x2a')](_0x426e27,_0xd13d('0x28'));_0x26a4ad[_0xd13d('0x2e')]=_['keys'](_0x485f36['query']);_0x26a4ad[_0xd13d('0x2f')]=_[_0xd13d('0x30')](_0x26a4ad[_0xd13d('0x31')],_0x26a4ad[_0xd13d('0x2e')]);_0x110a3a[_0xd13d('0x32')]=_[_0xd13d('0x30')](_0x26a4ad['model'],qs[_0xd13d('0x33')](_0x485f36['query']['fields']));_0x110a3a[_0xd13d('0x32')]=_0x110a3a[_0xd13d('0x32')][_0xd13d('0x34')]?_0x110a3a[_0xd13d('0x32')]:_0x26a4ad[_0xd13d('0x31')];if(!_0x485f36['query'][_0xd13d('0x35')](_0xd13d('0x36'))){_0x110a3a[_0xd13d('0x37')]=qs[_0xd13d('0x37')](_0x485f36[_0xd13d('0x2e')][_0xd13d('0x37')]);_0x110a3a[_0xd13d('0x21')]=qs['offset'](_0x485f36[_0xd13d('0x2e')]['offset']);}_0x110a3a[_0xd13d('0x38')]=qs[_0xd13d('0x39')](_0x485f36[_0xd13d('0x2e')][_0xd13d('0x39')]);_0x110a3a[_0xd13d('0x3a')]=qs[_0xd13d('0x2f')](_[_0xd13d('0x3b')](_0x485f36[_0xd13d('0x2e')],_0x26a4ad[_0xd13d('0x2f')]),_0x426e27);if(_0x485f36[_0xd13d('0x2e')][_0xd13d('0x3c')]){_0x110a3a[_0xd13d('0x3a')]=_[_0xd13d('0x3d')](_0x110a3a[_0xd13d('0x3a')],{'$or':_[_0xd13d('0x2a')](_0x426e27,function(_0x17bb1b){if(_0x17bb1b[_0xd13d('0x2d')]!==_0xd13d('0x3e')){var _0x1e5396={};_0x1e5396[_0x17bb1b['name']]={'$like':'%'+_0x485f36['query']['filter']+'%'};return _0x1e5396;}})});}_0x110a3a=_[_0xd13d('0x3d')]({},_0x110a3a,_0x485f36['options']);var _0x123e6b={'where':_0x110a3a[_0xd13d('0x3a')]};return db[_0xd13d('0x2b')][_0xd13d('0x20')](_0x123e6b)['then'](function(_0x3bea3d){_0x6f627b[_0xd13d('0x20')]=_0x3bea3d;if(_0x485f36['query'][_0xd13d('0x3f')]){_0x110a3a[_0xd13d('0x40')]=[{'all':!![]}];}return db[_0xd13d('0x2b')]['findAll'](_0x110a3a);})[_0xd13d('0x26')](function(_0x3eeee0){_0x6f627b[_0xd13d('0x41')]=_0x3eeee0;return _0x6f627b;})[_0xd13d('0x26')](respondWithFilteredResult(_0x24a30c,_0x110a3a))[_0xd13d('0x42')](handleError(_0x24a30c,null));};exports[_0xd13d('0x43')]=function(_0x21aac0,_0x231a2d){var _0x1de671={'raw':!![],'where':{'id':_0x21aac0[_0xd13d('0x44')]['id']}},_0xa70c53={};_0xa70c53[_0xd13d('0x31')]=_[_0xd13d('0x45')](db[_0xd13d('0x2b')][_0xd13d('0x46')]);_0xa70c53[_0xd13d('0x2e')]=_[_0xd13d('0x45')](_0x21aac0[_0xd13d('0x2e')]);_0xa70c53[_0xd13d('0x2f')]=_[_0xd13d('0x30')](_0xa70c53[_0xd13d('0x31')],_0xa70c53['query']);_0x1de671[_0xd13d('0x32')]=_[_0xd13d('0x30')](_0xa70c53[_0xd13d('0x31')],qs[_0xd13d('0x33')](_0x21aac0[_0xd13d('0x2e')][_0xd13d('0x33')]));_0x1de671[_0xd13d('0x32')]=_0x1de671[_0xd13d('0x32')]['length']?_0x1de671[_0xd13d('0x32')]:_0xa70c53['model'];if(_0x21aac0[_0xd13d('0x2e')]['includeAll']){_0x1de671[_0xd13d('0x40')]=[{'all':!![]}];}_0x1de671=_['merge']({},_0x1de671,_0x21aac0[_0xd13d('0x47')]);return db[_0xd13d('0x2b')][_0xd13d('0x48')](_0x1de671)[_0xd13d('0x26')](handleEntityNotFound(_0x231a2d,null))[_0xd13d('0x26')](respondWithResult(_0x231a2d,null))[_0xd13d('0x42')](handleError(_0x231a2d,null));};exports['create']=function(_0x4f6f4a,_0x2be6e6){return db[_0xd13d('0x2b')]['create'](_0x4f6f4a['body'],{})[_0xd13d('0x26')](respondWithResult(_0x2be6e6,0xc9))['catch'](handleError(_0x2be6e6,null));};exports[_0xd13d('0x49')]=function(_0x448d9e,_0x3a0218){return db[_0xd13d('0x2b')]['describe']()[_0xd13d('0x26')](respondWithResult(_0x3a0218,null))[_0xd13d('0x42')](handleError(_0x3a0218,null));};exports['update']=function(_0x4ad474,_0x322612){if(_0x4ad474['body']['uniqueid']){delete _0x4ad474[_0xd13d('0x4a')][_0xd13d('0x4b')];}return db[_0xd13d('0x2b')][_0xd13d('0x48')]({'where':{'uniqueid':_0x4ad474[_0xd13d('0x44')]['id']}})[_0xd13d('0x26')](handleEntityNotFound(_0x322612,null))['then'](saveUpdates(_0x4ad474[_0xd13d('0x4a')],null))[_0xd13d('0x26')](respondWithResult(_0x322612,null))[_0xd13d('0x42')](handleError(_0x322612,null));};