Built motion from commit ede67897.|2.6.29
[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 _0xf918=['include','find','create','body','params','describe','getQuestions','findOne','JscriptyQuestionReport','order','SessionId','eml-format','rimraf','zip-dir','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','status','end','json','limit','undefined','offset','set','Content-Range','apply','save','update','then','destroy','sendStatus','stack','name','send','index','map','JscriptySessionReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','sort','where','pick','filter','merge','VIRTUAL','options','count','findAll','rows','catch','show','includeAll'];(function(_0x43cdc9,_0x35df2a){var _0x2933e0=function(_0x480a54){while(--_0x480a54){_0x43cdc9['push'](_0x43cdc9['shift']());}};_0x2933e0(++_0x35df2a);}(_0xf918,0xa3));var _0x8f91=function(_0x2e914,_0x1c7566){_0x2e914=_0x2e914-0x0;var _0x936e45=_0xf918[_0x2e914];return _0x936e45;};'use strict';var emlformat=require(_0x8f91('0x0'));var rimraf=require(_0x8f91('0x1'));var zipdir=require(_0x8f91('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x8f91('0x3'));var BPromise=require(_0x8f91('0x4'));var Mustache=require('mustache');var util=require(_0x8f91('0x5'));var path=require(_0x8f91('0x6'));var sox=require('sox');var csv=require(_0x8f91('0x7'));var ejs=require(_0x8f91('0x8'));var fs=require('fs');var fs_extra=require(_0x8f91('0x9'));var _=require(_0x8f91('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x8f91('0xb'));var toCsv=require(_0x8f91('0x7'));var querystring=require('querystring');var Papa=require(_0x8f91('0xc'));var Redis=require(_0x8f91('0xd'));var authService=require(_0x8f91('0xe'));var qs=require(_0x8f91('0xf'));var as=require(_0x8f91('0x10'));var hardwareService=require(_0x8f91('0x11'));var logger=require(_0x8f91('0x12'))('api');var utils=require('../../config/utils');var config=require(_0x8f91('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4ee1a8,_0x57c7d8){_0x57c7d8=_0x57c7d8||0xcc;return function(_0x21e783){if(_0x21e783){return _0x4ee1a8['sendStatus'](_0x57c7d8);}return _0x4ee1a8[_0x8f91('0x14')](_0x57c7d8)[_0x8f91('0x15')]();};}function respondWithResult(_0x35eeb6,_0x33c16c){_0x33c16c=_0x33c16c||0xc8;return function(_0x4be887){if(_0x4be887){return _0x35eeb6['status'](_0x33c16c)[_0x8f91('0x16')](_0x4be887);}};}function respondWithFilteredResult(_0x13854f,_0x2b8ab0){return function(_0x302fe3){if(_0x302fe3){var _0x204b17=typeof _0x2b8ab0['offset']==='undefined'&&typeof _0x2b8ab0[_0x8f91('0x17')]===_0x8f91('0x18');var _0x591350=_0x302fe3['count'];var _0x3e01ab=_0x204b17?0x0:_0x2b8ab0['offset'];var _0x2ae208=_0x204b17?_0x302fe3['count']:_0x2b8ab0[_0x8f91('0x19')]+_0x2b8ab0[_0x8f91('0x17')];var _0x330864;if(_0x2ae208>=_0x591350){_0x2ae208=_0x591350;_0x330864=0xc8;}else{_0x330864=0xce;}_0x13854f[_0x8f91('0x14')](_0x330864);return _0x13854f[_0x8f91('0x1a')](_0x8f91('0x1b'),_0x3e01ab+'-'+_0x2ae208+'/'+_0x591350)[_0x8f91('0x16')](_0x302fe3);}return null;};}function patchUpdates(_0x56ac37){return function(_0x59cd1d){try{jsonpatch[_0x8f91('0x1c')](_0x59cd1d,_0x56ac37,!![]);}catch(_0x170432){return BPromise['reject'](_0x170432);}return _0x59cd1d[_0x8f91('0x1d')]();};}function saveUpdates(_0x52146d,_0x2836ee){return function(_0x2ef31c){if(_0x2ef31c){return _0x2ef31c[_0x8f91('0x1e')](_0x52146d)[_0x8f91('0x1f')](function(_0x20d51d){return _0x20d51d;});}return null;};}function removeEntity(_0x438cf7,_0x3ac0d6){return function(_0x30e543){if(_0x30e543){return _0x30e543[_0x8f91('0x20')]()[_0x8f91('0x1f')](function(){_0x438cf7[_0x8f91('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0xa4594f,_0xecfcfb){return function(_0xd5958c){if(!_0xd5958c){_0xa4594f[_0x8f91('0x21')](0x194);}return _0xd5958c;};}function handleError(_0x408a9e,_0x337873){_0x337873=_0x337873||0x1f4;return function(_0x1c81b6){logger['error'](_0x1c81b6[_0x8f91('0x22')]);if(_0x1c81b6[_0x8f91('0x23')]){delete _0x1c81b6['name'];}_0x408a9e['status'](_0x337873)[_0x8f91('0x24')](_0x1c81b6);};}exports[_0x8f91('0x25')]=function(_0x443fd1,_0x1d78e3){var _0x5b0c70={},_0x485f39={},_0x3288a0={'count':0x0,'rows':[]};var _0xa07424=_[_0x8f91('0x26')](db[_0x8f91('0x27')][_0x8f91('0x28')],function(_0x4362e2){return{'name':_0x4362e2[_0x8f91('0x29')],'type':_0x4362e2[_0x8f91('0x2a')][_0x8f91('0x2b')]};});_0x485f39[_0x8f91('0x2c')]=_['map'](_0xa07424,'name');_0x485f39[_0x8f91('0x2d')]=_[_0x8f91('0x2e')](_0x443fd1[_0x8f91('0x2d')]);_0x485f39[_0x8f91('0x2f')]=_[_0x8f91('0x30')](_0x485f39[_0x8f91('0x2c')],_0x485f39[_0x8f91('0x2d')]);_0x5b0c70[_0x8f91('0x31')]=_[_0x8f91('0x30')](_0x485f39[_0x8f91('0x2c')],qs['fields'](_0x443fd1[_0x8f91('0x2d')][_0x8f91('0x32')]));_0x5b0c70[_0x8f91('0x31')]=_0x5b0c70['attributes'][_0x8f91('0x33')]?_0x5b0c70[_0x8f91('0x31')]:_0x485f39[_0x8f91('0x2c')];if(!_0x443fd1[_0x8f91('0x2d')]['hasOwnProperty']('nolimit')){_0x5b0c70[_0x8f91('0x17')]=qs['limit'](_0x443fd1['query'][_0x8f91('0x17')]);_0x5b0c70[_0x8f91('0x19')]=qs[_0x8f91('0x19')](_0x443fd1[_0x8f91('0x2d')][_0x8f91('0x19')]);}_0x5b0c70['order']=qs[_0x8f91('0x34')](_0x443fd1[_0x8f91('0x2d')][_0x8f91('0x34')]);_0x5b0c70[_0x8f91('0x35')]=qs['filters'](_[_0x8f91('0x36')](_0x443fd1[_0x8f91('0x2d')],_0x485f39[_0x8f91('0x2f')]),_0xa07424);if(_0x443fd1['query'][_0x8f91('0x37')]){_0x5b0c70[_0x8f91('0x35')]=_[_0x8f91('0x38')](_0x5b0c70[_0x8f91('0x35')],{'$or':_[_0x8f91('0x26')](_0xa07424,function(_0x2996c4){if(_0x2996c4[_0x8f91('0x2a')]!==_0x8f91('0x39')){var _0x2b0f67={};_0x2b0f67[_0x2996c4[_0x8f91('0x23')]]={'$like':'%'+_0x443fd1[_0x8f91('0x2d')][_0x8f91('0x37')]+'%'};return _0x2b0f67;}})});}_0x5b0c70=_[_0x8f91('0x38')]({},_0x5b0c70,_0x443fd1[_0x8f91('0x3a')]);var _0x3b4f4c={'where':_0x5b0c70['where']};return db[_0x8f91('0x27')][_0x8f91('0x3b')](_0x3b4f4c)[_0x8f91('0x1f')](function(_0x1253d9){_0x3288a0['count']=_0x1253d9;if(_0x443fd1[_0x8f91('0x2d')]['includeAll']){_0x5b0c70['include']=[{'all':!![]}];}return db[_0x8f91('0x27')][_0x8f91('0x3c')](_0x5b0c70);})[_0x8f91('0x1f')](function(_0x33fbf0){_0x3288a0[_0x8f91('0x3d')]=_0x33fbf0;return _0x3288a0;})[_0x8f91('0x1f')](respondWithFilteredResult(_0x1d78e3,_0x5b0c70))[_0x8f91('0x3e')](handleError(_0x1d78e3,null));};exports[_0x8f91('0x3f')]=function(_0x227490,_0x2efa45){var _0x355e6f={'raw':!![],'where':{'id':_0x227490['params']['id']}},_0x2ebd6a={};_0x2ebd6a[_0x8f91('0x2c')]=_[_0x8f91('0x2e')](db[_0x8f91('0x27')][_0x8f91('0x28')]);_0x2ebd6a['query']=_[_0x8f91('0x2e')](_0x227490[_0x8f91('0x2d')]);_0x2ebd6a[_0x8f91('0x2f')]=_[_0x8f91('0x30')](_0x2ebd6a[_0x8f91('0x2c')],_0x2ebd6a[_0x8f91('0x2d')]);_0x355e6f[_0x8f91('0x31')]=_[_0x8f91('0x30')](_0x2ebd6a[_0x8f91('0x2c')],qs[_0x8f91('0x32')](_0x227490['query'][_0x8f91('0x32')]));_0x355e6f['attributes']=_0x355e6f['attributes'][_0x8f91('0x33')]?_0x355e6f[_0x8f91('0x31')]:_0x2ebd6a[_0x8f91('0x2c')];if(_0x227490[_0x8f91('0x2d')][_0x8f91('0x40')]){_0x355e6f[_0x8f91('0x41')]=[{'all':!![]}];}_0x355e6f=_[_0x8f91('0x38')]({},_0x355e6f,_0x227490[_0x8f91('0x3a')]);return db[_0x8f91('0x27')][_0x8f91('0x42')](_0x355e6f)['then'](handleEntityNotFound(_0x2efa45,null))[_0x8f91('0x1f')](respondWithResult(_0x2efa45,null))[_0x8f91('0x3e')](handleError(_0x2efa45,null));};exports[_0x8f91('0x43')]=function(_0x24ddf1,_0x1adeeb){return db['JscriptySessionReport'][_0x8f91('0x43')](_0x24ddf1[_0x8f91('0x44')],{})['then'](respondWithResult(_0x1adeeb,0xc9))['catch'](handleError(_0x1adeeb,null));};exports[_0x8f91('0x1e')]=function(_0x37b957,_0x234cd9){if(_0x37b957[_0x8f91('0x44')]['id']){delete _0x37b957[_0x8f91('0x44')]['id'];}return db[_0x8f91('0x27')][_0x8f91('0x42')]({'where':{'id':_0x37b957[_0x8f91('0x45')]['id']}})[_0x8f91('0x1f')](handleEntityNotFound(_0x234cd9,null))[_0x8f91('0x1f')](saveUpdates(_0x37b957[_0x8f91('0x44')],null))[_0x8f91('0x1f')](respondWithResult(_0x234cd9,null))[_0x8f91('0x3e')](handleError(_0x234cd9,null));};exports['destroy']=function(_0xaa2b4e,_0x351edd){return db[_0x8f91('0x27')]['find']({'where':{'id':_0xaa2b4e[_0x8f91('0x45')]['id']}})['then'](handleEntityNotFound(_0x351edd,null))['then'](removeEntity(_0x351edd,null))['catch'](handleError(_0x351edd,null));};exports[_0x8f91('0x46')]=function(_0x299d5e,_0x4fe169){return db['JscriptySessionReport']['describe']()[_0x8f91('0x1f')](respondWithResult(_0x4fe169,null))[_0x8f91('0x3e')](handleError(_0x4fe169,null));};exports[_0x8f91('0x47')]=function(_0x188d05,_0x31bedd,_0xebf3da){var _0xe81eae={'raw':!![],'where':{}};var _0x55e951={};var _0x4e0aa9={'count':0x0,'rows':[]};return db['JscriptySessionReport'][_0x8f91('0x48')]({'where':{'id':_0x188d05[_0x8f91('0x45')]['id']}})[_0x8f91('0x1f')](handleEntityNotFound(_0x31bedd,null))[_0x8f91('0x1f')](function(_0x26a6d6){if(_0x26a6d6){_0x55e951[_0x8f91('0x2c')]=_[_0x8f91('0x2e')](db[_0x8f91('0x49')][_0x8f91('0x28')]);_0x55e951['query']=_[_0x8f91('0x2e')](_0x188d05[_0x8f91('0x2d')]);_0x55e951[_0x8f91('0x2f')]=_[_0x8f91('0x30')](_0x55e951[_0x8f91('0x2c')],_0x55e951[_0x8f91('0x2d')]);_0xe81eae[_0x8f91('0x31')]=_[_0x8f91('0x30')](_0x55e951['model'],qs[_0x8f91('0x32')](_0x188d05['query'][_0x8f91('0x32')]));_0xe81eae[_0x8f91('0x31')]=_0xe81eae[_0x8f91('0x31')]['length']?_0xe81eae['attributes']:_0x55e951[_0x8f91('0x2c')];if(!_0x188d05['query']['hasOwnProperty']('nolimit')){_0xe81eae[_0x8f91('0x17')]=qs[_0x8f91('0x17')](_0x188d05[_0x8f91('0x2d')][_0x8f91('0x17')]);_0xe81eae[_0x8f91('0x19')]=qs['offset'](_0x188d05[_0x8f91('0x2d')][_0x8f91('0x19')]);}_0xe81eae[_0x8f91('0x4a')]=qs[_0x8f91('0x34')](_0x188d05[_0x8f91('0x2d')][_0x8f91('0x34')]);_0xe81eae[_0x8f91('0x35')]=qs[_0x8f91('0x2f')](_[_0x8f91('0x36')](_0x188d05[_0x8f91('0x2d')],_0x55e951['filters']));_0xe81eae[_0x8f91('0x35')][_0x8f91('0x4b')]=_0x26a6d6['id'];if(_0x188d05[_0x8f91('0x2d')][_0x8f91('0x37')]){_0xe81eae[_0x8f91('0x35')]=_[_0x8f91('0x38')](_0xe81eae[_0x8f91('0x35')],{'$or':_[_0x8f91('0x26')](_0xe81eae['attributes'],function(_0x5e3627){var _0x359474={};_0x359474[_0x5e3627]={'$like':'%'+_0x188d05[_0x8f91('0x2d')][_0x8f91('0x37')]+'%'};return _0x359474;})});}_0xe81eae=_[_0x8f91('0x38')]({},_0xe81eae,_0x188d05[_0x8f91('0x3a')]);return db[_0x8f91('0x49')][_0x8f91('0x3b')]({'where':_0xe81eae['where']})[_0x8f91('0x1f')](function(_0x2ab438){_0x4e0aa9[_0x8f91('0x3b')]=_0x2ab438;if(_0x188d05[_0x8f91('0x2d')][_0x8f91('0x40')]){_0xe81eae[_0x8f91('0x41')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0x8f91('0x3c')](_0xe81eae);})[_0x8f91('0x1f')](function(_0x196ef5){_0x4e0aa9['rows']=_0x196ef5;return _0x4e0aa9;});}})[_0x8f91('0x1f')](respondWithFilteredResult(_0x31bedd,_0xe81eae))[_0x8f91('0x3e')](handleError(_0x31bedd,null));};