Built motion from commit 3d6333b4.|2.6.31
[motion2.git] / server / api / jscriptySessionReport / jscriptySessionReport.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 _0xb5bd=['path','sox','to-csv','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','destroy','then','status','error','stack','send','map','rawAttributes','fieldName','type','key','name','query','keys','model','intersection','fields','attributes','hasOwnProperty','nolimit','order','where','filters','pick','filter','merge','VIRTUAL','JscriptySessionReport','includeAll','rows','catch','show','params','length','options','create','body','find','describe','JscriptyQuestionReport','sort','SessionId','include','findAll','eml-format','rimraf','zip-dir','request-promise','bluebird'];(function(_0x34adc9,_0x1e73ed){var _0x53b673=function(_0x1d0c99){while(--_0x1d0c99){_0x34adc9['push'](_0x34adc9['shift']());}};_0x53b673(++_0x1e73ed);}(_0xb5bd,0x9b));var _0xdb5b=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xb5bd[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xdb5b('0x0'));var rimraf=require(_0xdb5b('0x1'));var zipdir=require(_0xdb5b('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xdb5b('0x3'));var moment=require('moment');var BPromise=require(_0xdb5b('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0xdb5b('0x5'));var sox=require(_0xdb5b('0x6'));var csv=require(_0xdb5b('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xdb5b('0x8'));var squel=require(_0xdb5b('0x9'));var crypto=require('crypto');var jsforce=require(_0xdb5b('0xa'));var deskjs=require(_0xdb5b('0xb'));var toCsv=require(_0xdb5b('0x7'));var querystring=require(_0xdb5b('0xc'));var Papa=require(_0xdb5b('0xd'));var Redis=require(_0xdb5b('0xe'));var authService=require(_0xdb5b('0xf'));var qs=require(_0xdb5b('0x10'));var as=require(_0xdb5b('0x11'));var hardwareService=require(_0xdb5b('0x12'));var logger=require(_0xdb5b('0x13'))('api');var utils=require(_0xdb5b('0x14'));var config=require(_0xdb5b('0x15'));var licenseUtil=require(_0xdb5b('0x16'));var db=require(_0xdb5b('0x17'))['db'];function respondWithStatusCode(_0x133f53,_0x50d782){_0x50d782=_0x50d782||0xcc;return function(_0x393e8d){if(_0x393e8d){return _0x133f53[_0xdb5b('0x18')](_0x50d782);}return _0x133f53['status'](_0x50d782)[_0xdb5b('0x19')]();};}function respondWithResult(_0x3a96e0,_0xa1d5e2){_0xa1d5e2=_0xa1d5e2||0xc8;return function(_0x1250d1){if(_0x1250d1){return _0x3a96e0['status'](_0xa1d5e2)[_0xdb5b('0x1a')](_0x1250d1);}};}function respondWithFilteredResult(_0x1a36fa,_0x692e77){return function(_0xb73523){if(_0xb73523){var _0x1dac03=typeof _0x692e77[_0xdb5b('0x1b')]==='undefined'&&typeof _0x692e77[_0xdb5b('0x1c')]===_0xdb5b('0x1d');var _0x1a1c91=_0xb73523[_0xdb5b('0x1e')];var _0x337c5d=_0x1dac03?0x0:_0x692e77[_0xdb5b('0x1b')];var _0x520849=_0x1dac03?_0xb73523[_0xdb5b('0x1e')]:_0x692e77[_0xdb5b('0x1b')]+_0x692e77[_0xdb5b('0x1c')];var _0x43819d;if(_0x520849>=_0x1a1c91){_0x520849=_0x1a1c91;_0x43819d=0xc8;}else{_0x43819d=0xce;}_0x1a36fa['status'](_0x43819d);return _0x1a36fa[_0xdb5b('0x1f')](_0xdb5b('0x20'),_0x337c5d+'-'+_0x520849+'/'+_0x1a1c91)[_0xdb5b('0x1a')](_0xb73523);}return null;};}function patchUpdates(_0x838d20){return function(_0xeea28a){try{jsonpatch['apply'](_0xeea28a,_0x838d20,!![]);}catch(_0x12ef74){return BPromise[_0xdb5b('0x21')](_0x12ef74);}return _0xeea28a[_0xdb5b('0x22')]();};}function saveUpdates(_0x531fdd,_0x5ee221){return function(_0x567d6d){if(_0x567d6d){return _0x567d6d[_0xdb5b('0x23')](_0x531fdd)['then'](function(_0x26c0e1){return _0x26c0e1;});}return null;};}function removeEntity(_0x5bbc4f,_0x311c35){return function(_0x3b1cef){if(_0x3b1cef){return _0x3b1cef[_0xdb5b('0x24')]()[_0xdb5b('0x25')](function(){_0x5bbc4f[_0xdb5b('0x26')](0xcc)['end']();});}};}function handleEntityNotFound(_0x103b5b,_0x5bcfd1){return function(_0x209064){if(!_0x209064){_0x103b5b[_0xdb5b('0x18')](0x194);}return _0x209064;};}function handleError(_0x299302,_0x25100d){_0x25100d=_0x25100d||0x1f4;return function(_0x3ffa63){logger[_0xdb5b('0x27')](_0x3ffa63[_0xdb5b('0x28')]);if(_0x3ffa63['name']){delete _0x3ffa63['name'];}_0x299302['status'](_0x25100d)[_0xdb5b('0x29')](_0x3ffa63);};}exports['index']=function(_0x2d650f,_0x35bec8){var _0x2a1cab={},_0x21d24e={},_0x4d58c8={'count':0x0,'rows':[]};var _0x22acc1=_[_0xdb5b('0x2a')](db['JscriptySessionReport'][_0xdb5b('0x2b')],function(_0x1ac450){return{'name':_0x1ac450[_0xdb5b('0x2c')],'type':_0x1ac450[_0xdb5b('0x2d')][_0xdb5b('0x2e')]};});_0x21d24e['model']=_[_0xdb5b('0x2a')](_0x22acc1,_0xdb5b('0x2f'));_0x21d24e[_0xdb5b('0x30')]=_[_0xdb5b('0x31')](_0x2d650f['query']);_0x21d24e['filters']=_['intersection'](_0x21d24e[_0xdb5b('0x32')],_0x21d24e[_0xdb5b('0x30')]);_0x2a1cab['attributes']=_[_0xdb5b('0x33')](_0x21d24e['model'],qs[_0xdb5b('0x34')](_0x2d650f[_0xdb5b('0x30')][_0xdb5b('0x34')]));_0x2a1cab[_0xdb5b('0x35')]=_0x2a1cab['attributes']['length']?_0x2a1cab['attributes']:_0x21d24e[_0xdb5b('0x32')];if(!_0x2d650f[_0xdb5b('0x30')][_0xdb5b('0x36')](_0xdb5b('0x37'))){_0x2a1cab[_0xdb5b('0x1c')]=qs[_0xdb5b('0x1c')](_0x2d650f['query'][_0xdb5b('0x1c')]);_0x2a1cab[_0xdb5b('0x1b')]=qs['offset'](_0x2d650f[_0xdb5b('0x30')]['offset']);}_0x2a1cab[_0xdb5b('0x38')]=qs['sort'](_0x2d650f['query']['sort']);_0x2a1cab[_0xdb5b('0x39')]=qs[_0xdb5b('0x3a')](_[_0xdb5b('0x3b')](_0x2d650f['query'],_0x21d24e[_0xdb5b('0x3a')]),_0x22acc1);if(_0x2d650f[_0xdb5b('0x30')][_0xdb5b('0x3c')]){_0x2a1cab[_0xdb5b('0x39')]=_[_0xdb5b('0x3d')](_0x2a1cab[_0xdb5b('0x39')],{'$or':_['map'](_0x22acc1,function(_0x32f035){if(_0x32f035['type']!==_0xdb5b('0x3e')){var _0x3a9a7f={};_0x3a9a7f[_0x32f035['name']]={'$like':'%'+_0x2d650f[_0xdb5b('0x30')][_0xdb5b('0x3c')]+'%'};return _0x3a9a7f;}})});}_0x2a1cab=_[_0xdb5b('0x3d')]({},_0x2a1cab,_0x2d650f['options']);var _0x542319={'where':_0x2a1cab[_0xdb5b('0x39')]};return db[_0xdb5b('0x3f')][_0xdb5b('0x1e')](_0x542319)['then'](function(_0x4689f4){_0x4d58c8[_0xdb5b('0x1e')]=_0x4689f4;if(_0x2d650f[_0xdb5b('0x30')][_0xdb5b('0x40')]){_0x2a1cab['include']=[{'all':!![]}];}return db[_0xdb5b('0x3f')]['findAll'](_0x2a1cab);})[_0xdb5b('0x25')](function(_0x40228a){_0x4d58c8[_0xdb5b('0x41')]=_0x40228a;return _0x4d58c8;})[_0xdb5b('0x25')](respondWithFilteredResult(_0x35bec8,_0x2a1cab))[_0xdb5b('0x42')](handleError(_0x35bec8,null));};exports[_0xdb5b('0x43')]=function(_0x508301,_0x50e0db){var _0x5c9d89={'raw':!![],'where':{'id':_0x508301[_0xdb5b('0x44')]['id']}},_0x4c0ee8={};_0x4c0ee8[_0xdb5b('0x32')]=_[_0xdb5b('0x31')](db[_0xdb5b('0x3f')][_0xdb5b('0x2b')]);_0x4c0ee8[_0xdb5b('0x30')]=_[_0xdb5b('0x31')](_0x508301[_0xdb5b('0x30')]);_0x4c0ee8['filters']=_[_0xdb5b('0x33')](_0x4c0ee8[_0xdb5b('0x32')],_0x4c0ee8[_0xdb5b('0x30')]);_0x5c9d89[_0xdb5b('0x35')]=_[_0xdb5b('0x33')](_0x4c0ee8[_0xdb5b('0x32')],qs['fields'](_0x508301[_0xdb5b('0x30')][_0xdb5b('0x34')]));_0x5c9d89[_0xdb5b('0x35')]=_0x5c9d89['attributes'][_0xdb5b('0x45')]?_0x5c9d89['attributes']:_0x4c0ee8[_0xdb5b('0x32')];if(_0x508301[_0xdb5b('0x30')][_0xdb5b('0x40')]){_0x5c9d89['include']=[{'all':!![]}];}_0x5c9d89=_[_0xdb5b('0x3d')]({},_0x5c9d89,_0x508301[_0xdb5b('0x46')]);return db[_0xdb5b('0x3f')]['find'](_0x5c9d89)['then'](handleEntityNotFound(_0x50e0db,null))[_0xdb5b('0x25')](respondWithResult(_0x50e0db,null))[_0xdb5b('0x42')](handleError(_0x50e0db,null));};exports[_0xdb5b('0x47')]=function(_0x12255d,_0x3499c0){return db[_0xdb5b('0x3f')][_0xdb5b('0x47')](_0x12255d[_0xdb5b('0x48')],{})[_0xdb5b('0x25')](respondWithResult(_0x3499c0,0xc9))['catch'](handleError(_0x3499c0,null));};exports['update']=function(_0x894725,_0x33a7cd){if(_0x894725[_0xdb5b('0x48')]['id']){delete _0x894725[_0xdb5b('0x48')]['id'];}return db[_0xdb5b('0x3f')][_0xdb5b('0x49')]({'where':{'id':_0x894725[_0xdb5b('0x44')]['id']}})[_0xdb5b('0x25')](handleEntityNotFound(_0x33a7cd,null))['then'](saveUpdates(_0x894725['body'],null))['then'](respondWithResult(_0x33a7cd,null))[_0xdb5b('0x42')](handleError(_0x33a7cd,null));};exports['destroy']=function(_0xafee38,_0x7a20c1){return db[_0xdb5b('0x3f')]['find']({'where':{'id':_0xafee38[_0xdb5b('0x44')]['id']}})[_0xdb5b('0x25')](handleEntityNotFound(_0x7a20c1,null))['then'](removeEntity(_0x7a20c1,null))[_0xdb5b('0x42')](handleError(_0x7a20c1,null));};exports['describe']=function(_0x5a3281,_0x2deecf){return db[_0xdb5b('0x3f')][_0xdb5b('0x4a')]()['then'](respondWithResult(_0x2deecf,null))[_0xdb5b('0x42')](handleError(_0x2deecf,null));};exports['getQuestions']=function(_0x5e17db,_0x439ef3,_0x44ef40){var _0x228a65={'raw':!![],'where':{}};var _0x3f1e94={};var _0x5be049={'count':0x0,'rows':[]};return db[_0xdb5b('0x3f')]['findOne']({'where':{'id':_0x5e17db[_0xdb5b('0x44')]['id']}})['then'](handleEntityNotFound(_0x439ef3,null))[_0xdb5b('0x25')](function(_0x46c7ae){if(_0x46c7ae){_0x3f1e94[_0xdb5b('0x32')]=_['keys'](db[_0xdb5b('0x4b')][_0xdb5b('0x2b')]);_0x3f1e94['query']=_[_0xdb5b('0x31')](_0x5e17db[_0xdb5b('0x30')]);_0x3f1e94['filters']=_[_0xdb5b('0x33')](_0x3f1e94[_0xdb5b('0x32')],_0x3f1e94[_0xdb5b('0x30')]);_0x228a65[_0xdb5b('0x35')]=_[_0xdb5b('0x33')](_0x3f1e94['model'],qs['fields'](_0x5e17db[_0xdb5b('0x30')]['fields']));_0x228a65[_0xdb5b('0x35')]=_0x228a65[_0xdb5b('0x35')][_0xdb5b('0x45')]?_0x228a65[_0xdb5b('0x35')]:_0x3f1e94[_0xdb5b('0x32')];if(!_0x5e17db[_0xdb5b('0x30')][_0xdb5b('0x36')](_0xdb5b('0x37'))){_0x228a65[_0xdb5b('0x1c')]=qs[_0xdb5b('0x1c')](_0x5e17db['query'][_0xdb5b('0x1c')]);_0x228a65['offset']=qs[_0xdb5b('0x1b')](_0x5e17db[_0xdb5b('0x30')][_0xdb5b('0x1b')]);}_0x228a65['order']=qs[_0xdb5b('0x4c')](_0x5e17db[_0xdb5b('0x30')][_0xdb5b('0x4c')]);_0x228a65[_0xdb5b('0x39')]=qs['filters'](_[_0xdb5b('0x3b')](_0x5e17db[_0xdb5b('0x30')],_0x3f1e94[_0xdb5b('0x3a')]));_0x228a65['where'][_0xdb5b('0x4d')]=_0x46c7ae['id'];if(_0x5e17db[_0xdb5b('0x30')][_0xdb5b('0x3c')]){_0x228a65[_0xdb5b('0x39')]=_[_0xdb5b('0x3d')](_0x228a65['where'],{'$or':_[_0xdb5b('0x2a')](_0x228a65[_0xdb5b('0x35')],function(_0x39be2e){var _0x3c719b={};_0x3c719b[_0x39be2e]={'$like':'%'+_0x5e17db[_0xdb5b('0x30')][_0xdb5b('0x3c')]+'%'};return _0x3c719b;})});}_0x228a65=_[_0xdb5b('0x3d')]({},_0x228a65,_0x5e17db[_0xdb5b('0x46')]);return db['JscriptyQuestionReport'][_0xdb5b('0x1e')]({'where':_0x228a65['where']})[_0xdb5b('0x25')](function(_0x2721a4){_0x5be049[_0xdb5b('0x1e')]=_0x2721a4;if(_0x5e17db['query'][_0xdb5b('0x40')]){_0x228a65[_0xdb5b('0x4e')]=[{'all':!![]}];}return db[_0xdb5b('0x4b')][_0xdb5b('0x4f')](_0x228a65);})[_0xdb5b('0x25')](function(_0x1f1c80){_0x5be049[_0xdb5b('0x41')]=_0x1f1c80;return _0x5be049;});}})[_0xdb5b('0x25')](respondWithFilteredResult(_0x439ef3,_0x228a65))[_0xdb5b('0x42')](handleError(_0x439ef3,null));};