Built motion from commit d6d69adf.|2.6.33
[motion2.git] / server / api / openchannelQueueReport / openchannelQueueReport.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 _0xb84b=['request-promise','moment','bluebird','mustache','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','count','limit','set','Content-Range','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','OpenchannelQueueReport','rawAttributes','fieldName','query','keys','filters','model','attributes','fields','length','nolimit','order','sort','where','filter','merge','type','VIRTUAL','options','includeAll','findAll','rows','show','params','intersection','include','catch','create','body','find','describe','eml-format','rimraf','fast-json-patch'];(function(_0x13b6fc,_0x3e52c1){var _0x595398=function(_0x2fb338){while(--_0x2fb338){_0x13b6fc['push'](_0x13b6fc['shift']());}};_0x595398(++_0x3e52c1);}(_0xb84b,0x139));var _0xbb84=function(_0xdb6406,_0x431a46){_0xdb6406=_0xdb6406-0x0;var _0x24386d=_0xb84b[_0xdb6406];return _0x24386d;};'use strict';var emlformat=require(_0xbb84('0x0'));var rimraf=require(_0xbb84('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbb84('0x2'));var rp=require(_0xbb84('0x3'));var moment=require(_0xbb84('0x4'));var BPromise=require(_0xbb84('0x5'));var Mustache=require(_0xbb84('0x6'));var util=require('util');var path=require(_0xbb84('0x7'));var sox=require(_0xbb84('0x8'));var csv=require(_0xbb84('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xbb84('0xa'));var _=require(_0xbb84('0xb'));var squel=require('squel');var crypto=require(_0xbb84('0xc'));var jsforce=require(_0xbb84('0xd'));var deskjs=require(_0xbb84('0xe'));var toCsv=require(_0xbb84('0x9'));var querystring=require(_0xbb84('0xf'));var Papa=require(_0xbb84('0x10'));var Redis=require(_0xbb84('0x11'));var authService=require(_0xbb84('0x12'));var qs=require(_0xbb84('0x13'));var as=require(_0xbb84('0x14'));var hardwareService=require(_0xbb84('0x15'));var logger=require('../../config/logger')(_0xbb84('0x16'));var utils=require(_0xbb84('0x17'));var config=require(_0xbb84('0x18'));var licenseUtil=require(_0xbb84('0x19'));var db=require(_0xbb84('0x1a'))['db'];function respondWithStatusCode(_0x54fea8,_0x55a917){_0x55a917=_0x55a917||0xcc;return function(_0x8a345e){if(_0x8a345e){return _0x54fea8['sendStatus'](_0x55a917);}return _0x54fea8[_0xbb84('0x1b')](_0x55a917)[_0xbb84('0x1c')]();};}function respondWithResult(_0xdd15cc,_0x18b330){_0x18b330=_0x18b330||0xc8;return function(_0x479a42){if(_0x479a42){return _0xdd15cc['status'](_0x18b330)[_0xbb84('0x1d')](_0x479a42);}};}function respondWithFilteredResult(_0x5c990c,_0x36c24d){return function(_0x4ec136){if(_0x4ec136){var _0x278d86=typeof _0x36c24d[_0xbb84('0x1e')]===_0xbb84('0x1f')&&typeof _0x36c24d['limit']===_0xbb84('0x1f');var _0x1e5ba9=_0x4ec136[_0xbb84('0x20')];var _0x358a4f=_0x278d86?0x0:_0x36c24d[_0xbb84('0x1e')];var _0xe1a193=_0x278d86?_0x4ec136[_0xbb84('0x20')]:_0x36c24d[_0xbb84('0x1e')]+_0x36c24d[_0xbb84('0x21')];var _0x28205c;if(_0xe1a193>=_0x1e5ba9){_0xe1a193=_0x1e5ba9;_0x28205c=0xc8;}else{_0x28205c=0xce;}_0x5c990c[_0xbb84('0x1b')](_0x28205c);return _0x5c990c[_0xbb84('0x22')](_0xbb84('0x23'),_0x358a4f+'-'+_0xe1a193+'/'+_0x1e5ba9)[_0xbb84('0x1d')](_0x4ec136);}return null;};}function patchUpdates(_0x346428){return function(_0x13e9ca){try{jsonpatch['apply'](_0x13e9ca,_0x346428,!![]);}catch(_0x2b2efa){return BPromise[_0xbb84('0x24')](_0x2b2efa);}return _0x13e9ca[_0xbb84('0x25')]();};}function saveUpdates(_0x417c7e,_0x108873){return function(_0x720c60){if(_0x720c60){return _0x720c60[_0xbb84('0x26')](_0x417c7e)[_0xbb84('0x27')](function(_0x17cf25){return _0x17cf25;});}return null;};}function removeEntity(_0x111ac9,_0x238eab){return function(_0x23c05d){if(_0x23c05d){return _0x23c05d[_0xbb84('0x28')]()[_0xbb84('0x27')](function(){_0x111ac9['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4d44d5,_0x37b1d9){return function(_0x780b35){if(!_0x780b35){_0x4d44d5[_0xbb84('0x29')](0x194);}return _0x780b35;};}function handleError(_0x287bed,_0x5e11cd){_0x5e11cd=_0x5e11cd||0x1f4;return function(_0x28437e){logger[_0xbb84('0x2a')](_0x28437e[_0xbb84('0x2b')]);if(_0x28437e['name']){delete _0x28437e[_0xbb84('0x2c')];}_0x287bed[_0xbb84('0x1b')](_0x5e11cd)[_0xbb84('0x2d')](_0x28437e);};}exports[_0xbb84('0x2e')]=function(_0x2083f8,_0x4eb464){var _0x2e1bb4={},_0x5b6cf4={},_0x2b90a0={'count':0x0,'rows':[]};var _0x310665=_[_0xbb84('0x2f')](db[_0xbb84('0x30')][_0xbb84('0x31')],function(_0x4b0702){return{'name':_0x4b0702[_0xbb84('0x32')],'type':_0x4b0702['type']['key']};});_0x5b6cf4['model']=_[_0xbb84('0x2f')](_0x310665,'name');_0x5b6cf4[_0xbb84('0x33')]=_[_0xbb84('0x34')](_0x2083f8['query']);_0x5b6cf4[_0xbb84('0x35')]=_['intersection'](_0x5b6cf4[_0xbb84('0x36')],_0x5b6cf4[_0xbb84('0x33')]);_0x2e1bb4[_0xbb84('0x37')]=_['intersection'](_0x5b6cf4['model'],qs[_0xbb84('0x38')](_0x2083f8[_0xbb84('0x33')][_0xbb84('0x38')]));_0x2e1bb4[_0xbb84('0x37')]=_0x2e1bb4[_0xbb84('0x37')][_0xbb84('0x39')]?_0x2e1bb4[_0xbb84('0x37')]:_0x5b6cf4[_0xbb84('0x36')];if(!_0x2083f8[_0xbb84('0x33')]['hasOwnProperty'](_0xbb84('0x3a'))){_0x2e1bb4[_0xbb84('0x21')]=qs['limit'](_0x2083f8[_0xbb84('0x33')][_0xbb84('0x21')]);_0x2e1bb4[_0xbb84('0x1e')]=qs[_0xbb84('0x1e')](_0x2083f8[_0xbb84('0x33')][_0xbb84('0x1e')]);}_0x2e1bb4[_0xbb84('0x3b')]=qs[_0xbb84('0x3c')](_0x2083f8[_0xbb84('0x33')][_0xbb84('0x3c')]);_0x2e1bb4[_0xbb84('0x3d')]=qs['filters'](_['pick'](_0x2083f8[_0xbb84('0x33')],_0x5b6cf4[_0xbb84('0x35')]),_0x310665);if(_0x2083f8[_0xbb84('0x33')][_0xbb84('0x3e')]){_0x2e1bb4[_0xbb84('0x3d')]=_[_0xbb84('0x3f')](_0x2e1bb4[_0xbb84('0x3d')],{'$or':_[_0xbb84('0x2f')](_0x310665,function(_0x1a1fa3){if(_0x1a1fa3[_0xbb84('0x40')]!==_0xbb84('0x41')){var _0xd726b0={};_0xd726b0[_0x1a1fa3[_0xbb84('0x2c')]]={'$like':'%'+_0x2083f8['query']['filter']+'%'};return _0xd726b0;}})});}_0x2e1bb4=_['merge']({},_0x2e1bb4,_0x2083f8[_0xbb84('0x42')]);var _0x34a54a={'where':_0x2e1bb4[_0xbb84('0x3d')]};return db['OpenchannelQueueReport'][_0xbb84('0x20')](_0x34a54a)[_0xbb84('0x27')](function(_0x5784f0){_0x2b90a0[_0xbb84('0x20')]=_0x5784f0;if(_0x2083f8[_0xbb84('0x33')][_0xbb84('0x43')]){_0x2e1bb4['include']=[{'all':!![]}];}return db[_0xbb84('0x30')][_0xbb84('0x44')](_0x2e1bb4);})[_0xbb84('0x27')](function(_0x5c8bd8){_0x2b90a0[_0xbb84('0x45')]=_0x5c8bd8;return _0x2b90a0;})[_0xbb84('0x27')](respondWithFilteredResult(_0x4eb464,_0x2e1bb4))['catch'](handleError(_0x4eb464,null));};exports[_0xbb84('0x46')]=function(_0x28b02a,_0x3bec88){var _0x37edc5={'raw':!![],'where':{'id':_0x28b02a[_0xbb84('0x47')]['id']}},_0x3e95cc={};_0x3e95cc['model']=_[_0xbb84('0x34')](db['OpenchannelQueueReport'][_0xbb84('0x31')]);_0x3e95cc[_0xbb84('0x33')]=_['keys'](_0x28b02a[_0xbb84('0x33')]);_0x3e95cc['filters']=_['intersection'](_0x3e95cc[_0xbb84('0x36')],_0x3e95cc['query']);_0x37edc5['attributes']=_[_0xbb84('0x48')](_0x3e95cc[_0xbb84('0x36')],qs['fields'](_0x28b02a[_0xbb84('0x33')][_0xbb84('0x38')]));_0x37edc5[_0xbb84('0x37')]=_0x37edc5[_0xbb84('0x37')][_0xbb84('0x39')]?_0x37edc5[_0xbb84('0x37')]:_0x3e95cc['model'];if(_0x28b02a[_0xbb84('0x33')][_0xbb84('0x43')]){_0x37edc5[_0xbb84('0x49')]=[{'all':!![]}];}_0x37edc5=_[_0xbb84('0x3f')]({},_0x37edc5,_0x28b02a[_0xbb84('0x42')]);return db['OpenchannelQueueReport']['find'](_0x37edc5)[_0xbb84('0x27')](handleEntityNotFound(_0x3bec88,null))[_0xbb84('0x27')](respondWithResult(_0x3bec88,null))[_0xbb84('0x4a')](handleError(_0x3bec88,null));};exports['create']=function(_0x2e964a,_0x536122){return db[_0xbb84('0x30')][_0xbb84('0x4b')](_0x2e964a[_0xbb84('0x4c')],{})[_0xbb84('0x27')](respondWithResult(_0x536122,0xc9))['catch'](handleError(_0x536122,null));};exports['update']=function(_0x58ce2e,_0x1c455c){if(_0x58ce2e[_0xbb84('0x4c')]['id']){delete _0x58ce2e[_0xbb84('0x4c')]['id'];}return db[_0xbb84('0x30')][_0xbb84('0x4d')]({'where':{'id':_0x58ce2e[_0xbb84('0x47')]['id']}})[_0xbb84('0x27')](handleEntityNotFound(_0x1c455c,null))['then'](saveUpdates(_0x58ce2e[_0xbb84('0x4c')],null))[_0xbb84('0x27')](respondWithResult(_0x1c455c,null))[_0xbb84('0x4a')](handleError(_0x1c455c,null));};exports[_0xbb84('0x28')]=function(_0x20b493,_0x58656a){return db[_0xbb84('0x30')][_0xbb84('0x4d')]({'where':{'id':_0x20b493[_0xbb84('0x47')]['id']}})[_0xbb84('0x27')](handleEntityNotFound(_0x58656a,null))[_0xbb84('0x27')](removeEntity(_0x58656a,null))['catch'](handleError(_0x58656a,null));};exports[_0xbb84('0x4e')]=function(_0x3cc89e,_0x212081){return db[_0xbb84('0x30')][_0xbb84('0x4e')]()[_0xbb84('0x27')](respondWithResult(_0x212081,null))['catch'](handleError(_0x212081,null));};