Built motion from commit 25580385.|2.6.2
[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 _0x8f71=['merge','type','VIRTUAL','include','findAll','rows','catch','show','params','rawAttributes','find','create','body','describe','uniqueid','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','CmHopperHistory','fieldName','key','keys','query','filters','intersection','model','attributes','fields','length','nolimit','order','sort','pick','filter','where'];(function(_0x4ac716,_0x40243f){var _0x35f56b=function(_0x14e518){while(--_0x14e518){_0x4ac716['push'](_0x4ac716['shift']());}};_0x35f56b(++_0x40243f);}(_0x8f71,0x157));var _0x18f7=function(_0x1dd7a3,_0x2d7819){_0x1dd7a3=_0x1dd7a3-0x0;var _0x473c5d=_0x8f71[_0x1dd7a3];return _0x473c5d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x18f7('0x0'));var zipdir=require(_0x18f7('0x1'));var jsonpatch=require(_0x18f7('0x2'));var rp=require(_0x18f7('0x3'));var moment=require(_0x18f7('0x4'));var BPromise=require(_0x18f7('0x5'));var Mustache=require(_0x18f7('0x6'));var util=require(_0x18f7('0x7'));var path=require(_0x18f7('0x8'));var sox=require(_0x18f7('0x9'));var csv=require(_0x18f7('0xa'));var ejs=require(_0x18f7('0xb'));var fs=require('fs');var fs_extra=require(_0x18f7('0xc'));var _=require(_0x18f7('0xd'));var squel=require(_0x18f7('0xe'));var crypto=require(_0x18f7('0xf'));var jsforce=require(_0x18f7('0x10'));var deskjs=require(_0x18f7('0x11'));var toCsv=require(_0x18f7('0xa'));var querystring=require(_0x18f7('0x12'));var Papa=require('papaparse');var Redis=require(_0x18f7('0x13'));var authService=require(_0x18f7('0x14'));var qs=require(_0x18f7('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x18f7('0x16'));var logger=require(_0x18f7('0x17'))(_0x18f7('0x18'));var utils=require(_0x18f7('0x19'));var config=require(_0x18f7('0x1a'));var licenseUtil=require(_0x18f7('0x1b'));var db=require(_0x18f7('0x1c'))['db'];function respondWithStatusCode(_0x1c5165,_0x58b30d){_0x58b30d=_0x58b30d||0xcc;return function(_0x17c005){if(_0x17c005){return _0x1c5165['sendStatus'](_0x58b30d);}return _0x1c5165[_0x18f7('0x1d')](_0x58b30d)[_0x18f7('0x1e')]();};}function respondWithResult(_0x4f4e0a,_0x3dc2b0){_0x3dc2b0=_0x3dc2b0||0xc8;return function(_0xc9d7cc){if(_0xc9d7cc){return _0x4f4e0a[_0x18f7('0x1d')](_0x3dc2b0)['json'](_0xc9d7cc);}};}function respondWithFilteredResult(_0x514162,_0x1068cd){return function(_0x5dc69c){if(_0x5dc69c){var _0x27cf95=typeof _0x1068cd[_0x18f7('0x1f')]===_0x18f7('0x20')&&typeof _0x1068cd[_0x18f7('0x21')]==='undefined';var _0x2c8098=_0x5dc69c[_0x18f7('0x22')];var _0x2b2e17=_0x27cf95?0x0:_0x1068cd['offset'];var _0x32233e=_0x27cf95?_0x5dc69c[_0x18f7('0x22')]:_0x1068cd[_0x18f7('0x1f')]+_0x1068cd[_0x18f7('0x21')];var _0x4c9477;if(_0x32233e>=_0x2c8098){_0x32233e=_0x2c8098;_0x4c9477=0xc8;}else{_0x4c9477=0xce;}_0x514162['status'](_0x4c9477);return _0x514162[_0x18f7('0x23')](_0x18f7('0x24'),_0x2b2e17+'-'+_0x32233e+'/'+_0x2c8098)[_0x18f7('0x25')](_0x5dc69c);}return null;};}function patchUpdates(_0x7a56ce){return function(_0x2f8b48){try{jsonpatch['apply'](_0x2f8b48,_0x7a56ce,!![]);}catch(_0x24f7ca){return BPromise[_0x18f7('0x26')](_0x24f7ca);}return _0x2f8b48[_0x18f7('0x27')]();};}function saveUpdates(_0x2c8cf9,_0x3fbd39){return function(_0x444f34){if(_0x444f34){return _0x444f34[_0x18f7('0x28')](_0x2c8cf9)[_0x18f7('0x29')](function(_0x56afa8){return _0x56afa8;});}return null;};}function removeEntity(_0xdd088f,_0x2ec7cb){return function(_0x137d9c){if(_0x137d9c){return _0x137d9c[_0x18f7('0x2a')]()[_0x18f7('0x29')](function(){_0xdd088f['status'](0xcc)[_0x18f7('0x1e')]();});}};}function handleEntityNotFound(_0x35464a,_0x35c212){return function(_0x1cf03e){if(!_0x1cf03e){_0x35464a[_0x18f7('0x2b')](0x194);}return _0x1cf03e;};}function handleError(_0x11be80,_0x2ac81d){_0x2ac81d=_0x2ac81d||0x1f4;return function(_0x38db66){logger[_0x18f7('0x2c')](_0x38db66[_0x18f7('0x2d')]);if(_0x38db66[_0x18f7('0x2e')]){delete _0x38db66['name'];}_0x11be80['status'](_0x2ac81d)[_0x18f7('0x2f')](_0x38db66);};}exports[_0x18f7('0x30')]=function(_0x5734b1,_0x402b3c){var _0x1113bc={},_0x1c19ad={},_0x310737={'count':0x0,'rows':[]};var _0x2730f6=_[_0x18f7('0x31')](db[_0x18f7('0x32')]['rawAttributes'],function(_0x5de949){return{'name':_0x5de949[_0x18f7('0x33')],'type':_0x5de949['type'][_0x18f7('0x34')]};});_0x1c19ad['model']=_[_0x18f7('0x31')](_0x2730f6,_0x18f7('0x2e'));_0x1c19ad['query']=_[_0x18f7('0x35')](_0x5734b1[_0x18f7('0x36')]);_0x1c19ad[_0x18f7('0x37')]=_[_0x18f7('0x38')](_0x1c19ad[_0x18f7('0x39')],_0x1c19ad[_0x18f7('0x36')]);_0x1113bc[_0x18f7('0x3a')]=_['intersection'](_0x1c19ad[_0x18f7('0x39')],qs[_0x18f7('0x3b')](_0x5734b1[_0x18f7('0x36')][_0x18f7('0x3b')]));_0x1113bc[_0x18f7('0x3a')]=_0x1113bc[_0x18f7('0x3a')][_0x18f7('0x3c')]?_0x1113bc[_0x18f7('0x3a')]:_0x1c19ad['model'];if(!_0x5734b1['query']['hasOwnProperty'](_0x18f7('0x3d'))){_0x1113bc[_0x18f7('0x21')]=qs[_0x18f7('0x21')](_0x5734b1[_0x18f7('0x36')]['limit']);_0x1113bc[_0x18f7('0x1f')]=qs[_0x18f7('0x1f')](_0x5734b1['query']['offset']);}_0x1113bc[_0x18f7('0x3e')]=qs[_0x18f7('0x3f')](_0x5734b1[_0x18f7('0x36')]['sort']);_0x1113bc['where']=qs[_0x18f7('0x37')](_[_0x18f7('0x40')](_0x5734b1[_0x18f7('0x36')],_0x1c19ad[_0x18f7('0x37')]),_0x2730f6);if(_0x5734b1[_0x18f7('0x36')][_0x18f7('0x41')]){_0x1113bc[_0x18f7('0x42')]=_[_0x18f7('0x43')](_0x1113bc['where'],{'$or':_[_0x18f7('0x31')](_0x2730f6,function(_0x1f583c){if(_0x1f583c[_0x18f7('0x44')]!==_0x18f7('0x45')){var _0x25dc5b={};_0x25dc5b[_0x1f583c[_0x18f7('0x2e')]]={'$like':'%'+_0x5734b1['query'][_0x18f7('0x41')]+'%'};return _0x25dc5b;}})});}_0x1113bc=_[_0x18f7('0x43')]({},_0x1113bc,_0x5734b1['options']);var _0x5b8cc0={'where':_0x1113bc['where']};return db[_0x18f7('0x32')][_0x18f7('0x22')](_0x5b8cc0)[_0x18f7('0x29')](function(_0x42bd0c){_0x310737[_0x18f7('0x22')]=_0x42bd0c;if(_0x5734b1[_0x18f7('0x36')]['includeAll']){_0x1113bc[_0x18f7('0x46')]=[{'all':!![]}];}return db[_0x18f7('0x32')][_0x18f7('0x47')](_0x1113bc);})[_0x18f7('0x29')](function(_0x1a7e69){_0x310737[_0x18f7('0x48')]=_0x1a7e69;return _0x310737;})[_0x18f7('0x29')](respondWithFilteredResult(_0x402b3c,_0x1113bc))[_0x18f7('0x49')](handleError(_0x402b3c,null));};exports[_0x18f7('0x4a')]=function(_0x285d5b,_0x1dfe80){var _0x519be6={'raw':!![],'where':{'id':_0x285d5b[_0x18f7('0x4b')]['id']}},_0x41971e={};_0x41971e[_0x18f7('0x39')]=_[_0x18f7('0x35')](db['CmHopperHistory'][_0x18f7('0x4c')]);_0x41971e[_0x18f7('0x36')]=_['keys'](_0x285d5b['query']);_0x41971e[_0x18f7('0x37')]=_[_0x18f7('0x38')](_0x41971e[_0x18f7('0x39')],_0x41971e[_0x18f7('0x36')]);_0x519be6[_0x18f7('0x3a')]=_[_0x18f7('0x38')](_0x41971e[_0x18f7('0x39')],qs[_0x18f7('0x3b')](_0x285d5b[_0x18f7('0x36')]['fields']));_0x519be6[_0x18f7('0x3a')]=_0x519be6[_0x18f7('0x3a')][_0x18f7('0x3c')]?_0x519be6['attributes']:_0x41971e[_0x18f7('0x39')];if(_0x285d5b[_0x18f7('0x36')]['includeAll']){_0x519be6['include']=[{'all':!![]}];}_0x519be6=_[_0x18f7('0x43')]({},_0x519be6,_0x285d5b['options']);return db['CmHopperHistory'][_0x18f7('0x4d')](_0x519be6)[_0x18f7('0x29')](handleEntityNotFound(_0x1dfe80,null))['then'](respondWithResult(_0x1dfe80,null))[_0x18f7('0x49')](handleError(_0x1dfe80,null));};exports[_0x18f7('0x4e')]=function(_0x1bdfe6,_0x3286d6){return db['CmHopperHistory'][_0x18f7('0x4e')](_0x1bdfe6[_0x18f7('0x4f')],{})[_0x18f7('0x29')](respondWithResult(_0x3286d6,0xc9))['catch'](handleError(_0x3286d6,null));};exports[_0x18f7('0x50')]=function(_0x590c93,_0x2f9b04){return db[_0x18f7('0x32')][_0x18f7('0x50')]()[_0x18f7('0x29')](respondWithResult(_0x2f9b04,null))[_0x18f7('0x49')](handleError(_0x2f9b04,null));};exports[_0x18f7('0x28')]=function(_0x2f3eb4,_0x592627){if(_0x2f3eb4[_0x18f7('0x4f')]['uniqueid']){delete _0x2f3eb4[_0x18f7('0x4f')][_0x18f7('0x51')];}return db[_0x18f7('0x32')][_0x18f7('0x4d')]({'where':{'uniqueid':_0x2f3eb4[_0x18f7('0x4b')]['id']}})[_0x18f7('0x29')](handleEntityNotFound(_0x592627,null))[_0x18f7('0x29')](saveUpdates(_0x2f3eb4[_0x18f7('0x4f')],null))[_0x18f7('0x29')](respondWithResult(_0x592627,null))[_0x18f7('0x49')](handleError(_0x592627,null));};