4e2ce5a48e5d57bd8ab0543eb248030038e2cb6b
[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 _0xb06b=['describe','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','reject','update','destroy','then','error','stack','name','send','index','JscriptyQuestionReport','rawAttributes','fieldName','key','model','map','query','keys','intersection','attributes','fields','length','hasOwnProperty','sort','where','filters','pick','filter','merge','type','options','includeAll','include','findAll','rows','catch','params','find','create','body'];(function(_0x23f438,_0x1b2a91){var _0x10611c=function(_0x5cfa6c){while(--_0x5cfa6c){_0x23f438['push'](_0x23f438['shift']());}};_0x10611c(++_0x1b2a91);}(_0xb06b,0xdf));var _0xbb06=function(_0x37dbc2,_0xb46c96){_0x37dbc2=_0x37dbc2-0x0;var _0x20df72=_0xb06b[_0x37dbc2];return _0x20df72;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbb06('0x0'));var zipdir=require(_0xbb06('0x1'));var jsonpatch=require(_0xbb06('0x2'));var rp=require(_0xbb06('0x3'));var moment=require('moment');var BPromise=require(_0xbb06('0x4'));var Mustache=require(_0xbb06('0x5'));var util=require('util');var path=require(_0xbb06('0x6'));var sox=require(_0xbb06('0x7'));var csv=require(_0xbb06('0x8'));var ejs=require(_0xbb06('0x9'));var fs=require('fs');var fs_extra=require(_0xbb06('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xbb06('0xb'));var jsforce=require(_0xbb06('0xc'));var deskjs=require(_0xbb06('0xd'));var toCsv=require(_0xbb06('0x8'));var querystring=require(_0xbb06('0xe'));var Papa=require(_0xbb06('0xf'));var Redis=require(_0xbb06('0x10'));var authService=require(_0xbb06('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xbb06('0x12'));var hardwareService=require(_0xbb06('0x13'));var logger=require(_0xbb06('0x14'))(_0xbb06('0x15'));var utils=require(_0xbb06('0x16'));var config=require(_0xbb06('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xbb06('0x18'))['db'];function respondWithStatusCode(_0x266429,_0x4bdad8){_0x4bdad8=_0x4bdad8||0xcc;return function(_0x2d07dc){if(_0x2d07dc){return _0x266429[_0xbb06('0x19')](_0x4bdad8);}return _0x266429[_0xbb06('0x1a')](_0x4bdad8)[_0xbb06('0x1b')]();};}function respondWithResult(_0x3637dc,_0x544212){_0x544212=_0x544212||0xc8;return function(_0x5c4549){if(_0x5c4549){return _0x3637dc[_0xbb06('0x1a')](_0x544212)[_0xbb06('0x1c')](_0x5c4549);}};}function respondWithFilteredResult(_0x10cf5f,_0x290c01){return function(_0x2b8ba4){if(_0x2b8ba4){var _0x3ed383=typeof _0x290c01['offset']===_0xbb06('0x1d')&&typeof _0x290c01[_0xbb06('0x1e')]===_0xbb06('0x1d');var _0x4e7f20=_0x2b8ba4[_0xbb06('0x1f')];var _0x154f04=_0x3ed383?0x0:_0x290c01[_0xbb06('0x20')];var _0x57af99=_0x3ed383?_0x2b8ba4[_0xbb06('0x1f')]:_0x290c01[_0xbb06('0x20')]+_0x290c01['limit'];var _0x89d494;if(_0x57af99>=_0x4e7f20){_0x57af99=_0x4e7f20;_0x89d494=0xc8;}else{_0x89d494=0xce;}_0x10cf5f['status'](_0x89d494);return _0x10cf5f['set'](_0xbb06('0x21'),_0x154f04+'-'+_0x57af99+'/'+_0x4e7f20)[_0xbb06('0x1c')](_0x2b8ba4);}return null;};}function patchUpdates(_0x252355){return function(_0x3c4886){try{jsonpatch['apply'](_0x3c4886,_0x252355,!![]);}catch(_0xeb8bcf){return BPromise[_0xbb06('0x22')](_0xeb8bcf);}return _0x3c4886['save']();};}function saveUpdates(_0x11f55a,_0x2f4970){return function(_0x2bc230){if(_0x2bc230){return _0x2bc230[_0xbb06('0x23')](_0x11f55a)['then'](function(_0x52b134){return _0x52b134;});}return null;};}function removeEntity(_0x4f5044,_0x565a15){return function(_0x518dc2){if(_0x518dc2){return _0x518dc2[_0xbb06('0x24')]()[_0xbb06('0x25')](function(){_0x4f5044[_0xbb06('0x1a')](0xcc)[_0xbb06('0x1b')]();});}};}function handleEntityNotFound(_0xc5eba,_0x4c7268){return function(_0x46f463){if(!_0x46f463){_0xc5eba[_0xbb06('0x19')](0x194);}return _0x46f463;};}function handleError(_0x3c81fb,_0x1cb995){_0x1cb995=_0x1cb995||0x1f4;return function(_0x398e54){logger[_0xbb06('0x26')](_0x398e54[_0xbb06('0x27')]);if(_0x398e54[_0xbb06('0x28')]){delete _0x398e54[_0xbb06('0x28')];}_0x3c81fb[_0xbb06('0x1a')](_0x1cb995)[_0xbb06('0x29')](_0x398e54);};}exports[_0xbb06('0x2a')]=function(_0x13137f,_0x187110){var _0xdad5f7={},_0x5ac8ac={},_0x426011={'count':0x0,'rows':[]};var _0x3023df=_['map'](db[_0xbb06('0x2b')][_0xbb06('0x2c')],function(_0x1390d8){return{'name':_0x1390d8[_0xbb06('0x2d')],'type':_0x1390d8['type'][_0xbb06('0x2e')]};});_0x5ac8ac[_0xbb06('0x2f')]=_[_0xbb06('0x30')](_0x3023df,_0xbb06('0x28'));_0x5ac8ac[_0xbb06('0x31')]=_[_0xbb06('0x32')](_0x13137f[_0xbb06('0x31')]);_0x5ac8ac['filters']=_[_0xbb06('0x33')](_0x5ac8ac['model'],_0x5ac8ac[_0xbb06('0x31')]);_0xdad5f7[_0xbb06('0x34')]=_[_0xbb06('0x33')](_0x5ac8ac[_0xbb06('0x2f')],qs[_0xbb06('0x35')](_0x13137f['query'][_0xbb06('0x35')]));_0xdad5f7['attributes']=_0xdad5f7['attributes'][_0xbb06('0x36')]?_0xdad5f7[_0xbb06('0x34')]:_0x5ac8ac[_0xbb06('0x2f')];if(!_0x13137f[_0xbb06('0x31')][_0xbb06('0x37')]('nolimit')){_0xdad5f7[_0xbb06('0x1e')]=qs[_0xbb06('0x1e')](_0x13137f[_0xbb06('0x31')]['limit']);_0xdad5f7[_0xbb06('0x20')]=qs[_0xbb06('0x20')](_0x13137f['query'][_0xbb06('0x20')]);}_0xdad5f7['order']=qs['sort'](_0x13137f[_0xbb06('0x31')][_0xbb06('0x38')]);_0xdad5f7[_0xbb06('0x39')]=qs[_0xbb06('0x3a')](_[_0xbb06('0x3b')](_0x13137f[_0xbb06('0x31')],_0x5ac8ac[_0xbb06('0x3a')]),_0x3023df);if(_0x13137f[_0xbb06('0x31')][_0xbb06('0x3c')]){_0xdad5f7[_0xbb06('0x39')]=_[_0xbb06('0x3d')](_0xdad5f7[_0xbb06('0x39')],{'$or':_[_0xbb06('0x30')](_0x3023df,function(_0x3e058d){if(_0x3e058d[_0xbb06('0x3e')]!=='VIRTUAL'){var _0x108b80={};_0x108b80[_0x3e058d[_0xbb06('0x28')]]={'$like':'%'+_0x13137f[_0xbb06('0x31')][_0xbb06('0x3c')]+'%'};return _0x108b80;}})});}_0xdad5f7=_['merge']({},_0xdad5f7,_0x13137f[_0xbb06('0x3f')]);var _0x98ab5f={'where':_0xdad5f7[_0xbb06('0x39')]};return db[_0xbb06('0x2b')][_0xbb06('0x1f')](_0x98ab5f)['then'](function(_0x5b785f){_0x426011[_0xbb06('0x1f')]=_0x5b785f;if(_0x13137f[_0xbb06('0x31')][_0xbb06('0x40')]){_0xdad5f7[_0xbb06('0x41')]=[{'all':!![]}];}return db[_0xbb06('0x2b')][_0xbb06('0x42')](_0xdad5f7);})['then'](function(_0x1dde5d){_0x426011[_0xbb06('0x43')]=_0x1dde5d;return _0x426011;})['then'](respondWithFilteredResult(_0x187110,_0xdad5f7))[_0xbb06('0x44')](handleError(_0x187110,null));};exports['show']=function(_0x3e7802,_0xbc2323){var _0x3d0108={'raw':!![],'where':{'id':_0x3e7802[_0xbb06('0x45')]['id']}},_0x49eeb1={};_0x49eeb1[_0xbb06('0x2f')]=_['keys'](db[_0xbb06('0x2b')][_0xbb06('0x2c')]);_0x49eeb1[_0xbb06('0x31')]=_[_0xbb06('0x32')](_0x3e7802[_0xbb06('0x31')]);_0x49eeb1[_0xbb06('0x3a')]=_['intersection'](_0x49eeb1[_0xbb06('0x2f')],_0x49eeb1[_0xbb06('0x31')]);_0x3d0108['attributes']=_[_0xbb06('0x33')](_0x49eeb1[_0xbb06('0x2f')],qs[_0xbb06('0x35')](_0x3e7802[_0xbb06('0x31')][_0xbb06('0x35')]));_0x3d0108[_0xbb06('0x34')]=_0x3d0108[_0xbb06('0x34')]['length']?_0x3d0108[_0xbb06('0x34')]:_0x49eeb1[_0xbb06('0x2f')];if(_0x3e7802[_0xbb06('0x31')][_0xbb06('0x40')]){_0x3d0108[_0xbb06('0x41')]=[{'all':!![]}];}_0x3d0108=_['merge']({},_0x3d0108,_0x3e7802['options']);return db[_0xbb06('0x2b')][_0xbb06('0x46')](_0x3d0108)[_0xbb06('0x25')](handleEntityNotFound(_0xbc2323,null))[_0xbb06('0x25')](respondWithResult(_0xbc2323,null))['catch'](handleError(_0xbc2323,null));};exports[_0xbb06('0x47')]=function(_0x31878e,_0x101971){return db[_0xbb06('0x2b')]['create'](_0x31878e[_0xbb06('0x48')],{})[_0xbb06('0x25')](respondWithResult(_0x101971,0xc9))[_0xbb06('0x44')](handleError(_0x101971,null));};exports[_0xbb06('0x23')]=function(_0xc8f984,_0x525508){if(_0xc8f984[_0xbb06('0x48')]['id']){delete _0xc8f984[_0xbb06('0x48')]['id'];}return db[_0xbb06('0x2b')]['find']({'where':{'id':_0xc8f984[_0xbb06('0x45')]['id']}})[_0xbb06('0x25')](handleEntityNotFound(_0x525508,null))[_0xbb06('0x25')](saveUpdates(_0xc8f984[_0xbb06('0x48')],null))['then'](respondWithResult(_0x525508,null))[_0xbb06('0x44')](handleError(_0x525508,null));};exports['destroy']=function(_0x540834,_0x165ff2){return db[_0xbb06('0x2b')][_0xbb06('0x46')]({'where':{'id':_0x540834['params']['id']}})[_0xbb06('0x25')](handleEntityNotFound(_0x165ff2,null))[_0xbb06('0x25')](removeEntity(_0x165ff2,null))['catch'](handleError(_0x165ff2,null));};exports[_0xbb06('0x49')]=function(_0x4383ca,_0x263b84){return db[_0xbb06('0x2b')][_0xbb06('0x49')]()['then'](respondWithResult(_0x263b84,null))[_0xbb06('0x44')](handleError(_0x263b84,null));};