Built motion from commit c116dc8b.|2.6.30
[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 _0xc57b=['VIRTUAL','options','count','include','findAll','rows','catch','params','includeAll','find','create','body','describe','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','json','offset','undefined','limit','set','Content-Range','apply','save','update','then','destroy','end','error','stack','name','send','JscriptyQuestionReport','rawAttributes','type','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge'];(function(_0x449978,_0x33e040){var _0xa232d4=function(_0x2fb84b){while(--_0x2fb84b){_0x449978['push'](_0x449978['shift']());}};_0xa232d4(++_0x33e040);}(_0xc57b,0xe2));var _0xbc57=function(_0x1ded20,_0x53af75){_0x1ded20=_0x1ded20-0x0;var _0x1ab760=_0xc57b[_0x1ded20];return _0x1ab760;};'use strict';var emlformat=require(_0xbc57('0x0'));var rimraf=require(_0xbc57('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbc57('0x2'));var rp=require(_0xbc57('0x3'));var moment=require('moment');var BPromise=require(_0xbc57('0x4'));var Mustache=require(_0xbc57('0x5'));var util=require(_0xbc57('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xbc57('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xbc57('0x8'));var squel=require(_0xbc57('0x9'));var crypto=require(_0xbc57('0xa'));var jsforce=require(_0xbc57('0xb'));var deskjs=require(_0xbc57('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xbc57('0xd'));var Redis=require('ioredis');var authService=require(_0xbc57('0xe'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbc57('0xf'));var logger=require(_0xbc57('0x10'))(_0xbc57('0x11'));var utils=require(_0xbc57('0x12'));var config=require(_0xbc57('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x429dc2,_0x5ef2db){_0x5ef2db=_0x5ef2db||0xcc;return function(_0x1b1776){if(_0x1b1776){return _0x429dc2[_0xbc57('0x14')](_0x5ef2db);}return _0x429dc2[_0xbc57('0x15')](_0x5ef2db)['end']();};}function respondWithResult(_0x26bfb8,_0x530cb5){_0x530cb5=_0x530cb5||0xc8;return function(_0x198ce3){if(_0x198ce3){return _0x26bfb8[_0xbc57('0x15')](_0x530cb5)[_0xbc57('0x16')](_0x198ce3);}};}function respondWithFilteredResult(_0x3f4c30,_0x58a5ee){return function(_0x15dfc9){if(_0x15dfc9){var _0x5b47cd=typeof _0x58a5ee[_0xbc57('0x17')]===_0xbc57('0x18')&&typeof _0x58a5ee[_0xbc57('0x19')]==='undefined';var _0x8afa45=_0x15dfc9['count'];var _0x2a3c50=_0x5b47cd?0x0:_0x58a5ee[_0xbc57('0x17')];var _0x50fa17=_0x5b47cd?_0x15dfc9['count']:_0x58a5ee['offset']+_0x58a5ee[_0xbc57('0x19')];var _0x298330;if(_0x50fa17>=_0x8afa45){_0x50fa17=_0x8afa45;_0x298330=0xc8;}else{_0x298330=0xce;}_0x3f4c30['status'](_0x298330);return _0x3f4c30[_0xbc57('0x1a')](_0xbc57('0x1b'),_0x2a3c50+'-'+_0x50fa17+'/'+_0x8afa45)[_0xbc57('0x16')](_0x15dfc9);}return null;};}function patchUpdates(_0x265837){return function(_0x452b81){try{jsonpatch[_0xbc57('0x1c')](_0x452b81,_0x265837,!![]);}catch(_0x17c03a){return BPromise['reject'](_0x17c03a);}return _0x452b81[_0xbc57('0x1d')]();};}function saveUpdates(_0x37c764,_0x771064){return function(_0x47d91d){if(_0x47d91d){return _0x47d91d[_0xbc57('0x1e')](_0x37c764)[_0xbc57('0x1f')](function(_0x37e3e2){return _0x37e3e2;});}return null;};}function removeEntity(_0x2559c8,_0x35b3b5){return function(_0x23a7dd){if(_0x23a7dd){return _0x23a7dd[_0xbc57('0x20')]()[_0xbc57('0x1f')](function(){_0x2559c8[_0xbc57('0x15')](0xcc)[_0xbc57('0x21')]();});}};}function handleEntityNotFound(_0x1e82ef,_0x2c9c94){return function(_0x397efd){if(!_0x397efd){_0x1e82ef[_0xbc57('0x14')](0x194);}return _0x397efd;};}function handleError(_0x1a4815,_0x511219){_0x511219=_0x511219||0x1f4;return function(_0x671cc6){logger[_0xbc57('0x22')](_0x671cc6[_0xbc57('0x23')]);if(_0x671cc6[_0xbc57('0x24')]){delete _0x671cc6['name'];}_0x1a4815[_0xbc57('0x15')](_0x511219)[_0xbc57('0x25')](_0x671cc6);};}exports['index']=function(_0x471e3b,_0x336d09){var _0x5674a2={},_0x42f385={},_0x15dd5a={'count':0x0,'rows':[]};var _0x5e4dab=_['map'](db[_0xbc57('0x26')][_0xbc57('0x27')],function(_0x34a30b){return{'name':_0x34a30b['fieldName'],'type':_0x34a30b[_0xbc57('0x28')]['key']};});_0x42f385[_0xbc57('0x29')]=_[_0xbc57('0x2a')](_0x5e4dab,_0xbc57('0x24'));_0x42f385[_0xbc57('0x2b')]=_[_0xbc57('0x2c')](_0x471e3b[_0xbc57('0x2b')]);_0x42f385[_0xbc57('0x2d')]=_['intersection'](_0x42f385[_0xbc57('0x29')],_0x42f385['query']);_0x5674a2[_0xbc57('0x2e')]=_[_0xbc57('0x2f')](_0x42f385[_0xbc57('0x29')],qs[_0xbc57('0x30')](_0x471e3b[_0xbc57('0x2b')][_0xbc57('0x30')]));_0x5674a2[_0xbc57('0x2e')]=_0x5674a2[_0xbc57('0x2e')][_0xbc57('0x31')]?_0x5674a2[_0xbc57('0x2e')]:_0x42f385[_0xbc57('0x29')];if(!_0x471e3b['query'][_0xbc57('0x32')](_0xbc57('0x33'))){_0x5674a2[_0xbc57('0x19')]=qs[_0xbc57('0x19')](_0x471e3b['query'][_0xbc57('0x19')]);_0x5674a2['offset']=qs['offset'](_0x471e3b[_0xbc57('0x2b')][_0xbc57('0x17')]);}_0x5674a2[_0xbc57('0x34')]=qs[_0xbc57('0x35')](_0x471e3b[_0xbc57('0x2b')][_0xbc57('0x35')]);_0x5674a2[_0xbc57('0x36')]=qs[_0xbc57('0x2d')](_[_0xbc57('0x37')](_0x471e3b[_0xbc57('0x2b')],_0x42f385[_0xbc57('0x2d')]),_0x5e4dab);if(_0x471e3b[_0xbc57('0x2b')][_0xbc57('0x38')]){_0x5674a2['where']=_[_0xbc57('0x39')](_0x5674a2['where'],{'$or':_[_0xbc57('0x2a')](_0x5e4dab,function(_0x28bf76){if(_0x28bf76[_0xbc57('0x28')]!==_0xbc57('0x3a')){var _0x312ce4={};_0x312ce4[_0x28bf76[_0xbc57('0x24')]]={'$like':'%'+_0x471e3b[_0xbc57('0x2b')]['filter']+'%'};return _0x312ce4;}})});}_0x5674a2=_['merge']({},_0x5674a2,_0x471e3b[_0xbc57('0x3b')]);var _0x22dfb1={'where':_0x5674a2['where']};return db[_0xbc57('0x26')][_0xbc57('0x3c')](_0x22dfb1)[_0xbc57('0x1f')](function(_0x5b6e56){_0x15dd5a[_0xbc57('0x3c')]=_0x5b6e56;if(_0x471e3b[_0xbc57('0x2b')]['includeAll']){_0x5674a2[_0xbc57('0x3d')]=[{'all':!![]}];}return db[_0xbc57('0x26')][_0xbc57('0x3e')](_0x5674a2);})[_0xbc57('0x1f')](function(_0x4ce7bc){_0x15dd5a[_0xbc57('0x3f')]=_0x4ce7bc;return _0x15dd5a;})[_0xbc57('0x1f')](respondWithFilteredResult(_0x336d09,_0x5674a2))[_0xbc57('0x40')](handleError(_0x336d09,null));};exports['show']=function(_0x1c6529,_0x379648){var _0x2e8a18={'raw':!![],'where':{'id':_0x1c6529[_0xbc57('0x41')]['id']}},_0x1a381b={};_0x1a381b[_0xbc57('0x29')]=_[_0xbc57('0x2c')](db[_0xbc57('0x26')][_0xbc57('0x27')]);_0x1a381b[_0xbc57('0x2b')]=_['keys'](_0x1c6529[_0xbc57('0x2b')]);_0x1a381b[_0xbc57('0x2d')]=_[_0xbc57('0x2f')](_0x1a381b[_0xbc57('0x29')],_0x1a381b[_0xbc57('0x2b')]);_0x2e8a18[_0xbc57('0x2e')]=_[_0xbc57('0x2f')](_0x1a381b[_0xbc57('0x29')],qs['fields'](_0x1c6529[_0xbc57('0x2b')][_0xbc57('0x30')]));_0x2e8a18[_0xbc57('0x2e')]=_0x2e8a18[_0xbc57('0x2e')][_0xbc57('0x31')]?_0x2e8a18[_0xbc57('0x2e')]:_0x1a381b['model'];if(_0x1c6529['query'][_0xbc57('0x42')]){_0x2e8a18[_0xbc57('0x3d')]=[{'all':!![]}];}_0x2e8a18=_[_0xbc57('0x39')]({},_0x2e8a18,_0x1c6529[_0xbc57('0x3b')]);return db[_0xbc57('0x26')][_0xbc57('0x43')](_0x2e8a18)['then'](handleEntityNotFound(_0x379648,null))[_0xbc57('0x1f')](respondWithResult(_0x379648,null))['catch'](handleError(_0x379648,null));};exports[_0xbc57('0x44')]=function(_0x566ea9,_0x1ce77c){return db['JscriptyQuestionReport'][_0xbc57('0x44')](_0x566ea9['body'],{})[_0xbc57('0x1f')](respondWithResult(_0x1ce77c,0xc9))['catch'](handleError(_0x1ce77c,null));};exports[_0xbc57('0x1e')]=function(_0x9b2391,_0x96a767){if(_0x9b2391[_0xbc57('0x45')]['id']){delete _0x9b2391[_0xbc57('0x45')]['id'];}return db[_0xbc57('0x26')][_0xbc57('0x43')]({'where':{'id':_0x9b2391[_0xbc57('0x41')]['id']}})[_0xbc57('0x1f')](handleEntityNotFound(_0x96a767,null))[_0xbc57('0x1f')](saveUpdates(_0x9b2391['body'],null))['then'](respondWithResult(_0x96a767,null))[_0xbc57('0x40')](handleError(_0x96a767,null));};exports[_0xbc57('0x20')]=function(_0x384bc4,_0x4a98dc){return db[_0xbc57('0x26')][_0xbc57('0x43')]({'where':{'id':_0x384bc4['params']['id']}})['then'](handleEntityNotFound(_0x4a98dc,null))[_0xbc57('0x1f')](removeEntity(_0x4a98dc,null))[_0xbc57('0x40')](handleError(_0x4a98dc,null));};exports[_0xbc57('0x46')]=function(_0x2de597,_0x55a4b8){return db[_0xbc57('0x26')][_0xbc57('0x46')]()['then'](respondWithResult(_0x55a4b8,null))['catch'](handleError(_0x55a4b8,null));};