42fa284acf14dc9b1fd47934c870b77706519cd0
[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 _0x891f=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','then','destroy','error','stack','name','map','CmHopperHistory','rawAttributes','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','options','includeAll','include','findAll','rows','catch','show','params','find','create','describe','update','body','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring'];(function(_0xbe2f9d,_0x4c9cdb){var _0xa6ad32=function(_0x3caee7){while(--_0x3caee7){_0xbe2f9d['push'](_0xbe2f9d['shift']());}};_0xa6ad32(++_0x4c9cdb);}(_0x891f,0x113));var _0xf891=function(_0x2cd637,_0x201bcf){_0x2cd637=_0x2cd637-0x0;var _0x43225f=_0x891f[_0x2cd637];return _0x43225f;};'use strict';var emlformat=require(_0xf891('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf891('0x1'));var jsonpatch=require(_0xf891('0x2'));var rp=require(_0xf891('0x3'));var moment=require('moment');var BPromise=require(_0xf891('0x4'));var Mustache=require(_0xf891('0x5'));var util=require(_0xf891('0x6'));var path=require(_0xf891('0x7'));var sox=require(_0xf891('0x8'));var csv=require('to-csv');var ejs=require(_0xf891('0x9'));var fs=require('fs');var fs_extra=require(_0xf891('0xa'));var _=require('lodash');var squel=require(_0xf891('0xb'));var crypto=require(_0xf891('0xc'));var jsforce=require(_0xf891('0xd'));var deskjs=require(_0xf891('0xe'));var toCsv=require(_0xf891('0xf'));var querystring=require(_0xf891('0x10'));var Papa=require('papaparse');var Redis=require(_0xf891('0x11'));var authService=require(_0xf891('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xf891('0x13'));var hardwareService=require(_0xf891('0x14'));var logger=require(_0xf891('0x15'))(_0xf891('0x16'));var utils=require(_0xf891('0x17'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4e15f8,_0x11c72c){_0x11c72c=_0x11c72c||0xcc;return function(_0x4f0ba9){if(_0x4f0ba9){return _0x4e15f8[_0xf891('0x18')](_0x11c72c);}return _0x4e15f8[_0xf891('0x19')](_0x11c72c)[_0xf891('0x1a')]();};}function respondWithResult(_0x11c65c,_0x2713f0){_0x2713f0=_0x2713f0||0xc8;return function(_0x4db12e){if(_0x4db12e){return _0x11c65c[_0xf891('0x19')](_0x2713f0)[_0xf891('0x1b')](_0x4db12e);}};}function respondWithFilteredResult(_0x267aca,_0x11e354){return function(_0x892fed){if(_0x892fed){var _0x382e85=typeof _0x11e354[_0xf891('0x1c')]===_0xf891('0x1d')&&typeof _0x11e354['limit']===_0xf891('0x1d');var _0x5ac879=_0x892fed[_0xf891('0x1e')];var _0x30092e=_0x382e85?0x0:_0x11e354[_0xf891('0x1c')];var _0x27e782=_0x382e85?_0x892fed[_0xf891('0x1e')]:_0x11e354[_0xf891('0x1c')]+_0x11e354[_0xf891('0x1f')];var _0x452643;if(_0x27e782>=_0x5ac879){_0x27e782=_0x5ac879;_0x452643=0xc8;}else{_0x452643=0xce;}_0x267aca[_0xf891('0x19')](_0x452643);return _0x267aca[_0xf891('0x20')](_0xf891('0x21'),_0x30092e+'-'+_0x27e782+'/'+_0x5ac879)['json'](_0x892fed);}return null;};}function patchUpdates(_0x4ae199){return function(_0x27ac59){try{jsonpatch[_0xf891('0x22')](_0x27ac59,_0x4ae199,!![]);}catch(_0x40dd81){return BPromise['reject'](_0x40dd81);}return _0x27ac59['save']();};}function saveUpdates(_0x3100d4,_0x3017b0){return function(_0x2567b6){if(_0x2567b6){return _0x2567b6['update'](_0x3100d4)[_0xf891('0x23')](function(_0x1b776b){return _0x1b776b;});}return null;};}function removeEntity(_0x2758b9,_0x160862){return function(_0x44b19c){if(_0x44b19c){return _0x44b19c[_0xf891('0x24')]()[_0xf891('0x23')](function(){_0x2758b9[_0xf891('0x19')](0xcc)[_0xf891('0x1a')]();});}};}function handleEntityNotFound(_0x36b1b2,_0x4a176d){return function(_0x5f521e){if(!_0x5f521e){_0x36b1b2[_0xf891('0x18')](0x194);}return _0x5f521e;};}function handleError(_0x488f5c,_0x115080){_0x115080=_0x115080||0x1f4;return function(_0x2c9804){logger[_0xf891('0x25')](_0x2c9804[_0xf891('0x26')]);if(_0x2c9804['name']){delete _0x2c9804[_0xf891('0x27')];}_0x488f5c[_0xf891('0x19')](_0x115080)['send'](_0x2c9804);};}exports['index']=function(_0x172fea,_0x213f0d){var _0x40458e={},_0x492d8f={},_0x5d21cd={'count':0x0,'rows':[]};var _0x4e7a2e=_[_0xf891('0x28')](db[_0xf891('0x29')][_0xf891('0x2a')],function(_0x4eb779){return{'name':_0x4eb779['fieldName'],'type':_0x4eb779['type']['key']};});_0x492d8f[_0xf891('0x2b')]=_[_0xf891('0x28')](_0x4e7a2e,_0xf891('0x27'));_0x492d8f[_0xf891('0x2c')]=_[_0xf891('0x2d')](_0x172fea[_0xf891('0x2c')]);_0x492d8f[_0xf891('0x2e')]=_['intersection'](_0x492d8f['model'],_0x492d8f['query']);_0x40458e[_0xf891('0x2f')]=_[_0xf891('0x30')](_0x492d8f[_0xf891('0x2b')],qs[_0xf891('0x31')](_0x172fea[_0xf891('0x2c')][_0xf891('0x31')]));_0x40458e[_0xf891('0x2f')]=_0x40458e[_0xf891('0x2f')][_0xf891('0x32')]?_0x40458e['attributes']:_0x492d8f[_0xf891('0x2b')];if(!_0x172fea[_0xf891('0x2c')][_0xf891('0x33')](_0xf891('0x34'))){_0x40458e['limit']=qs['limit'](_0x172fea[_0xf891('0x2c')][_0xf891('0x1f')]);_0x40458e['offset']=qs[_0xf891('0x1c')](_0x172fea[_0xf891('0x2c')][_0xf891('0x1c')]);}_0x40458e[_0xf891('0x35')]=qs[_0xf891('0x36')](_0x172fea[_0xf891('0x2c')]['sort']);_0x40458e[_0xf891('0x37')]=qs[_0xf891('0x2e')](_[_0xf891('0x38')](_0x172fea['query'],_0x492d8f['filters']),_0x4e7a2e);if(_0x172fea[_0xf891('0x2c')][_0xf891('0x39')]){_0x40458e[_0xf891('0x37')]=_[_0xf891('0x3a')](_0x40458e[_0xf891('0x37')],{'$or':_['map'](_0x4e7a2e,function(_0x32df52){if(_0x32df52[_0xf891('0x3b')]!=='VIRTUAL'){var _0x31a6b5={};_0x31a6b5[_0x32df52[_0xf891('0x27')]]={'$like':'%'+_0x172fea[_0xf891('0x2c')][_0xf891('0x39')]+'%'};return _0x31a6b5;}})});}_0x40458e=_[_0xf891('0x3a')]({},_0x40458e,_0x172fea[_0xf891('0x3c')]);var _0x2ee2ac={'where':_0x40458e[_0xf891('0x37')]};return db[_0xf891('0x29')][_0xf891('0x1e')](_0x2ee2ac)[_0xf891('0x23')](function(_0x34e19b){_0x5d21cd[_0xf891('0x1e')]=_0x34e19b;if(_0x172fea[_0xf891('0x2c')][_0xf891('0x3d')]){_0x40458e[_0xf891('0x3e')]=[{'all':!![]}];}return db[_0xf891('0x29')][_0xf891('0x3f')](_0x40458e);})['then'](function(_0x2e322a){_0x5d21cd[_0xf891('0x40')]=_0x2e322a;return _0x5d21cd;})[_0xf891('0x23')](respondWithFilteredResult(_0x213f0d,_0x40458e))[_0xf891('0x41')](handleError(_0x213f0d,null));};exports[_0xf891('0x42')]=function(_0x50de54,_0x15cba7){var _0xa4997f={'raw':!![],'where':{'id':_0x50de54[_0xf891('0x43')]['id']}},_0x1f6ad8={};_0x1f6ad8[_0xf891('0x2b')]=_[_0xf891('0x2d')](db['CmHopperHistory']['rawAttributes']);_0x1f6ad8['query']=_[_0xf891('0x2d')](_0x50de54[_0xf891('0x2c')]);_0x1f6ad8['filters']=_[_0xf891('0x30')](_0x1f6ad8[_0xf891('0x2b')],_0x1f6ad8[_0xf891('0x2c')]);_0xa4997f[_0xf891('0x2f')]=_[_0xf891('0x30')](_0x1f6ad8['model'],qs[_0xf891('0x31')](_0x50de54['query'][_0xf891('0x31')]));_0xa4997f[_0xf891('0x2f')]=_0xa4997f[_0xf891('0x2f')][_0xf891('0x32')]?_0xa4997f['attributes']:_0x1f6ad8[_0xf891('0x2b')];if(_0x50de54[_0xf891('0x2c')][_0xf891('0x3d')]){_0xa4997f[_0xf891('0x3e')]=[{'all':!![]}];}_0xa4997f=_['merge']({},_0xa4997f,_0x50de54[_0xf891('0x3c')]);return db[_0xf891('0x29')][_0xf891('0x44')](_0xa4997f)['then'](handleEntityNotFound(_0x15cba7,null))[_0xf891('0x23')](respondWithResult(_0x15cba7,null))[_0xf891('0x41')](handleError(_0x15cba7,null));};exports[_0xf891('0x45')]=function(_0x1ca577,_0x36d160){return db[_0xf891('0x29')]['create'](_0x1ca577['body'],{})[_0xf891('0x23')](respondWithResult(_0x36d160,0xc9))['catch'](handleError(_0x36d160,null));};exports[_0xf891('0x46')]=function(_0x169ba2,_0x1675f2){return db[_0xf891('0x29')][_0xf891('0x46')]()['then'](respondWithResult(_0x1675f2,null))[_0xf891('0x41')](handleError(_0x1675f2,null));};exports[_0xf891('0x47')]=function(_0x1d9822,_0x2bcec4){if(_0x1d9822['body']['uniqueid']){delete _0x1d9822[_0xf891('0x48')]['uniqueid'];}return db[_0xf891('0x29')]['find']({'where':{'uniqueid':_0x1d9822['params']['id']}})[_0xf891('0x23')](handleEntityNotFound(_0x2bcec4,null))[_0xf891('0x23')](saveUpdates(_0x1d9822['body'],null))[_0xf891('0x23')](respondWithResult(_0x2bcec4,null))[_0xf891('0x41')](handleError(_0x2bcec4,null));};