Built motion from commit (unavailable).|2.4.3
[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 _0x599f=['fields','query','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','map','type','key','VIRTUAL','field','options','includeAll','findAll','rows','catch','show','params','rawAttributes','include','find','create','body','destroy','describe','getQuestions','findOne','JscriptyQuestionReport','SessionId','filter','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','ejs','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','count','offset','limit','set','Content-Range','json','reject','save','update','then','end','error','stack','name','index','JscriptySessionReport','model','keys','filters','intersection','attributes'];(function(_0x2ad3cc,_0x5201e2){var _0x472a69=function(_0x41cd86){while(--_0x41cd86){_0x2ad3cc['push'](_0x2ad3cc['shift']());}};_0x472a69(++_0x5201e2);}(_0x599f,0x74));var _0xf599=function(_0xba386f,_0x44b23c){_0xba386f=_0xba386f-0x0;var _0x40b503=_0x599f[_0xba386f];return _0x40b503;};'use strict';var pdf=require(_0xf599('0x0'));var emlformat=require(_0xf599('0x1'));var rimraf=require(_0xf599('0x2'));var zipdir=require(_0xf599('0x3'));var jsonpatch=require(_0xf599('0x4'));var rp=require(_0xf599('0x5'));var moment=require(_0xf599('0x6'));var BPromise=require(_0xf599('0x7'));var Mustache=require(_0xf599('0x8'));var util=require(_0xf599('0x9'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf599('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf599('0xb'));var crypto=require(_0xf599('0xc'));var jsforce=require(_0xf599('0xd'));var deskjs=require(_0xf599('0xe'));var toCsv=require(_0xf599('0xf'));var querystring=require(_0xf599('0x10'));var Papa=require(_0xf599('0x11'));var Redis=require(_0xf599('0x12'));var authService=require(_0xf599('0x13'));var qs=require('../../components/parsers/qs');var hardwareService=require(_0xf599('0x14'));var logger=require(_0xf599('0x15'))(_0xf599('0x16'));var utils=require(_0xf599('0x17'));var config=require(_0xf599('0x18'));var db=require(_0xf599('0x19'))['db'];function respondWithStatusCode(_0x1ecedf,_0x48d4cd){_0x48d4cd=_0x48d4cd||0xcc;return function(_0x34da5c){if(_0x34da5c){return _0x1ecedf['sendStatus'](_0x48d4cd);}return _0x1ecedf['status'](_0x48d4cd)['end']();};}function respondWithResult(_0x546d62,_0x332c7b){_0x332c7b=_0x332c7b||0xc8;return function(_0x195941){if(_0x195941){return _0x546d62[_0xf599('0x1a')](_0x332c7b)['json'](_0x195941);}};}function respondWithFilteredResult(_0x53292e,_0x408137){return function(_0x58f810){if(_0x58f810){var _0x5d5bc8=_0x58f810[_0xf599('0x1b')],_0x1e4124=_0x408137[_0xf599('0x1c')],_0x1ead22=_0x408137[_0xf599('0x1c')]+_0x408137[_0xf599('0x1d')],_0x56a408;if(_0x1ead22>=_0x5d5bc8){_0x1ead22=_0x5d5bc8;_0x56a408=0xc8;}else{_0x56a408=0xce;}_0x53292e[_0xf599('0x1a')](_0x56a408);return _0x53292e[_0xf599('0x1e')](_0xf599('0x1f'),_0x1e4124+'-'+_0x1ead22+'/'+_0x5d5bc8)[_0xf599('0x20')](_0x58f810);}return null;};}function patchUpdates(_0x2aff01){return function(_0x4d5d0d){try{jsonpatch['apply'](_0x4d5d0d,_0x2aff01,!![]);}catch(_0x5724a2){return BPromise[_0xf599('0x21')](_0x5724a2);}return _0x4d5d0d[_0xf599('0x22')]();};}function saveUpdates(_0x3df53d,_0x350754){return function(_0x821d48){if(_0x821d48){return _0x821d48[_0xf599('0x23')](_0x3df53d)['then'](function(_0x38e60e){return _0x38e60e;});}return null;};}function removeEntity(_0x99c1ce,_0x47d7d9){return function(_0x4697b5){if(_0x4697b5){return _0x4697b5['destroy']()[_0xf599('0x24')](function(){_0x99c1ce[_0xf599('0x1a')](0xcc)[_0xf599('0x25')]();});}};}function handleEntityNotFound(_0x695ebd,_0x480641){return function(_0x86866f){if(!_0x86866f){_0x695ebd['sendStatus'](0x194);}return _0x86866f;};}function handleError(_0x224744,_0x498634){_0x498634=_0x498634||0x1f4;return function(_0xa786c6){logger[_0xf599('0x26')](_0xa786c6[_0xf599('0x27')]);if(_0xa786c6[_0xf599('0x28')]){delete _0xa786c6['name'];}_0x224744[_0xf599('0x1a')](_0x498634)['send'](_0xa786c6);};}exports[_0xf599('0x29')]=function(_0x4c652e,_0xa8814b){var _0x1127c9={},_0x40ed53={},_0x59cdeb={'count':0x0,'rows':[]};var _0x2f78f1=db[_0xf599('0x2a')]['rawAttributes'];_0x40ed53[_0xf599('0x2b')]=_[_0xf599('0x2c')](_0x2f78f1);_0x40ed53['query']=_[_0xf599('0x2c')](_0x4c652e['query']);_0x40ed53[_0xf599('0x2d')]=_[_0xf599('0x2e')](_0x40ed53[_0xf599('0x2b')],_0x40ed53['query']);_0x1127c9[_0xf599('0x2f')]=_['intersection'](_0x40ed53['model'],qs[_0xf599('0x30')](_0x4c652e[_0xf599('0x31')][_0xf599('0x30')]));_0x1127c9[_0xf599('0x2f')]=_0x1127c9[_0xf599('0x2f')][_0xf599('0x32')]?_0x1127c9['attributes']:_0x40ed53[_0xf599('0x2b')];if(!_0x4c652e[_0xf599('0x31')][_0xf599('0x33')](_0xf599('0x34'))){_0x1127c9[_0xf599('0x1d')]=qs[_0xf599('0x1d')](_0x4c652e[_0xf599('0x31')][_0xf599('0x1d')]);_0x1127c9['offset']=qs[_0xf599('0x1c')](_0x4c652e[_0xf599('0x31')][_0xf599('0x1c')]);}_0x1127c9[_0xf599('0x35')]=qs[_0xf599('0x36')](_0x4c652e[_0xf599('0x31')]['sort']);_0x1127c9[_0xf599('0x37')]=qs[_0xf599('0x2d')](_[_0xf599('0x38')](_0x4c652e[_0xf599('0x31')],_0x40ed53['filters']));if(_0x4c652e['query']['filter']){_0x1127c9['where']=_[_0xf599('0x39')](_0x1127c9[_0xf599('0x37')],{'$or':_[_0xf599('0x3a')](_0x2f78f1,function(_0x3bd103){if(_0x3bd103[_0xf599('0x3b')][_0xf599('0x3c')]!==_0xf599('0x3d')){var _0x484683={};_0x484683[_0x3bd103[_0xf599('0x3e')]]={'$like':'%'+_0x4c652e[_0xf599('0x31')]['filter']+'%'};return _0x484683;}})});}_0x1127c9=_['merge']({},_0x1127c9,_0x4c652e[_0xf599('0x3f')]);var _0x21fb5d={'where':_0x1127c9[_0xf599('0x37')]};return db[_0xf599('0x2a')][_0xf599('0x1b')](_0x21fb5d)[_0xf599('0x24')](function(_0x41b1f9){_0x59cdeb[_0xf599('0x1b')]=_0x41b1f9;if(_0x4c652e['query'][_0xf599('0x40')]){_0x1127c9['include']=[{'all':!![]}];}return db['JscriptySessionReport'][_0xf599('0x41')](_0x1127c9);})[_0xf599('0x24')](function(_0x44e109){_0x59cdeb[_0xf599('0x42')]=_0x44e109;return _0x59cdeb;})[_0xf599('0x24')](respondWithFilteredResult(_0xa8814b,_0x1127c9))[_0xf599('0x43')](handleError(_0xa8814b,null));};exports[_0xf599('0x44')]=function(_0x42e1fc,_0x3ed8c4){var _0x2a4a76={'raw':!![],'where':{'id':_0x42e1fc[_0xf599('0x45')]['id']}},_0x73d7a6={};_0x73d7a6['model']=_[_0xf599('0x2c')](db[_0xf599('0x2a')][_0xf599('0x46')]);_0x73d7a6[_0xf599('0x31')]=_[_0xf599('0x2c')](_0x42e1fc[_0xf599('0x31')]);_0x73d7a6[_0xf599('0x2d')]=_[_0xf599('0x2e')](_0x73d7a6[_0xf599('0x2b')],_0x73d7a6['query']);_0x2a4a76[_0xf599('0x2f')]=_['intersection'](_0x73d7a6[_0xf599('0x2b')],qs['fields'](_0x42e1fc[_0xf599('0x31')][_0xf599('0x30')]));_0x2a4a76[_0xf599('0x2f')]=_0x2a4a76['attributes'][_0xf599('0x32')]?_0x2a4a76[_0xf599('0x2f')]:_0x73d7a6[_0xf599('0x2b')];if(_0x42e1fc[_0xf599('0x31')]['includeAll']){_0x2a4a76[_0xf599('0x47')]=[{'all':!![]}];}_0x2a4a76=_['merge']({},_0x2a4a76,_0x42e1fc[_0xf599('0x3f')]);return db[_0xf599('0x2a')][_0xf599('0x48')](_0x2a4a76)[_0xf599('0x24')](handleEntityNotFound(_0x3ed8c4,null))['then'](respondWithResult(_0x3ed8c4,null))[_0xf599('0x43')](handleError(_0x3ed8c4,null));};exports[_0xf599('0x49')]=function(_0x3c9e57,_0x5412b0){return db['JscriptySessionReport'][_0xf599('0x49')](_0x3c9e57[_0xf599('0x4a')],{})[_0xf599('0x24')](respondWithResult(_0x5412b0,0xc9))['catch'](handleError(_0x5412b0,null));};exports['update']=function(_0x33560a,_0xcf9898){if(_0x33560a['body']['id']){delete _0x33560a[_0xf599('0x4a')]['id'];}return db[_0xf599('0x2a')]['find']({'where':{'id':_0x33560a[_0xf599('0x45')]['id']}})['then'](handleEntityNotFound(_0xcf9898,null))[_0xf599('0x24')](saveUpdates(_0x33560a['body'],null))['then'](respondWithResult(_0xcf9898,null))[_0xf599('0x43')](handleError(_0xcf9898,null));};exports[_0xf599('0x4b')]=function(_0x44505a,_0x26bd39){return db[_0xf599('0x2a')][_0xf599('0x48')]({'where':{'id':_0x44505a[_0xf599('0x45')]['id']}})[_0xf599('0x24')](handleEntityNotFound(_0x26bd39,null))[_0xf599('0x24')](removeEntity(_0x26bd39,null))[_0xf599('0x43')](handleError(_0x26bd39,null));};exports[_0xf599('0x4c')]=function(_0x10ff23,_0x469de8){return db[_0xf599('0x2a')][_0xf599('0x4c')]()[_0xf599('0x24')](respondWithResult(_0x469de8,null))[_0xf599('0x43')](handleError(_0x469de8,null));};exports[_0xf599('0x4d')]=function(_0x26a21b,_0x44a3c2,_0x20e86b){var _0x316ff1={'raw':!![],'where':{}};var _0x586ae0={};var _0x381538={'count':0x0,'rows':[]};return db['JscriptySessionReport'][_0xf599('0x4e')]({'where':{'id':_0x26a21b[_0xf599('0x45')]['id']}})[_0xf599('0x24')](handleEntityNotFound(_0x44a3c2,null))['then'](function(_0x4f99c6){if(_0x4f99c6){_0x586ae0['model']=_[_0xf599('0x2c')](db[_0xf599('0x4f')][_0xf599('0x46')]);_0x586ae0['query']=_[_0xf599('0x2c')](_0x26a21b[_0xf599('0x31')]);_0x586ae0[_0xf599('0x2d')]=_[_0xf599('0x2e')](_0x586ae0[_0xf599('0x2b')],_0x586ae0[_0xf599('0x31')]);_0x316ff1[_0xf599('0x2f')]=_[_0xf599('0x2e')](_0x586ae0[_0xf599('0x2b')],qs[_0xf599('0x30')](_0x26a21b['query'][_0xf599('0x30')]));_0x316ff1[_0xf599('0x2f')]=_0x316ff1['attributes'][_0xf599('0x32')]?_0x316ff1[_0xf599('0x2f')]:_0x586ae0[_0xf599('0x2b')];if(!_0x26a21b['query'][_0xf599('0x33')](_0xf599('0x34'))){_0x316ff1[_0xf599('0x1d')]=qs[_0xf599('0x1d')](_0x26a21b[_0xf599('0x31')][_0xf599('0x1d')]);_0x316ff1[_0xf599('0x1c')]=qs[_0xf599('0x1c')](_0x26a21b[_0xf599('0x31')][_0xf599('0x1c')]);}_0x316ff1[_0xf599('0x35')]=qs['sort'](_0x26a21b[_0xf599('0x31')][_0xf599('0x36')]);_0x316ff1[_0xf599('0x37')]=qs['filters'](_[_0xf599('0x38')](_0x26a21b['query'],_0x586ae0['filters']));_0x316ff1[_0xf599('0x37')][_0xf599('0x50')]=_0x4f99c6['id'];if(_0x26a21b[_0xf599('0x31')]['filter']){_0x316ff1[_0xf599('0x37')]=_[_0xf599('0x39')](_0x316ff1[_0xf599('0x37')],{'$or':_[_0xf599('0x3a')](_0x316ff1[_0xf599('0x2f')],function(_0x353c48){var _0x390885={};_0x390885[_0x353c48]={'$like':'%'+_0x26a21b['query'][_0xf599('0x51')]+'%'};return _0x390885;})});}_0x316ff1=_['merge']({},_0x316ff1,_0x26a21b[_0xf599('0x3f')]);return db[_0xf599('0x4f')][_0xf599('0x1b')]({'where':_0x316ff1['where']})[_0xf599('0x24')](function(_0x257dda){_0x381538[_0xf599('0x1b')]=_0x257dda;if(_0x26a21b['query'][_0xf599('0x40')]){_0x316ff1[_0xf599('0x47')]=[{'all':!![]}];}return db[_0xf599('0x4f')][_0xf599('0x41')](_0x316ff1);})[_0xf599('0x24')](function(_0x18076d){_0x381538[_0xf599('0x42')]=_0x18076d;return _0x381538;});}})[_0xf599('0x24')](respondWithFilteredResult(_0x44a3c2,_0x316ff1))[_0xf599('0x43')](handleError(_0x44a3c2,null));};