Built motion from commit (unavailable).|2.5.10
[motion2.git] / server / api / jscriptyQuestionReport / jscriptyQuestionReport.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 _0x9cbe=['limit','set','Content-Range','json','apply','reject','save','update','then','destroy','end','error','stack','name','send','map','JscriptyQuestionReport','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','filter','where','merge','VIRTUAL','options','count','include','findAll','rows','catch','show','params','includeAll','find','create','body','describe','html-pdf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','lodash','crypto','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset'];(function(_0x4f01f6,_0x169ed2){var _0x2dbb8e=function(_0x2f6ac2){while(--_0x2f6ac2){_0x4f01f6['push'](_0x4f01f6['shift']());}};_0x2dbb8e(++_0x169ed2);}(_0x9cbe,0x154));var _0xe9cb=function(_0x62c958,_0x2bfdbc){_0x62c958=_0x62c958-0x0;var _0x57ec61=_0x9cbe[_0x62c958];return _0x57ec61;};'use strict';var pdf=require(_0xe9cb('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xe9cb('0x1'));var jsonpatch=require(_0xe9cb('0x2'));var rp=require('request-promise');var moment=require(_0xe9cb('0x3'));var BPromise=require(_0xe9cb('0x4'));var Mustache=require('mustache');var util=require(_0xe9cb('0x5'));var path=require(_0xe9cb('0x6'));var sox=require(_0xe9cb('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xe9cb('0x8'));var squel=require('squel');var crypto=require(_0xe9cb('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xe9cb('0xa'));var querystring=require(_0xe9cb('0xb'));var Papa=require('papaparse');var Redis=require(_0xe9cb('0xc'));var authService=require(_0xe9cb('0xd'));var qs=require(_0xe9cb('0xe'));var as=require(_0xe9cb('0xf'));var hardwareService=require(_0xe9cb('0x10'));var logger=require(_0xe9cb('0x11'))(_0xe9cb('0x12'));var utils=require('../../config/utils');var config=require(_0xe9cb('0x13'));var licenseUtil=require(_0xe9cb('0x14'));var db=require(_0xe9cb('0x15'))['db'];function respondWithStatusCode(_0x28b79d,_0xce6160){_0xce6160=_0xce6160||0xcc;return function(_0x1ebf2f){if(_0x1ebf2f){return _0x28b79d[_0xe9cb('0x16')](_0xce6160);}return _0x28b79d[_0xe9cb('0x17')](_0xce6160)['end']();};}function respondWithResult(_0xa8db2e,_0x6fd309){_0x6fd309=_0x6fd309||0xc8;return function(_0x42b059){if(_0x42b059){return _0xa8db2e[_0xe9cb('0x17')](_0x6fd309)['json'](_0x42b059);}};}function respondWithFilteredResult(_0x59b50a,_0x233913){return function(_0x4e3c55){if(_0x4e3c55){var _0x592c11=_0x4e3c55['count'],_0x2272e6=_0x233913[_0xe9cb('0x18')],_0x3985df=_0x233913['offset']+_0x233913[_0xe9cb('0x19')],_0xa91593;if(_0x3985df>=_0x592c11){_0x3985df=_0x592c11;_0xa91593=0xc8;}else{_0xa91593=0xce;}_0x59b50a['status'](_0xa91593);return _0x59b50a[_0xe9cb('0x1a')](_0xe9cb('0x1b'),_0x2272e6+'-'+_0x3985df+'/'+_0x592c11)[_0xe9cb('0x1c')](_0x4e3c55);}return null;};}function patchUpdates(_0x13a023){return function(_0x19c4da){try{jsonpatch[_0xe9cb('0x1d')](_0x19c4da,_0x13a023,!![]);}catch(_0x5beb70){return BPromise[_0xe9cb('0x1e')](_0x5beb70);}return _0x19c4da[_0xe9cb('0x1f')]();};}function saveUpdates(_0x5b5a7c,_0xbb25d8){return function(_0x4cafeb){if(_0x4cafeb){return _0x4cafeb[_0xe9cb('0x20')](_0x5b5a7c)[_0xe9cb('0x21')](function(_0x15adab){return _0x15adab;});}return null;};}function removeEntity(_0x2796d6,_0x367056){return function(_0x111dfa){if(_0x111dfa){return _0x111dfa[_0xe9cb('0x22')]()[_0xe9cb('0x21')](function(){_0x2796d6[_0xe9cb('0x17')](0xcc)[_0xe9cb('0x23')]();});}};}function handleEntityNotFound(_0x8bb783,_0x59d309){return function(_0x3f643d){if(!_0x3f643d){_0x8bb783['sendStatus'](0x194);}return _0x3f643d;};}function handleError(_0x51a57a,_0x21b420){_0x21b420=_0x21b420||0x1f4;return function(_0x1d9fca){logger[_0xe9cb('0x24')](_0x1d9fca[_0xe9cb('0x25')]);if(_0x1d9fca[_0xe9cb('0x26')]){delete _0x1d9fca['name'];}_0x51a57a[_0xe9cb('0x17')](_0x21b420)[_0xe9cb('0x27')](_0x1d9fca);};}exports['index']=function(_0x571bce,_0x207165){var _0x4e1d67={},_0x1b1335={},_0x2f6cf5={'count':0x0,'rows':[]};var _0x3288c0=_[_0xe9cb('0x28')](db[_0xe9cb('0x29')][_0xe9cb('0x2a')],function(_0x484532){return{'name':_0x484532['fieldName'],'type':_0x484532[_0xe9cb('0x2b')][_0xe9cb('0x2c')]};});_0x1b1335[_0xe9cb('0x2d')]=_[_0xe9cb('0x28')](_0x3288c0,_0xe9cb('0x26'));_0x1b1335[_0xe9cb('0x2e')]=_[_0xe9cb('0x2f')](_0x571bce[_0xe9cb('0x2e')]);_0x1b1335[_0xe9cb('0x30')]=_[_0xe9cb('0x31')](_0x1b1335[_0xe9cb('0x2d')],_0x1b1335[_0xe9cb('0x2e')]);_0x4e1d67[_0xe9cb('0x32')]=_[_0xe9cb('0x31')](_0x1b1335[_0xe9cb('0x2d')],qs[_0xe9cb('0x33')](_0x571bce[_0xe9cb('0x2e')][_0xe9cb('0x33')]));_0x4e1d67[_0xe9cb('0x32')]=_0x4e1d67[_0xe9cb('0x32')][_0xe9cb('0x34')]?_0x4e1d67['attributes']:_0x1b1335[_0xe9cb('0x2d')];if(!_0x571bce[_0xe9cb('0x2e')]['hasOwnProperty'](_0xe9cb('0x35'))){_0x4e1d67[_0xe9cb('0x19')]=qs[_0xe9cb('0x19')](_0x571bce[_0xe9cb('0x2e')][_0xe9cb('0x19')]);_0x4e1d67[_0xe9cb('0x18')]=qs[_0xe9cb('0x18')](_0x571bce['query'][_0xe9cb('0x18')]);}_0x4e1d67[_0xe9cb('0x36')]=qs['sort'](_0x571bce[_0xe9cb('0x2e')][_0xe9cb('0x37')]);_0x4e1d67['where']=qs[_0xe9cb('0x30')](_['pick'](_0x571bce[_0xe9cb('0x2e')],_0x1b1335[_0xe9cb('0x30')]),_0x3288c0);if(_0x571bce[_0xe9cb('0x2e')][_0xe9cb('0x38')]){_0x4e1d67[_0xe9cb('0x39')]=_[_0xe9cb('0x3a')](_0x4e1d67['where'],{'$or':_[_0xe9cb('0x28')](_0x3288c0,function(_0x12359e){if(_0x12359e['type']!==_0xe9cb('0x3b')){var _0x247b3b={};_0x247b3b[_0x12359e[_0xe9cb('0x26')]]={'$like':'%'+_0x571bce['query'][_0xe9cb('0x38')]+'%'};return _0x247b3b;}})});}_0x4e1d67=_['merge']({},_0x4e1d67,_0x571bce[_0xe9cb('0x3c')]);var _0x5f106d={'where':_0x4e1d67[_0xe9cb('0x39')]};return db[_0xe9cb('0x29')][_0xe9cb('0x3d')](_0x5f106d)['then'](function(_0x28039e){_0x2f6cf5[_0xe9cb('0x3d')]=_0x28039e;if(_0x571bce[_0xe9cb('0x2e')]['includeAll']){_0x4e1d67[_0xe9cb('0x3e')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xe9cb('0x3f')](_0x4e1d67);})['then'](function(_0x550a80){_0x2f6cf5[_0xe9cb('0x40')]=_0x550a80;return _0x2f6cf5;})[_0xe9cb('0x21')](respondWithFilteredResult(_0x207165,_0x4e1d67))[_0xe9cb('0x41')](handleError(_0x207165,null));};exports[_0xe9cb('0x42')]=function(_0x6ecd78,_0x2844df){var _0x2c49fc={'raw':!![],'where':{'id':_0x6ecd78[_0xe9cb('0x43')]['id']}},_0x47212c={};_0x47212c[_0xe9cb('0x2d')]=_[_0xe9cb('0x2f')](db['JscriptyQuestionReport']['rawAttributes']);_0x47212c[_0xe9cb('0x2e')]=_[_0xe9cb('0x2f')](_0x6ecd78['query']);_0x47212c[_0xe9cb('0x30')]=_[_0xe9cb('0x31')](_0x47212c['model'],_0x47212c['query']);_0x2c49fc[_0xe9cb('0x32')]=_['intersection'](_0x47212c[_0xe9cb('0x2d')],qs[_0xe9cb('0x33')](_0x6ecd78[_0xe9cb('0x2e')][_0xe9cb('0x33')]));_0x2c49fc[_0xe9cb('0x32')]=_0x2c49fc[_0xe9cb('0x32')][_0xe9cb('0x34')]?_0x2c49fc[_0xe9cb('0x32')]:_0x47212c[_0xe9cb('0x2d')];if(_0x6ecd78['query'][_0xe9cb('0x44')]){_0x2c49fc[_0xe9cb('0x3e')]=[{'all':!![]}];}_0x2c49fc=_[_0xe9cb('0x3a')]({},_0x2c49fc,_0x6ecd78['options']);return db[_0xe9cb('0x29')][_0xe9cb('0x45')](_0x2c49fc)[_0xe9cb('0x21')](handleEntityNotFound(_0x2844df,null))[_0xe9cb('0x21')](respondWithResult(_0x2844df,null))['catch'](handleError(_0x2844df,null));};exports[_0xe9cb('0x46')]=function(_0x3f5544,_0x45dfe7){return db[_0xe9cb('0x29')][_0xe9cb('0x46')](_0x3f5544['body'],{})['then'](respondWithResult(_0x45dfe7,0xc9))['catch'](handleError(_0x45dfe7,null));};exports[_0xe9cb('0x20')]=function(_0x1c066f,_0x2b2e21){if(_0x1c066f[_0xe9cb('0x47')]['id']){delete _0x1c066f[_0xe9cb('0x47')]['id'];}return db[_0xe9cb('0x29')][_0xe9cb('0x45')]({'where':{'id':_0x1c066f[_0xe9cb('0x43')]['id']}})[_0xe9cb('0x21')](handleEntityNotFound(_0x2b2e21,null))[_0xe9cb('0x21')](saveUpdates(_0x1c066f[_0xe9cb('0x47')],null))[_0xe9cb('0x21')](respondWithResult(_0x2b2e21,null))[_0xe9cb('0x41')](handleError(_0x2b2e21,null));};exports['destroy']=function(_0x31a144,_0x1b8a82){return db[_0xe9cb('0x29')][_0xe9cb('0x45')]({'where':{'id':_0x31a144[_0xe9cb('0x43')]['id']}})['then'](handleEntityNotFound(_0x1b8a82,null))['then'](removeEntity(_0x1b8a82,null))[_0xe9cb('0x41')](handleError(_0x1b8a82,null));};exports[_0xe9cb('0x48')]=function(_0x455c59,_0x5c856d){return db[_0xe9cb('0x29')][_0xe9cb('0x48')]()[_0xe9cb('0x21')](respondWithResult(_0x5c856d,null))[_0xe9cb('0x41')](handleError(_0x5c856d,null));};