Built motion from commit (unavailable).|2.4.20
[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 _0xf17f=['order','SessionId','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','ejs','squel','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','JscriptySessionReport','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','findOne','JscriptyQuestionReport'];(function(_0x1c7889,_0x24cd26){var _0x2f14e5=function(_0x9ae1b1){while(--_0x9ae1b1){_0x1c7889['push'](_0x1c7889['shift']());}};_0x2f14e5(++_0x24cd26);}(_0xf17f,0x13a));var _0xff17=function(_0xe22ceb,_0x27dc83){_0xe22ceb=_0xe22ceb-0x0;var _0x45bb58=_0xf17f[_0xe22ceb];return _0x45bb58;};'use strict';var pdf=require(_0xff17('0x0'));var emlformat=require(_0xff17('0x1'));var rimraf=require(_0xff17('0x2'));var zipdir=require(_0xff17('0x3'));var jsonpatch=require(_0xff17('0x4'));var rp=require('request-promise');var moment=require(_0xff17('0x5'));var BPromise=require(_0xff17('0x6'));var Mustache=require(_0xff17('0x7'));var util=require('util');var path=require(_0xff17('0x8'));var sox=require(_0xff17('0x9'));var csv=require('to-csv');var ejs=require(_0xff17('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xff17('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xff17('0xc'));var toCsv=require(_0xff17('0xd'));var querystring=require(_0xff17('0xe'));var Papa=require(_0xff17('0xf'));var Redis=require(_0xff17('0x10'));var authService=require(_0xff17('0x11'));var qs=require(_0xff17('0x12'));var as=require(_0xff17('0x13'));var hardwareService=require(_0xff17('0x14'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xff17('0x15'));var db=require(_0xff17('0x16'))['db'];function respondWithStatusCode(_0x4d87b4,_0x448b4b){_0x448b4b=_0x448b4b||0xcc;return function(_0x299666){if(_0x299666){return _0x4d87b4[_0xff17('0x17')](_0x448b4b);}return _0x4d87b4[_0xff17('0x18')](_0x448b4b)[_0xff17('0x19')]();};}function respondWithResult(_0x52df78,_0x346251){_0x346251=_0x346251||0xc8;return function(_0x3bb02c){if(_0x3bb02c){return _0x52df78[_0xff17('0x18')](_0x346251)[_0xff17('0x1a')](_0x3bb02c);}};}function respondWithFilteredResult(_0x14f0d2,_0x5281f3){return function(_0x55d0a7){if(_0x55d0a7){var _0x45692c=_0x55d0a7[_0xff17('0x1b')],_0x3eb0d7=_0x5281f3[_0xff17('0x1c')],_0x4e20ff=_0x5281f3['offset']+_0x5281f3[_0xff17('0x1d')],_0x17835d;if(_0x4e20ff>=_0x45692c){_0x4e20ff=_0x45692c;_0x17835d=0xc8;}else{_0x17835d=0xce;}_0x14f0d2[_0xff17('0x18')](_0x17835d);return _0x14f0d2[_0xff17('0x1e')](_0xff17('0x1f'),_0x3eb0d7+'-'+_0x4e20ff+'/'+_0x45692c)[_0xff17('0x1a')](_0x55d0a7);}return null;};}function patchUpdates(_0x4a9158){return function(_0x4d27e9){try{jsonpatch[_0xff17('0x20')](_0x4d27e9,_0x4a9158,!![]);}catch(_0x73e821){return BPromise[_0xff17('0x21')](_0x73e821);}return _0x4d27e9[_0xff17('0x22')]();};}function saveUpdates(_0x3aafaa,_0xc7407f){return function(_0x292e89){if(_0x292e89){return _0x292e89[_0xff17('0x23')](_0x3aafaa)[_0xff17('0x24')](function(_0x2dba3b){return _0x2dba3b;});}return null;};}function removeEntity(_0x204c59,_0x31ea67){return function(_0x42bd54){if(_0x42bd54){return _0x42bd54['destroy']()[_0xff17('0x24')](function(){_0x204c59[_0xff17('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3e0794,_0x5d908a){return function(_0x5be4da){if(!_0x5be4da){_0x3e0794['sendStatus'](0x194);}return _0x5be4da;};}function handleError(_0x12ba32,_0x1f4540){_0x1f4540=_0x1f4540||0x1f4;return function(_0x27edb8){logger[_0xff17('0x25')](_0x27edb8[_0xff17('0x26')]);if(_0x27edb8[_0xff17('0x27')]){delete _0x27edb8[_0xff17('0x27')];}_0x12ba32['status'](_0x1f4540)[_0xff17('0x28')](_0x27edb8);};}exports[_0xff17('0x29')]=function(_0x299a92,_0x264750){var _0x15bd1b={},_0x135f78={},_0x37b1f3={'count':0x0,'rows':[]};var _0x48d953=_[_0xff17('0x2a')](db[_0xff17('0x2b')][_0xff17('0x2c')],function(_0x4f36ac){return{'name':_0x4f36ac['fieldName'],'type':_0x4f36ac[_0xff17('0x2d')][_0xff17('0x2e')]};});_0x135f78[_0xff17('0x2f')]=_[_0xff17('0x2a')](_0x48d953,'name');_0x135f78[_0xff17('0x30')]=_[_0xff17('0x31')](_0x299a92[_0xff17('0x30')]);_0x135f78[_0xff17('0x32')]=_['intersection'](_0x135f78[_0xff17('0x2f')],_0x135f78[_0xff17('0x30')]);_0x15bd1b['attributes']=_[_0xff17('0x33')](_0x135f78[_0xff17('0x2f')],qs[_0xff17('0x34')](_0x299a92['query'][_0xff17('0x34')]));_0x15bd1b[_0xff17('0x35')]=_0x15bd1b[_0xff17('0x35')][_0xff17('0x36')]?_0x15bd1b[_0xff17('0x35')]:_0x135f78[_0xff17('0x2f')];if(!_0x299a92[_0xff17('0x30')][_0xff17('0x37')](_0xff17('0x38'))){_0x15bd1b[_0xff17('0x1d')]=qs[_0xff17('0x1d')](_0x299a92['query'][_0xff17('0x1d')]);_0x15bd1b['offset']=qs[_0xff17('0x1c')](_0x299a92[_0xff17('0x30')][_0xff17('0x1c')]);}_0x15bd1b['order']=qs[_0xff17('0x39')](_0x299a92[_0xff17('0x30')]['sort']);_0x15bd1b[_0xff17('0x3a')]=qs[_0xff17('0x32')](_['pick'](_0x299a92[_0xff17('0x30')],_0x135f78[_0xff17('0x32')]));if(_0x299a92['query'][_0xff17('0x3b')]){_0x15bd1b[_0xff17('0x3a')]=_[_0xff17('0x3c')](_0x15bd1b['where'],{'$or':_[_0xff17('0x2a')](_0x48d953,function(_0x31f765){if(_0x31f765[_0xff17('0x2d')]!==_0xff17('0x3d')){var _0x4a386a={};_0x4a386a[_0x31f765[_0xff17('0x27')]]={'$like':'%'+_0x299a92[_0xff17('0x30')]['filter']+'%'};return _0x4a386a;}})});}_0x15bd1b=_[_0xff17('0x3c')]({},_0x15bd1b,_0x299a92[_0xff17('0x3e')]);var _0xa69602={'where':_0x15bd1b[_0xff17('0x3a')]};return db[_0xff17('0x2b')][_0xff17('0x1b')](_0xa69602)[_0xff17('0x24')](function(_0x2d035e){_0x37b1f3[_0xff17('0x1b')]=_0x2d035e;if(_0x299a92[_0xff17('0x30')][_0xff17('0x3f')]){_0x15bd1b[_0xff17('0x40')]=[{'all':!![]}];}return db[_0xff17('0x2b')][_0xff17('0x41')](_0x15bd1b);})[_0xff17('0x24')](function(_0x4a1f7d){_0x37b1f3[_0xff17('0x42')]=_0x4a1f7d;return _0x37b1f3;})[_0xff17('0x24')](respondWithFilteredResult(_0x264750,_0x15bd1b))[_0xff17('0x43')](handleError(_0x264750,null));};exports[_0xff17('0x44')]=function(_0x309cbd,_0x188862){var _0x53ed23={'raw':!![],'where':{'id':_0x309cbd[_0xff17('0x45')]['id']}},_0x2167f1={};_0x2167f1['model']=_[_0xff17('0x31')](db[_0xff17('0x2b')][_0xff17('0x2c')]);_0x2167f1['query']=_[_0xff17('0x31')](_0x309cbd['query']);_0x2167f1[_0xff17('0x32')]=_[_0xff17('0x33')](_0x2167f1[_0xff17('0x2f')],_0x2167f1[_0xff17('0x30')]);_0x53ed23[_0xff17('0x35')]=_[_0xff17('0x33')](_0x2167f1[_0xff17('0x2f')],qs[_0xff17('0x34')](_0x309cbd[_0xff17('0x30')][_0xff17('0x34')]));_0x53ed23[_0xff17('0x35')]=_0x53ed23[_0xff17('0x35')]['length']?_0x53ed23[_0xff17('0x35')]:_0x2167f1[_0xff17('0x2f')];if(_0x309cbd['query'][_0xff17('0x3f')]){_0x53ed23['include']=[{'all':!![]}];}_0x53ed23=_[_0xff17('0x3c')]({},_0x53ed23,_0x309cbd[_0xff17('0x3e')]);return db[_0xff17('0x2b')][_0xff17('0x46')](_0x53ed23)[_0xff17('0x24')](handleEntityNotFound(_0x188862,null))[_0xff17('0x24')](respondWithResult(_0x188862,null))[_0xff17('0x43')](handleError(_0x188862,null));};exports[_0xff17('0x47')]=function(_0x5cfa66,_0x1f5bf1){return db['JscriptySessionReport'][_0xff17('0x47')](_0x5cfa66[_0xff17('0x48')],{})[_0xff17('0x24')](respondWithResult(_0x1f5bf1,0xc9))[_0xff17('0x43')](handleError(_0x1f5bf1,null));};exports[_0xff17('0x23')]=function(_0x45219f,_0x46eaff){if(_0x45219f[_0xff17('0x48')]['id']){delete _0x45219f[_0xff17('0x48')]['id'];}return db[_0xff17('0x2b')][_0xff17('0x46')]({'where':{'id':_0x45219f[_0xff17('0x45')]['id']}})[_0xff17('0x24')](handleEntityNotFound(_0x46eaff,null))[_0xff17('0x24')](saveUpdates(_0x45219f[_0xff17('0x48')],null))[_0xff17('0x24')](respondWithResult(_0x46eaff,null))[_0xff17('0x43')](handleError(_0x46eaff,null));};exports['destroy']=function(_0x4793c6,_0xb2ae2f){return db[_0xff17('0x2b')][_0xff17('0x46')]({'where':{'id':_0x4793c6[_0xff17('0x45')]['id']}})['then'](handleEntityNotFound(_0xb2ae2f,null))[_0xff17('0x24')](removeEntity(_0xb2ae2f,null))['catch'](handleError(_0xb2ae2f,null));};exports['describe']=function(_0x5dc2f3,_0x45b05a){return db['JscriptySessionReport'][_0xff17('0x49')]()[_0xff17('0x24')](respondWithResult(_0x45b05a,null))[_0xff17('0x43')](handleError(_0x45b05a,null));};exports['getQuestions']=function(_0x55fa70,_0x2411bb,_0x19f07e){var _0x33a4e7={'raw':!![],'where':{}};var _0x11c525={};var _0x108513={'count':0x0,'rows':[]};return db['JscriptySessionReport'][_0xff17('0x4a')]({'where':{'id':_0x55fa70['params']['id']}})[_0xff17('0x24')](handleEntityNotFound(_0x2411bb,null))['then'](function(_0xe1ad4){if(_0xe1ad4){_0x11c525[_0xff17('0x2f')]=_[_0xff17('0x31')](db[_0xff17('0x4b')][_0xff17('0x2c')]);_0x11c525[_0xff17('0x30')]=_['keys'](_0x55fa70['query']);_0x11c525['filters']=_[_0xff17('0x33')](_0x11c525[_0xff17('0x2f')],_0x11c525['query']);_0x33a4e7['attributes']=_[_0xff17('0x33')](_0x11c525['model'],qs['fields'](_0x55fa70[_0xff17('0x30')][_0xff17('0x34')]));_0x33a4e7[_0xff17('0x35')]=_0x33a4e7[_0xff17('0x35')][_0xff17('0x36')]?_0x33a4e7[_0xff17('0x35')]:_0x11c525[_0xff17('0x2f')];if(!_0x55fa70['query'][_0xff17('0x37')](_0xff17('0x38'))){_0x33a4e7['limit']=qs[_0xff17('0x1d')](_0x55fa70[_0xff17('0x30')][_0xff17('0x1d')]);_0x33a4e7[_0xff17('0x1c')]=qs[_0xff17('0x1c')](_0x55fa70['query'][_0xff17('0x1c')]);}_0x33a4e7[_0xff17('0x4c')]=qs['sort'](_0x55fa70['query'][_0xff17('0x39')]);_0x33a4e7[_0xff17('0x3a')]=qs[_0xff17('0x32')](_['pick'](_0x55fa70[_0xff17('0x30')],_0x11c525[_0xff17('0x32')]));_0x33a4e7[_0xff17('0x3a')][_0xff17('0x4d')]=_0xe1ad4['id'];if(_0x55fa70['query'][_0xff17('0x3b')]){_0x33a4e7[_0xff17('0x3a')]=_[_0xff17('0x3c')](_0x33a4e7['where'],{'$or':_['map'](_0x33a4e7['attributes'],function(_0x57b2f5){var _0x4f2673={};_0x4f2673[_0x57b2f5]={'$like':'%'+_0x55fa70[_0xff17('0x30')][_0xff17('0x3b')]+'%'};return _0x4f2673;})});}_0x33a4e7=_[_0xff17('0x3c')]({},_0x33a4e7,_0x55fa70[_0xff17('0x3e')]);return db['JscriptyQuestionReport'][_0xff17('0x1b')]({'where':_0x33a4e7['where']})[_0xff17('0x24')](function(_0x71cbf){_0x108513[_0xff17('0x1b')]=_0x71cbf;if(_0x55fa70[_0xff17('0x30')]['includeAll']){_0x33a4e7[_0xff17('0x40')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xff17('0x41')](_0x33a4e7);})[_0xff17('0x24')](function(_0x457bc7){_0x108513[_0xff17('0x42')]=_0x457bc7;return _0x108513;});}})[_0xff17('0x24')](respondWithFilteredResult(_0x2411bb,_0x33a4e7))[_0xff17('0x43')](handleError(_0x2411bb,null));};