Built motion from commit (unavailable).|2.5.31
[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 _0x5db8=['model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','type','VIRTUAL','options','includeAll','include','rows','catch','params','keys','find','create','describe','uniqueid','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','error','name','render','merge','body','contact','message','agent','interaction','account','index','CmHopperHistory','rawAttributes','fieldName','key'];(function(_0xaa8c2c,_0x36d94f){var _0x18f841=function(_0x332014){while(--_0x332014){_0xaa8c2c['push'](_0xaa8c2c['shift']());}};_0x18f841(++_0x36d94f);}(_0x5db8,0xbb));var _0x85db=function(_0x57a4d0,_0xa6e6b){_0x57a4d0=_0x57a4d0-0x0;var _0xaaadee=_0x5db8[_0x57a4d0];return _0xaaadee;};'use strict';var emlformat=require(_0x85db('0x0'));var rimraf=require(_0x85db('0x1'));var zipdir=require(_0x85db('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x85db('0x3'));var moment=require(_0x85db('0x4'));var BPromise=require(_0x85db('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x85db('0x6'));var sox=require(_0x85db('0x7'));var csv=require(_0x85db('0x8'));var ejs=require(_0x85db('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x85db('0xa'));var crypto=require(_0x85db('0xb'));var jsforce=require(_0x85db('0xc'));var deskjs=require(_0x85db('0xd'));var toCsv=require('to-csv');var querystring=require(_0x85db('0xe'));var Papa=require('papaparse');var Redis=require(_0x85db('0xf'));var authService=require(_0x85db('0x10'));var qs=require(_0x85db('0x11'));var as=require(_0x85db('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x85db('0x13'));var config=require(_0x85db('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x85db('0x15'))['db'];function respondWithStatusCode(_0x541f2f,_0x437f7a){_0x437f7a=_0x437f7a||0xcc;return function(_0x35f8c6){if(_0x35f8c6){return _0x541f2f[_0x85db('0x16')](_0x437f7a);}return _0x541f2f[_0x85db('0x17')](_0x437f7a)[_0x85db('0x18')]();};}function respondWithResult(_0xb7ea66,_0x2b7507){_0x2b7507=_0x2b7507||0xc8;return function(_0x25ec64){if(_0x25ec64){return _0xb7ea66[_0x85db('0x17')](_0x2b7507)[_0x85db('0x19')](_0x25ec64);}};}function respondWithFilteredResult(_0x1e9dec,_0x270fd7){return function(_0x2be61d){if(_0x2be61d){var _0x5ccfef=typeof _0x270fd7[_0x85db('0x1a')]===_0x85db('0x1b')&&typeof _0x270fd7[_0x85db('0x1c')]===_0x85db('0x1b');var _0x2ecd71=_0x2be61d[_0x85db('0x1d')];var _0x3209b3=_0x5ccfef?0x0:_0x270fd7['offset'];var _0x37ac04=_0x5ccfef?_0x2be61d[_0x85db('0x1d')]:_0x270fd7[_0x85db('0x1a')]+_0x270fd7[_0x85db('0x1c')];var _0x4d976d;if(_0x37ac04>=_0x2ecd71){_0x37ac04=_0x2ecd71;_0x4d976d=0xc8;}else{_0x4d976d=0xce;}_0x1e9dec[_0x85db('0x17')](_0x4d976d);return _0x1e9dec[_0x85db('0x1e')](_0x85db('0x1f'),_0x3209b3+'-'+_0x37ac04+'/'+_0x2ecd71)[_0x85db('0x19')](_0x2be61d);}return null;};}function patchUpdates(_0x107c10){return function(_0x5c37d7){try{jsonpatch[_0x85db('0x20')](_0x5c37d7,_0x107c10,!![]);}catch(_0x398aa2){return BPromise[_0x85db('0x21')](_0x398aa2);}return _0x5c37d7[_0x85db('0x22')]();};}function saveUpdates(_0x44c122,_0x3842d7){return function(_0x3a7148){if(_0x3a7148){return _0x3a7148[_0x85db('0x23')](_0x44c122)['then'](function(_0xfffea2){return _0xfffea2;});}return null;};}function removeEntity(_0x2534bc,_0x57fe5b){return function(_0x3381ec){if(_0x3381ec){return _0x3381ec[_0x85db('0x24')]()[_0x85db('0x25')](function(){_0x2534bc['status'](0xcc)[_0x85db('0x18')]();});}};}function handleEntityNotFound(_0x46f428,_0x1b1980){return function(_0x54ba03){if(!_0x54ba03){_0x46f428['sendStatus'](0x194);}return _0x54ba03;};}function handleError(_0x50ea52,_0x1e4ddb){_0x1e4ddb=_0x1e4ddb||0x1f4;return function(_0x105bb9){logger[_0x85db('0x26')](_0x105bb9['stack']);if(_0x105bb9[_0x85db('0x27')]){delete _0x105bb9[_0x85db('0x27')];}_0x50ea52[_0x85db('0x17')](_0x1e4ddb)['send'](_0x105bb9);};}function getMustacheRender(_0x5c8ddd,_0x299013){return Mustache[_0x85db('0x28')](_0x5c8ddd,_[_0x85db('0x29')](_0x299013[_0x85db('0x2a')],{'contact':_0x299013[_0x85db('0x2b')],'message':_0x299013[_0x85db('0x2c')],'agent':_0x299013[_0x85db('0x2d')],'interaction':_0x299013[_0x85db('0x2e')],'account':_0x299013[_0x85db('0x2f')]}))||'';}exports[_0x85db('0x30')]=function(_0x580e90,_0x4a15b9){var _0x13ad98={},_0x5e0e75={},_0x22e404={'count':0x0,'rows':[]};var _0x203cad=_['map'](db[_0x85db('0x31')][_0x85db('0x32')],function(_0x38369f){return{'name':_0x38369f[_0x85db('0x33')],'type':_0x38369f['type'][_0x85db('0x34')]};});_0x5e0e75[_0x85db('0x35')]=_[_0x85db('0x36')](_0x203cad,_0x85db('0x27'));_0x5e0e75[_0x85db('0x37')]=_['keys'](_0x580e90[_0x85db('0x37')]);_0x5e0e75[_0x85db('0x38')]=_[_0x85db('0x39')](_0x5e0e75[_0x85db('0x35')],_0x5e0e75['query']);_0x13ad98[_0x85db('0x3a')]=_[_0x85db('0x39')](_0x5e0e75[_0x85db('0x35')],qs['fields'](_0x580e90['query'][_0x85db('0x3b')]));_0x13ad98[_0x85db('0x3a')]=_0x13ad98['attributes'][_0x85db('0x3c')]?_0x13ad98[_0x85db('0x3a')]:_0x5e0e75[_0x85db('0x35')];if(!_0x580e90[_0x85db('0x37')][_0x85db('0x3d')](_0x85db('0x3e'))){_0x13ad98[_0x85db('0x1c')]=qs[_0x85db('0x1c')](_0x580e90[_0x85db('0x37')][_0x85db('0x1c')]);_0x13ad98[_0x85db('0x1a')]=qs[_0x85db('0x1a')](_0x580e90['query'][_0x85db('0x1a')]);}_0x13ad98[_0x85db('0x3f')]=qs[_0x85db('0x40')](_0x580e90[_0x85db('0x37')]['sort']);_0x13ad98[_0x85db('0x41')]=qs[_0x85db('0x38')](_[_0x85db('0x42')](_0x580e90[_0x85db('0x37')],_0x5e0e75['filters']),_0x203cad);if(_0x580e90['query']['filter']){_0x13ad98['where']=_['merge'](_0x13ad98[_0x85db('0x41')],{'$or':_[_0x85db('0x36')](_0x203cad,function(_0x3e8d9e){if(_0x3e8d9e[_0x85db('0x43')]!==_0x85db('0x44')){var _0x530e2a={};_0x530e2a[_0x3e8d9e['name']]={'$like':'%'+_0x580e90[_0x85db('0x37')]['filter']+'%'};return _0x530e2a;}})});}_0x13ad98=_[_0x85db('0x29')]({},_0x13ad98,_0x580e90[_0x85db('0x45')]);var _0x517b7e={'where':_0x13ad98['where']};return db[_0x85db('0x31')][_0x85db('0x1d')](_0x517b7e)[_0x85db('0x25')](function(_0x73eb93){_0x22e404[_0x85db('0x1d')]=_0x73eb93;if(_0x580e90['query'][_0x85db('0x46')]){_0x13ad98[_0x85db('0x47')]=[{'all':!![]}];}return db[_0x85db('0x31')]['findAll'](_0x13ad98);})['then'](function(_0x52ea6d){_0x22e404[_0x85db('0x48')]=_0x52ea6d;return _0x22e404;})[_0x85db('0x25')](respondWithFilteredResult(_0x4a15b9,_0x13ad98))[_0x85db('0x49')](handleError(_0x4a15b9,null));};exports['show']=function(_0x5ef59b,_0x3e4dbc){var _0x48f3ae={'raw':!![],'where':{'id':_0x5ef59b[_0x85db('0x4a')]['id']}},_0x35ec12={};_0x35ec12[_0x85db('0x35')]=_['keys'](db[_0x85db('0x31')][_0x85db('0x32')]);_0x35ec12[_0x85db('0x37')]=_[_0x85db('0x4b')](_0x5ef59b[_0x85db('0x37')]);_0x35ec12[_0x85db('0x38')]=_[_0x85db('0x39')](_0x35ec12[_0x85db('0x35')],_0x35ec12[_0x85db('0x37')]);_0x48f3ae['attributes']=_[_0x85db('0x39')](_0x35ec12[_0x85db('0x35')],qs[_0x85db('0x3b')](_0x5ef59b[_0x85db('0x37')][_0x85db('0x3b')]));_0x48f3ae[_0x85db('0x3a')]=_0x48f3ae['attributes'][_0x85db('0x3c')]?_0x48f3ae[_0x85db('0x3a')]:_0x35ec12[_0x85db('0x35')];if(_0x5ef59b['query']['includeAll']){_0x48f3ae[_0x85db('0x47')]=[{'all':!![]}];}_0x48f3ae=_['merge']({},_0x48f3ae,_0x5ef59b[_0x85db('0x45')]);return db[_0x85db('0x31')][_0x85db('0x4c')](_0x48f3ae)[_0x85db('0x25')](handleEntityNotFound(_0x3e4dbc,null))[_0x85db('0x25')](respondWithResult(_0x3e4dbc,null))['catch'](handleError(_0x3e4dbc,null));};exports['create']=function(_0x40d87c,_0x8a2d42){return db[_0x85db('0x31')][_0x85db('0x4d')](_0x40d87c[_0x85db('0x2a')],{})[_0x85db('0x25')](respondWithResult(_0x8a2d42,0xc9))[_0x85db('0x49')](handleError(_0x8a2d42,null));};exports[_0x85db('0x4e')]=function(_0x4735a0,_0xb59eda){return db['CmHopperHistory'][_0x85db('0x4e')]()[_0x85db('0x25')](respondWithResult(_0xb59eda,null))['catch'](handleError(_0xb59eda,null));};exports['update']=function(_0x8697f5,_0x306be6){if(_0x8697f5['body']['uniqueid']){delete _0x8697f5[_0x85db('0x2a')][_0x85db('0x4f')];}return db['CmHopperHistory'][_0x85db('0x4c')]({'where':{'uniqueid':_0x8697f5[_0x85db('0x4a')]['id']}})[_0x85db('0x25')](handleEntityNotFound(_0x306be6,null))[_0x85db('0x25')](saveUpdates(_0x8697f5[_0x85db('0x2a')],null))[_0x85db('0x25')](respondWithResult(_0x306be6,null))[_0x85db('0x49')](handleError(_0x306be6,null));};