Built motion from commit e0fa946e.|2.6.5
[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 _0x194f=['offset','undefined','limit','count','set','json','reject','save','update','then','stack','name','send','index','map','JscriptySessionReport','fieldName','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','catch','show','params','keys','find','create','body','destroy','describe','getQuestions','findOne','JscriptyQuestionReport','rawAttributes','SessionId','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end'];(function(_0x554e96,_0x2eea80){var _0x449d9c=function(_0x5536b5){while(--_0x5536b5){_0x554e96['push'](_0x554e96['shift']());}};_0x449d9c(++_0x2eea80);}(_0x194f,0x87));var _0xf194=function(_0x5c9ee8,_0x2629b8){_0x5c9ee8=_0x5c9ee8-0x0;var _0x2ab59d=_0x194f[_0x5c9ee8];return _0x2ab59d;};'use strict';var emlformat=require(_0xf194('0x0'));var rimraf=require(_0xf194('0x1'));var zipdir=require(_0xf194('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf194('0x3'));var moment=require(_0xf194('0x4'));var BPromise=require(_0xf194('0x5'));var Mustache=require(_0xf194('0x6'));var util=require(_0xf194('0x7'));var path=require('path');var sox=require(_0xf194('0x8'));var csv=require(_0xf194('0x9'));var ejs=require(_0xf194('0xa'));var fs=require('fs');var fs_extra=require(_0xf194('0xb'));var _=require(_0xf194('0xc'));var squel=require(_0xf194('0xd'));var crypto=require('crypto');var jsforce=require(_0xf194('0xe'));var deskjs=require(_0xf194('0xf'));var toCsv=require(_0xf194('0x9'));var querystring=require('querystring');var Papa=require(_0xf194('0x10'));var Redis=require(_0xf194('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xf194('0x12'));var as=require(_0xf194('0x13'));var hardwareService=require(_0xf194('0x14'));var logger=require(_0xf194('0x15'))(_0xf194('0x16'));var utils=require(_0xf194('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xf194('0x18'));var db=require(_0xf194('0x19'))['db'];function respondWithStatusCode(_0x11531f,_0x916098){_0x916098=_0x916098||0xcc;return function(_0x272e78){if(_0x272e78){return _0x11531f[_0xf194('0x1a')](_0x916098);}return _0x11531f[_0xf194('0x1b')](_0x916098)[_0xf194('0x1c')]();};}function respondWithResult(_0x328785,_0x90ca44){_0x90ca44=_0x90ca44||0xc8;return function(_0x20fa70){if(_0x20fa70){return _0x328785[_0xf194('0x1b')](_0x90ca44)['json'](_0x20fa70);}};}function respondWithFilteredResult(_0x3bffc6,_0x1b2043){return function(_0x1396c1){if(_0x1396c1){var _0x40b3d8=typeof _0x1b2043[_0xf194('0x1d')]===_0xf194('0x1e')&&typeof _0x1b2043[_0xf194('0x1f')]===_0xf194('0x1e');var _0x3ae0a8=_0x1396c1[_0xf194('0x20')];var _0x592b8b=_0x40b3d8?0x0:_0x1b2043[_0xf194('0x1d')];var _0x45ffe8=_0x40b3d8?_0x1396c1['count']:_0x1b2043[_0xf194('0x1d')]+_0x1b2043[_0xf194('0x1f')];var _0x3766c6;if(_0x45ffe8>=_0x3ae0a8){_0x45ffe8=_0x3ae0a8;_0x3766c6=0xc8;}else{_0x3766c6=0xce;}_0x3bffc6[_0xf194('0x1b')](_0x3766c6);return _0x3bffc6[_0xf194('0x21')]('Content-Range',_0x592b8b+'-'+_0x45ffe8+'/'+_0x3ae0a8)[_0xf194('0x22')](_0x1396c1);}return null;};}function patchUpdates(_0x43bd20){return function(_0x44628c){try{jsonpatch['apply'](_0x44628c,_0x43bd20,!![]);}catch(_0x34014a){return BPromise[_0xf194('0x23')](_0x34014a);}return _0x44628c[_0xf194('0x24')]();};}function saveUpdates(_0x581fa4,_0x100d54){return function(_0x2e3256){if(_0x2e3256){return _0x2e3256[_0xf194('0x25')](_0x581fa4)[_0xf194('0x26')](function(_0xcf29c5){return _0xcf29c5;});}return null;};}function removeEntity(_0x5a6fa9,_0x237641){return function(_0x1e4959){if(_0x1e4959){return _0x1e4959['destroy']()['then'](function(){_0x5a6fa9[_0xf194('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x542efd,_0x481e24){return function(_0x51f796){if(!_0x51f796){_0x542efd[_0xf194('0x1a')](0x194);}return _0x51f796;};}function handleError(_0x5033d0,_0x53706f){_0x53706f=_0x53706f||0x1f4;return function(_0x3cad4e){logger['error'](_0x3cad4e[_0xf194('0x27')]);if(_0x3cad4e['name']){delete _0x3cad4e[_0xf194('0x28')];}_0x5033d0['status'](_0x53706f)[_0xf194('0x29')](_0x3cad4e);};}exports[_0xf194('0x2a')]=function(_0x13b62c,_0x4243f8){var _0x555586={},_0x5b29a8={},_0x308a4c={'count':0x0,'rows':[]};var _0x3b765e=_[_0xf194('0x2b')](db[_0xf194('0x2c')]['rawAttributes'],function(_0x102cb5){return{'name':_0x102cb5[_0xf194('0x2d')],'type':_0x102cb5['type'][_0xf194('0x2e')]};});_0x5b29a8[_0xf194('0x2f')]=_[_0xf194('0x2b')](_0x3b765e,_0xf194('0x28'));_0x5b29a8[_0xf194('0x30')]=_['keys'](_0x13b62c[_0xf194('0x30')]);_0x5b29a8[_0xf194('0x31')]=_[_0xf194('0x32')](_0x5b29a8['model'],_0x5b29a8[_0xf194('0x30')]);_0x555586['attributes']=_[_0xf194('0x32')](_0x5b29a8[_0xf194('0x2f')],qs[_0xf194('0x33')](_0x13b62c[_0xf194('0x30')][_0xf194('0x33')]));_0x555586[_0xf194('0x34')]=_0x555586[_0xf194('0x34')][_0xf194('0x35')]?_0x555586[_0xf194('0x34')]:_0x5b29a8[_0xf194('0x2f')];if(!_0x13b62c['query'][_0xf194('0x36')](_0xf194('0x37'))){_0x555586[_0xf194('0x1f')]=qs[_0xf194('0x1f')](_0x13b62c['query'][_0xf194('0x1f')]);_0x555586[_0xf194('0x1d')]=qs['offset'](_0x13b62c['query'][_0xf194('0x1d')]);}_0x555586[_0xf194('0x38')]=qs[_0xf194('0x39')](_0x13b62c[_0xf194('0x30')][_0xf194('0x39')]);_0x555586[_0xf194('0x3a')]=qs[_0xf194('0x31')](_[_0xf194('0x3b')](_0x13b62c['query'],_0x5b29a8[_0xf194('0x31')]),_0x3b765e);if(_0x13b62c[_0xf194('0x30')][_0xf194('0x3c')]){_0x555586[_0xf194('0x3a')]=_[_0xf194('0x3d')](_0x555586[_0xf194('0x3a')],{'$or':_['map'](_0x3b765e,function(_0x5b5032){if(_0x5b5032[_0xf194('0x3e')]!==_0xf194('0x3f')){var _0x426d66={};_0x426d66[_0x5b5032['name']]={'$like':'%'+_0x13b62c[_0xf194('0x30')][_0xf194('0x3c')]+'%'};return _0x426d66;}})});}_0x555586=_[_0xf194('0x3d')]({},_0x555586,_0x13b62c[_0xf194('0x40')]);var _0x15758f={'where':_0x555586[_0xf194('0x3a')]};return db[_0xf194('0x2c')]['count'](_0x15758f)[_0xf194('0x26')](function(_0x14e533){_0x308a4c[_0xf194('0x20')]=_0x14e533;if(_0x13b62c[_0xf194('0x30')][_0xf194('0x41')]){_0x555586[_0xf194('0x42')]=[{'all':!![]}];}return db[_0xf194('0x2c')][_0xf194('0x43')](_0x555586);})[_0xf194('0x26')](function(_0x5e3e4a){_0x308a4c['rows']=_0x5e3e4a;return _0x308a4c;})[_0xf194('0x26')](respondWithFilteredResult(_0x4243f8,_0x555586))[_0xf194('0x44')](handleError(_0x4243f8,null));};exports[_0xf194('0x45')]=function(_0xaccb9c,_0x38eadd){var _0xcdfc8b={'raw':!![],'where':{'id':_0xaccb9c[_0xf194('0x46')]['id']}},_0x2b4e9a={};_0x2b4e9a['model']=_[_0xf194('0x47')](db['JscriptySessionReport']['rawAttributes']);_0x2b4e9a['query']=_[_0xf194('0x47')](_0xaccb9c['query']);_0x2b4e9a[_0xf194('0x31')]=_[_0xf194('0x32')](_0x2b4e9a[_0xf194('0x2f')],_0x2b4e9a[_0xf194('0x30')]);_0xcdfc8b[_0xf194('0x34')]=_['intersection'](_0x2b4e9a[_0xf194('0x2f')],qs[_0xf194('0x33')](_0xaccb9c[_0xf194('0x30')][_0xf194('0x33')]));_0xcdfc8b[_0xf194('0x34')]=_0xcdfc8b[_0xf194('0x34')][_0xf194('0x35')]?_0xcdfc8b[_0xf194('0x34')]:_0x2b4e9a['model'];if(_0xaccb9c[_0xf194('0x30')][_0xf194('0x41')]){_0xcdfc8b[_0xf194('0x42')]=[{'all':!![]}];}_0xcdfc8b=_[_0xf194('0x3d')]({},_0xcdfc8b,_0xaccb9c[_0xf194('0x40')]);return db[_0xf194('0x2c')][_0xf194('0x48')](_0xcdfc8b)[_0xf194('0x26')](handleEntityNotFound(_0x38eadd,null))[_0xf194('0x26')](respondWithResult(_0x38eadd,null))[_0xf194('0x44')](handleError(_0x38eadd,null));};exports[_0xf194('0x49')]=function(_0x1fe1e6,_0x38b3d3){return db[_0xf194('0x2c')][_0xf194('0x49')](_0x1fe1e6[_0xf194('0x4a')],{})[_0xf194('0x26')](respondWithResult(_0x38b3d3,0xc9))[_0xf194('0x44')](handleError(_0x38b3d3,null));};exports[_0xf194('0x25')]=function(_0x2dc974,_0x2620a0){if(_0x2dc974[_0xf194('0x4a')]['id']){delete _0x2dc974[_0xf194('0x4a')]['id'];}return db[_0xf194('0x2c')][_0xf194('0x48')]({'where':{'id':_0x2dc974['params']['id']}})[_0xf194('0x26')](handleEntityNotFound(_0x2620a0,null))[_0xf194('0x26')](saveUpdates(_0x2dc974[_0xf194('0x4a')],null))[_0xf194('0x26')](respondWithResult(_0x2620a0,null))[_0xf194('0x44')](handleError(_0x2620a0,null));};exports[_0xf194('0x4b')]=function(_0x307d84,_0x3a7fa7){return db[_0xf194('0x2c')]['find']({'where':{'id':_0x307d84[_0xf194('0x46')]['id']}})[_0xf194('0x26')](handleEntityNotFound(_0x3a7fa7,null))[_0xf194('0x26')](removeEntity(_0x3a7fa7,null))[_0xf194('0x44')](handleError(_0x3a7fa7,null));};exports[_0xf194('0x4c')]=function(_0x3bfb3b,_0x24657a){return db[_0xf194('0x2c')][_0xf194('0x4c')]()['then'](respondWithResult(_0x24657a,null))[_0xf194('0x44')](handleError(_0x24657a,null));};exports[_0xf194('0x4d')]=function(_0x4ceef1,_0x59281f,_0x5241ba){var _0x2e4f7f={'raw':!![],'where':{}};var _0x348bf1={};var _0x344633={'count':0x0,'rows':[]};return db[_0xf194('0x2c')][_0xf194('0x4e')]({'where':{'id':_0x4ceef1[_0xf194('0x46')]['id']}})[_0xf194('0x26')](handleEntityNotFound(_0x59281f,null))[_0xf194('0x26')](function(_0x570d15){if(_0x570d15){_0x348bf1['model']=_['keys'](db[_0xf194('0x4f')][_0xf194('0x50')]);_0x348bf1[_0xf194('0x30')]=_[_0xf194('0x47')](_0x4ceef1[_0xf194('0x30')]);_0x348bf1['filters']=_[_0xf194('0x32')](_0x348bf1[_0xf194('0x2f')],_0x348bf1[_0xf194('0x30')]);_0x2e4f7f['attributes']=_[_0xf194('0x32')](_0x348bf1['model'],qs[_0xf194('0x33')](_0x4ceef1[_0xf194('0x30')][_0xf194('0x33')]));_0x2e4f7f['attributes']=_0x2e4f7f[_0xf194('0x34')]['length']?_0x2e4f7f[_0xf194('0x34')]:_0x348bf1[_0xf194('0x2f')];if(!_0x4ceef1[_0xf194('0x30')][_0xf194('0x36')](_0xf194('0x37'))){_0x2e4f7f[_0xf194('0x1f')]=qs['limit'](_0x4ceef1[_0xf194('0x30')][_0xf194('0x1f')]);_0x2e4f7f[_0xf194('0x1d')]=qs[_0xf194('0x1d')](_0x4ceef1['query'][_0xf194('0x1d')]);}_0x2e4f7f[_0xf194('0x38')]=qs[_0xf194('0x39')](_0x4ceef1[_0xf194('0x30')]['sort']);_0x2e4f7f['where']=qs[_0xf194('0x31')](_[_0xf194('0x3b')](_0x4ceef1[_0xf194('0x30')],_0x348bf1[_0xf194('0x31')]));_0x2e4f7f['where'][_0xf194('0x51')]=_0x570d15['id'];if(_0x4ceef1[_0xf194('0x30')][_0xf194('0x3c')]){_0x2e4f7f[_0xf194('0x3a')]=_[_0xf194('0x3d')](_0x2e4f7f['where'],{'$or':_[_0xf194('0x2b')](_0x2e4f7f[_0xf194('0x34')],function(_0x4c2ca2){var _0x7811f5={};_0x7811f5[_0x4c2ca2]={'$like':'%'+_0x4ceef1[_0xf194('0x30')]['filter']+'%'};return _0x7811f5;})});}_0x2e4f7f=_['merge']({},_0x2e4f7f,_0x4ceef1[_0xf194('0x40')]);return db[_0xf194('0x4f')]['count']({'where':_0x2e4f7f[_0xf194('0x3a')]})[_0xf194('0x26')](function(_0x295469){_0x344633[_0xf194('0x20')]=_0x295469;if(_0x4ceef1[_0xf194('0x30')][_0xf194('0x41')]){_0x2e4f7f[_0xf194('0x42')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xf194('0x43')](_0x2e4f7f);})[_0xf194('0x26')](function(_0x3a284a){_0x344633['rows']=_0x3a284a;return _0x344633;});}})[_0xf194('0x26')](respondWithFilteredResult(_0x59281f,_0x2e4f7f))[_0xf194('0x44')](handleError(_0x59281f,null));};