72fa752b77aa286df0fa3b2ecdccc58e86f883e0
[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 _0x6aee=['undefined','limit','count','Content-Range','apply','reject','update','then','error','stack','name','send','index','JscriptyQuestionReport','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','options','find','create','body','destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset'];(function(_0x48881f,_0x3b21de){var _0x2ae3a6=function(_0x32b35b){while(--_0x32b35b){_0x48881f['push'](_0x48881f['shift']());}};_0x2ae3a6(++_0x3b21de);}(_0x6aee,0x11b));var _0xe6ae=function(_0x59636e,_0x2670c1){_0x59636e=_0x59636e-0x0;var _0x53920e=_0x6aee[_0x59636e];return _0x53920e;};'use strict';var emlformat=require(_0xe6ae('0x0'));var rimraf=require(_0xe6ae('0x1'));var zipdir=require(_0xe6ae('0x2'));var jsonpatch=require(_0xe6ae('0x3'));var rp=require('request-promise');var moment=require(_0xe6ae('0x4'));var BPromise=require(_0xe6ae('0x5'));var Mustache=require(_0xe6ae('0x6'));var util=require(_0xe6ae('0x7'));var path=require(_0xe6ae('0x8'));var sox=require(_0xe6ae('0x9'));var csv=require(_0xe6ae('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xe6ae('0xb'));var _=require(_0xe6ae('0xc'));var squel=require(_0xe6ae('0xd'));var crypto=require('crypto');var jsforce=require(_0xe6ae('0xe'));var deskjs=require(_0xe6ae('0xf'));var toCsv=require('to-csv');var querystring=require(_0xe6ae('0x10'));var Papa=require(_0xe6ae('0x11'));var Redis=require(_0xe6ae('0x12'));var authService=require(_0xe6ae('0x13'));var qs=require(_0xe6ae('0x14'));var as=require(_0xe6ae('0x15'));var hardwareService=require(_0xe6ae('0x16'));var logger=require('../../config/logger')(_0xe6ae('0x17'));var utils=require(_0xe6ae('0x18'));var config=require(_0xe6ae('0x19'));var licenseUtil=require(_0xe6ae('0x1a'));var db=require(_0xe6ae('0x1b'))['db'];function respondWithStatusCode(_0x122494,_0x22201b){_0x22201b=_0x22201b||0xcc;return function(_0x256d77){if(_0x256d77){return _0x122494[_0xe6ae('0x1c')](_0x22201b);}return _0x122494['status'](_0x22201b)[_0xe6ae('0x1d')]();};}function respondWithResult(_0x4a3cb4,_0x30530a){_0x30530a=_0x30530a||0xc8;return function(_0x2fa05b){if(_0x2fa05b){return _0x4a3cb4[_0xe6ae('0x1e')](_0x30530a)[_0xe6ae('0x1f')](_0x2fa05b);}};}function respondWithFilteredResult(_0x5414d8,_0x33e6a3){return function(_0x153f8c){if(_0x153f8c){var _0x3b919b=typeof _0x33e6a3[_0xe6ae('0x20')]===_0xe6ae('0x21')&&typeof _0x33e6a3[_0xe6ae('0x22')]===_0xe6ae('0x21');var _0x4f7dcd=_0x153f8c[_0xe6ae('0x23')];var _0x56b4c9=_0x3b919b?0x0:_0x33e6a3[_0xe6ae('0x20')];var _0x2a44cc=_0x3b919b?_0x153f8c['count']:_0x33e6a3[_0xe6ae('0x20')]+_0x33e6a3[_0xe6ae('0x22')];var _0x437160;if(_0x2a44cc>=_0x4f7dcd){_0x2a44cc=_0x4f7dcd;_0x437160=0xc8;}else{_0x437160=0xce;}_0x5414d8[_0xe6ae('0x1e')](_0x437160);return _0x5414d8['set'](_0xe6ae('0x24'),_0x56b4c9+'-'+_0x2a44cc+'/'+_0x4f7dcd)[_0xe6ae('0x1f')](_0x153f8c);}return null;};}function patchUpdates(_0x51212b){return function(_0x537f1d){try{jsonpatch[_0xe6ae('0x25')](_0x537f1d,_0x51212b,!![]);}catch(_0x3a8d0c){return BPromise[_0xe6ae('0x26')](_0x3a8d0c);}return _0x537f1d['save']();};}function saveUpdates(_0x42cebb,_0x406ad8){return function(_0x3b1b08){if(_0x3b1b08){return _0x3b1b08[_0xe6ae('0x27')](_0x42cebb)['then'](function(_0x301f9a){return _0x301f9a;});}return null;};}function removeEntity(_0x55d0f9,_0x5dcb7b){return function(_0xa8723a){if(_0xa8723a){return _0xa8723a['destroy']()[_0xe6ae('0x28')](function(){_0x55d0f9[_0xe6ae('0x1e')](0xcc)[_0xe6ae('0x1d')]();});}};}function handleEntityNotFound(_0x596009,_0x4406d5){return function(_0x4253aa){if(!_0x4253aa){_0x596009['sendStatus'](0x194);}return _0x4253aa;};}function handleError(_0x41cb44,_0x3fda76){_0x3fda76=_0x3fda76||0x1f4;return function(_0x59666f){logger[_0xe6ae('0x29')](_0x59666f[_0xe6ae('0x2a')]);if(_0x59666f[_0xe6ae('0x2b')]){delete _0x59666f[_0xe6ae('0x2b')];}_0x41cb44[_0xe6ae('0x1e')](_0x3fda76)[_0xe6ae('0x2c')](_0x59666f);};}exports[_0xe6ae('0x2d')]=function(_0x2256e4,_0x4d0638){var _0x212dc1={},_0x570755={},_0x58638a={'count':0x0,'rows':[]};var _0x35dd90=_['map'](db[_0xe6ae('0x2e')][_0xe6ae('0x2f')],function(_0x1aef83){return{'name':_0x1aef83[_0xe6ae('0x30')],'type':_0x1aef83[_0xe6ae('0x31')][_0xe6ae('0x32')]};});_0x570755[_0xe6ae('0x33')]=_['map'](_0x35dd90,_0xe6ae('0x2b'));_0x570755['query']=_[_0xe6ae('0x34')](_0x2256e4[_0xe6ae('0x35')]);_0x570755[_0xe6ae('0x36')]=_[_0xe6ae('0x37')](_0x570755[_0xe6ae('0x33')],_0x570755[_0xe6ae('0x35')]);_0x212dc1[_0xe6ae('0x38')]=_[_0xe6ae('0x37')](_0x570755[_0xe6ae('0x33')],qs[_0xe6ae('0x39')](_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x39')]));_0x212dc1['attributes']=_0x212dc1[_0xe6ae('0x38')][_0xe6ae('0x3a')]?_0x212dc1['attributes']:_0x570755[_0xe6ae('0x33')];if(!_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x3b')](_0xe6ae('0x3c'))){_0x212dc1['limit']=qs[_0xe6ae('0x22')](_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x22')]);_0x212dc1[_0xe6ae('0x20')]=qs[_0xe6ae('0x20')](_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x20')]);}_0x212dc1['order']=qs[_0xe6ae('0x3d')](_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x3d')]);_0x212dc1[_0xe6ae('0x3e')]=qs['filters'](_['pick'](_0x2256e4[_0xe6ae('0x35')],_0x570755[_0xe6ae('0x36')]),_0x35dd90);if(_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x3f')]){_0x212dc1[_0xe6ae('0x3e')]=_[_0xe6ae('0x40')](_0x212dc1['where'],{'$or':_['map'](_0x35dd90,function(_0x7b1f36){if(_0x7b1f36[_0xe6ae('0x31')]!==_0xe6ae('0x41')){var _0x538130={};_0x538130[_0x7b1f36[_0xe6ae('0x2b')]]={'$like':'%'+_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x3f')]+'%'};return _0x538130;}})});}_0x212dc1=_['merge']({},_0x212dc1,_0x2256e4['options']);var _0x568abe={'where':_0x212dc1[_0xe6ae('0x3e')]};return db[_0xe6ae('0x2e')][_0xe6ae('0x23')](_0x568abe)[_0xe6ae('0x28')](function(_0x2a7b66){_0x58638a[_0xe6ae('0x23')]=_0x2a7b66;if(_0x2256e4[_0xe6ae('0x35')][_0xe6ae('0x42')]){_0x212dc1[_0xe6ae('0x43')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xe6ae('0x44')](_0x212dc1);})[_0xe6ae('0x28')](function(_0x31711e){_0x58638a[_0xe6ae('0x45')]=_0x31711e;return _0x58638a;})[_0xe6ae('0x28')](respondWithFilteredResult(_0x4d0638,_0x212dc1))[_0xe6ae('0x46')](handleError(_0x4d0638,null));};exports[_0xe6ae('0x47')]=function(_0x55f4c2,_0x3e050d){var _0x3449c2={'raw':!![],'where':{'id':_0x55f4c2[_0xe6ae('0x48')]['id']}},_0x5c940c={};_0x5c940c['model']=_[_0xe6ae('0x34')](db[_0xe6ae('0x2e')][_0xe6ae('0x2f')]);_0x5c940c[_0xe6ae('0x35')]=_['keys'](_0x55f4c2[_0xe6ae('0x35')]);_0x5c940c['filters']=_[_0xe6ae('0x37')](_0x5c940c['model'],_0x5c940c[_0xe6ae('0x35')]);_0x3449c2[_0xe6ae('0x38')]=_['intersection'](_0x5c940c[_0xe6ae('0x33')],qs[_0xe6ae('0x39')](_0x55f4c2['query'][_0xe6ae('0x39')]));_0x3449c2[_0xe6ae('0x38')]=_0x3449c2[_0xe6ae('0x38')][_0xe6ae('0x3a')]?_0x3449c2['attributes']:_0x5c940c[_0xe6ae('0x33')];if(_0x55f4c2['query']['includeAll']){_0x3449c2[_0xe6ae('0x43')]=[{'all':!![]}];}_0x3449c2=_[_0xe6ae('0x40')]({},_0x3449c2,_0x55f4c2[_0xe6ae('0x49')]);return db[_0xe6ae('0x2e')][_0xe6ae('0x4a')](_0x3449c2)['then'](handleEntityNotFound(_0x3e050d,null))[_0xe6ae('0x28')](respondWithResult(_0x3e050d,null))[_0xe6ae('0x46')](handleError(_0x3e050d,null));};exports['create']=function(_0x181415,_0x549cab){return db[_0xe6ae('0x2e')][_0xe6ae('0x4b')](_0x181415[_0xe6ae('0x4c')],{})[_0xe6ae('0x28')](respondWithResult(_0x549cab,0xc9))[_0xe6ae('0x46')](handleError(_0x549cab,null));};exports[_0xe6ae('0x27')]=function(_0x54bf5c,_0x575df8){if(_0x54bf5c[_0xe6ae('0x4c')]['id']){delete _0x54bf5c[_0xe6ae('0x4c')]['id'];}return db[_0xe6ae('0x2e')][_0xe6ae('0x4a')]({'where':{'id':_0x54bf5c[_0xe6ae('0x48')]['id']}})['then'](handleEntityNotFound(_0x575df8,null))['then'](saveUpdates(_0x54bf5c[_0xe6ae('0x4c')],null))[_0xe6ae('0x28')](respondWithResult(_0x575df8,null))['catch'](handleError(_0x575df8,null));};exports[_0xe6ae('0x4d')]=function(_0x522c8d,_0x273b52){return db[_0xe6ae('0x2e')][_0xe6ae('0x4a')]({'where':{'id':_0x522c8d[_0xe6ae('0x48')]['id']}})['then'](handleEntityNotFound(_0x273b52,null))['then'](removeEntity(_0x273b52,null))[_0xe6ae('0x46')](handleError(_0x273b52,null));};exports[_0xe6ae('0x4e')]=function(_0x288cba,_0x513ac7){return db[_0xe6ae('0x2e')]['describe']()[_0xe6ae('0x28')](respondWithResult(_0x513ac7,null))['catch'](handleError(_0x513ac7,null));};