Built motion from commit (unavailable).|2.5.3
[motion2.git] / server / api / jscriptyAnswerReport / jscriptyAnswerReport.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 _0xdc50=['api','../../mysqldb','sendStatus','status','offset','limit','json','apply','reject','save','update','then','destroy','error','stack','name','map','rawAttributes','fieldName','type','key','keys','query','intersection','model','fields','attributes','hasOwnProperty','nolimit','where','filter','merge','VIRTUAL','options','JscriptyAnswerReport','count','include','findAll','show','params','length','includeAll','create','body','find','catch','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','squel','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger'];(function(_0x191154,_0x56f74c){var _0x3dcd73=function(_0x51c321){while(--_0x51c321){_0x191154['push'](_0x191154['shift']());}};_0x3dcd73(++_0x56f74c);}(_0xdc50,0xb5));var _0x0dc5=function(_0x502332,_0x456219){_0x502332=_0x502332-0x0;var _0x550c62=_0xdc50[_0x502332];return _0x550c62;};'use strict';var pdf=require(_0x0dc5('0x0'));var emlformat=require(_0x0dc5('0x1'));var rimraf=require(_0x0dc5('0x2'));var zipdir=require(_0x0dc5('0x3'));var jsonpatch=require(_0x0dc5('0x4'));var rp=require(_0x0dc5('0x5'));var moment=require(_0x0dc5('0x6'));var BPromise=require(_0x0dc5('0x7'));var Mustache=require(_0x0dc5('0x8'));var util=require('util');var path=require(_0x0dc5('0x9'));var sox=require('sox');var csv=require(_0x0dc5('0xa'));var ejs=require(_0x0dc5('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x0dc5('0xc'));var crypto=require('crypto');var jsforce=require(_0x0dc5('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x0dc5('0xa'));var querystring=require('querystring');var Papa=require(_0x0dc5('0xe'));var Redis=require(_0x0dc5('0xf'));var authService=require(_0x0dc5('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x0dc5('0x11'));var hardwareService=require(_0x0dc5('0x12'));var logger=require(_0x0dc5('0x13'))(_0x0dc5('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x0dc5('0x15'))['db'];function respondWithStatusCode(_0x3f82db,_0x313d46){_0x313d46=_0x313d46||0xcc;return function(_0x5cc76a){if(_0x5cc76a){return _0x3f82db[_0x0dc5('0x16')](_0x313d46);}return _0x3f82db[_0x0dc5('0x17')](_0x313d46)['end']();};}function respondWithResult(_0x1af174,_0x1dc7bc){_0x1dc7bc=_0x1dc7bc||0xc8;return function(_0x438cdf){if(_0x438cdf){return _0x1af174[_0x0dc5('0x17')](_0x1dc7bc)['json'](_0x438cdf);}};}function respondWithFilteredResult(_0x2a87c2,_0x358ef1){return function(_0x326309){if(_0x326309){var _0x586388=_0x326309['count'],_0xdb984e=_0x358ef1[_0x0dc5('0x18')],_0x90b929=_0x358ef1[_0x0dc5('0x18')]+_0x358ef1[_0x0dc5('0x19')],_0x54c365;if(_0x90b929>=_0x586388){_0x90b929=_0x586388;_0x54c365=0xc8;}else{_0x54c365=0xce;}_0x2a87c2['status'](_0x54c365);return _0x2a87c2['set']('Content-Range',_0xdb984e+'-'+_0x90b929+'/'+_0x586388)[_0x0dc5('0x1a')](_0x326309);}return null;};}function patchUpdates(_0x401942){return function(_0x1a13eb){try{jsonpatch[_0x0dc5('0x1b')](_0x1a13eb,_0x401942,!![]);}catch(_0x2bf192){return BPromise[_0x0dc5('0x1c')](_0x2bf192);}return _0x1a13eb[_0x0dc5('0x1d')]();};}function saveUpdates(_0x1df7f6,_0xef92c3){return function(_0x2e8c5c){if(_0x2e8c5c){return _0x2e8c5c[_0x0dc5('0x1e')](_0x1df7f6)[_0x0dc5('0x1f')](function(_0x2a7ce9){return _0x2a7ce9;});}return null;};}function removeEntity(_0x1349fc,_0x19e89e){return function(_0x4e3b8e){if(_0x4e3b8e){return _0x4e3b8e[_0x0dc5('0x20')]()[_0x0dc5('0x1f')](function(){_0x1349fc[_0x0dc5('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4c7217,_0x15a987){return function(_0x4280b5){if(!_0x4280b5){_0x4c7217['sendStatus'](0x194);}return _0x4280b5;};}function handleError(_0x32311b,_0x2c2cc9){_0x2c2cc9=_0x2c2cc9||0x1f4;return function(_0x4a82cd){logger[_0x0dc5('0x21')](_0x4a82cd[_0x0dc5('0x22')]);if(_0x4a82cd[_0x0dc5('0x23')]){delete _0x4a82cd[_0x0dc5('0x23')];}_0x32311b[_0x0dc5('0x17')](_0x2c2cc9)['send'](_0x4a82cd);};}exports['index']=function(_0x4e743b,_0x12eb4b){var _0x2977ef={},_0x553b38={},_0x2d1fd5={'count':0x0,'rows':[]};var _0x4746b8=_[_0x0dc5('0x24')](db['JscriptyAnswerReport'][_0x0dc5('0x25')],function(_0x5463ec){return{'name':_0x5463ec[_0x0dc5('0x26')],'type':_0x5463ec[_0x0dc5('0x27')][_0x0dc5('0x28')]};});_0x553b38['model']=_[_0x0dc5('0x24')](_0x4746b8,_0x0dc5('0x23'));_0x553b38['query']=_[_0x0dc5('0x29')](_0x4e743b[_0x0dc5('0x2a')]);_0x553b38['filters']=_['intersection'](_0x553b38['model'],_0x553b38['query']);_0x2977ef['attributes']=_[_0x0dc5('0x2b')](_0x553b38[_0x0dc5('0x2c')],qs[_0x0dc5('0x2d')](_0x4e743b[_0x0dc5('0x2a')][_0x0dc5('0x2d')]));_0x2977ef['attributes']=_0x2977ef['attributes']['length']?_0x2977ef[_0x0dc5('0x2e')]:_0x553b38[_0x0dc5('0x2c')];if(!_0x4e743b[_0x0dc5('0x2a')][_0x0dc5('0x2f')](_0x0dc5('0x30'))){_0x2977ef[_0x0dc5('0x19')]=qs['limit'](_0x4e743b[_0x0dc5('0x2a')][_0x0dc5('0x19')]);_0x2977ef['offset']=qs[_0x0dc5('0x18')](_0x4e743b[_0x0dc5('0x2a')]['offset']);}_0x2977ef['order']=qs['sort'](_0x4e743b['query']['sort']);_0x2977ef[_0x0dc5('0x31')]=qs['filters'](_['pick'](_0x4e743b['query'],_0x553b38['filters']),_0x4746b8);if(_0x4e743b['query'][_0x0dc5('0x32')]){_0x2977ef['where']=_[_0x0dc5('0x33')](_0x2977ef['where'],{'$or':_[_0x0dc5('0x24')](_0x4746b8,function(_0x323d2d){if(_0x323d2d[_0x0dc5('0x27')]!==_0x0dc5('0x34')){var _0x36bf0c={};_0x36bf0c[_0x323d2d[_0x0dc5('0x23')]]={'$like':'%'+_0x4e743b[_0x0dc5('0x2a')][_0x0dc5('0x32')]+'%'};return _0x36bf0c;}})});}_0x2977ef=_[_0x0dc5('0x33')]({},_0x2977ef,_0x4e743b[_0x0dc5('0x35')]);var _0x12554c={'where':_0x2977ef[_0x0dc5('0x31')]};return db[_0x0dc5('0x36')][_0x0dc5('0x37')](_0x12554c)[_0x0dc5('0x1f')](function(_0x288f3c){_0x2d1fd5[_0x0dc5('0x37')]=_0x288f3c;if(_0x4e743b[_0x0dc5('0x2a')]['includeAll']){_0x2977ef[_0x0dc5('0x38')]=[{'all':!![]}];}return db[_0x0dc5('0x36')][_0x0dc5('0x39')](_0x2977ef);})[_0x0dc5('0x1f')](function(_0x53f9a3){_0x2d1fd5['rows']=_0x53f9a3;return _0x2d1fd5;})['then'](respondWithFilteredResult(_0x12eb4b,_0x2977ef))['catch'](handleError(_0x12eb4b,null));};exports[_0x0dc5('0x3a')]=function(_0x2b0788,_0x45f7a9){var _0x2f2788={'raw':!![],'where':{'id':_0x2b0788[_0x0dc5('0x3b')]['id']}},_0x5debd6={};_0x5debd6['model']=_['keys'](db[_0x0dc5('0x36')][_0x0dc5('0x25')]);_0x5debd6[_0x0dc5('0x2a')]=_[_0x0dc5('0x29')](_0x2b0788[_0x0dc5('0x2a')]);_0x5debd6['filters']=_[_0x0dc5('0x2b')](_0x5debd6[_0x0dc5('0x2c')],_0x5debd6[_0x0dc5('0x2a')]);_0x2f2788[_0x0dc5('0x2e')]=_[_0x0dc5('0x2b')](_0x5debd6['model'],qs[_0x0dc5('0x2d')](_0x2b0788[_0x0dc5('0x2a')][_0x0dc5('0x2d')]));_0x2f2788['attributes']=_0x2f2788[_0x0dc5('0x2e')][_0x0dc5('0x3c')]?_0x2f2788[_0x0dc5('0x2e')]:_0x5debd6[_0x0dc5('0x2c')];if(_0x2b0788['query'][_0x0dc5('0x3d')]){_0x2f2788[_0x0dc5('0x38')]=[{'all':!![]}];}_0x2f2788=_[_0x0dc5('0x33')]({},_0x2f2788,_0x2b0788[_0x0dc5('0x35')]);return db[_0x0dc5('0x36')]['find'](_0x2f2788)['then'](handleEntityNotFound(_0x45f7a9,null))[_0x0dc5('0x1f')](respondWithResult(_0x45f7a9,null))['catch'](handleError(_0x45f7a9,null));};exports[_0x0dc5('0x3e')]=function(_0x2f54a6,_0x3c6bb3){return db[_0x0dc5('0x36')][_0x0dc5('0x3e')](_0x2f54a6['body'],{})[_0x0dc5('0x1f')](respondWithResult(_0x3c6bb3,0xc9))['catch'](handleError(_0x3c6bb3,null));};exports['update']=function(_0x15fd17,_0x15bd6e){if(_0x15fd17[_0x0dc5('0x3f')]['id']){delete _0x15fd17[_0x0dc5('0x3f')]['id'];}return db[_0x0dc5('0x36')][_0x0dc5('0x40')]({'where':{'id':_0x15fd17[_0x0dc5('0x3b')]['id']}})['then'](handleEntityNotFound(_0x15bd6e,null))['then'](saveUpdates(_0x15fd17[_0x0dc5('0x3f')],null))[_0x0dc5('0x1f')](respondWithResult(_0x15bd6e,null))[_0x0dc5('0x41')](handleError(_0x15bd6e,null));};exports[_0x0dc5('0x20')]=function(_0x215f82,_0x4fb55a){return db[_0x0dc5('0x36')]['find']({'where':{'id':_0x215f82[_0x0dc5('0x3b')]['id']}})[_0x0dc5('0x1f')](handleEntityNotFound(_0x4fb55a,null))['then'](removeEntity(_0x4fb55a,null))[_0x0dc5('0x41')](handleError(_0x4fb55a,null));};exports[_0x0dc5('0x42')]=function(_0x21a868,_0x3a9d6b){return db[_0x0dc5('0x36')][_0x0dc5('0x42')]()[_0x0dc5('0x1f')](respondWithResult(_0x3a9d6b,null))[_0x0dc5('0x41')](handleError(_0x3a9d6b,null));};