Built motion from commit (unavailable).|2.5.19
[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 _0xfff6=['nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','JscriptyAnswerReport','includeAll','catch','show','params','include','find','create','body','describe','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','index','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','length'];(function(_0x52de9b,_0x19df61){var _0x1ad0c7=function(_0x26a38c){while(--_0x26a38c){_0x52de9b['push'](_0x52de9b['shift']());}};_0x1ad0c7(++_0x19df61);}(_0xfff6,0x185));var _0x6fff=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xfff6[_0x20a584];return _0x4b41a8;};'use strict';var pdf=require(_0x6fff('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x6fff('0x1'));var jsonpatch=require(_0x6fff('0x2'));var rp=require(_0x6fff('0x3'));var moment=require(_0x6fff('0x4'));var BPromise=require(_0x6fff('0x5'));var Mustache=require(_0x6fff('0x6'));var util=require(_0x6fff('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x6fff('0x8'));var ejs=require(_0x6fff('0x9'));var fs=require('fs');var _=require(_0x6fff('0xa'));var squel=require('squel');var crypto=require(_0x6fff('0xb'));var jsforce=require(_0x6fff('0xc'));var deskjs=require(_0x6fff('0xd'));var toCsv=require('to-csv');var querystring=require(_0x6fff('0xe'));var Papa=require(_0x6fff('0xf'));var Redis=require(_0x6fff('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x6fff('0x11'));var as=require(_0x6fff('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x6fff('0x13'))('api');var utils=require(_0x6fff('0x14'));var config=require(_0x6fff('0x15'));var licenseUtil=require(_0x6fff('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xbbc09,_0x34b05b){_0x34b05b=_0x34b05b||0xcc;return function(_0x3be773){if(_0x3be773){return _0xbbc09[_0x6fff('0x17')](_0x34b05b);}return _0xbbc09[_0x6fff('0x18')](_0x34b05b)[_0x6fff('0x19')]();};}function respondWithResult(_0x104fdc,_0x82df53){_0x82df53=_0x82df53||0xc8;return function(_0x2c5e37){if(_0x2c5e37){return _0x104fdc['status'](_0x82df53)[_0x6fff('0x1a')](_0x2c5e37);}};}function respondWithFilteredResult(_0x3edb2b,_0x4ab6ff){return function(_0x4160bb){if(_0x4160bb){var _0x4522a2=_0x4160bb[_0x6fff('0x1b')],_0x1ad915=_0x4ab6ff[_0x6fff('0x1c')],_0x5600c3=_0x4ab6ff['offset']+_0x4ab6ff[_0x6fff('0x1d')],_0x28b274;if(_0x5600c3>=_0x4522a2){_0x5600c3=_0x4522a2;_0x28b274=0xc8;}else{_0x28b274=0xce;}_0x3edb2b[_0x6fff('0x18')](_0x28b274);return _0x3edb2b[_0x6fff('0x1e')](_0x6fff('0x1f'),_0x1ad915+'-'+_0x5600c3+'/'+_0x4522a2)[_0x6fff('0x1a')](_0x4160bb);}return null;};}function patchUpdates(_0x45b3d6){return function(_0x544413){try{jsonpatch[_0x6fff('0x20')](_0x544413,_0x45b3d6,!![]);}catch(_0xf1a4dc){return BPromise[_0x6fff('0x21')](_0xf1a4dc);}return _0x544413[_0x6fff('0x22')]();};}function saveUpdates(_0x142d9d,_0x397bc8){return function(_0x46e2c8){if(_0x46e2c8){return _0x46e2c8[_0x6fff('0x23')](_0x142d9d)[_0x6fff('0x24')](function(_0x1daee6){return _0x1daee6;});}return null;};}function removeEntity(_0x291d59,_0x3a5c4b){return function(_0x583cb5){if(_0x583cb5){return _0x583cb5[_0x6fff('0x25')]()['then'](function(){_0x291d59[_0x6fff('0x18')](0xcc)[_0x6fff('0x19')]();});}};}function handleEntityNotFound(_0x423e07,_0x3b60da){return function(_0x4e4b51){if(!_0x4e4b51){_0x423e07[_0x6fff('0x17')](0x194);}return _0x4e4b51;};}function handleError(_0x16a3bf,_0x6be7a4){_0x6be7a4=_0x6be7a4||0x1f4;return function(_0x211ca9){logger[_0x6fff('0x26')](_0x211ca9[_0x6fff('0x27')]);if(_0x211ca9[_0x6fff('0x28')]){delete _0x211ca9[_0x6fff('0x28')];}_0x16a3bf[_0x6fff('0x18')](_0x6be7a4)['send'](_0x211ca9);};}exports[_0x6fff('0x29')]=function(_0x517cbb,_0x4ca537){var _0x49335b={},_0x13a04a={},_0x3caa12={'count':0x0,'rows':[]};var _0x4ee087=_['map'](db['JscriptyAnswerReport'][_0x6fff('0x2a')],function(_0x19f5ca){return{'name':_0x19f5ca[_0x6fff('0x2b')],'type':_0x19f5ca[_0x6fff('0x2c')][_0x6fff('0x2d')]};});_0x13a04a[_0x6fff('0x2e')]=_[_0x6fff('0x2f')](_0x4ee087,_0x6fff('0x28'));_0x13a04a[_0x6fff('0x30')]=_[_0x6fff('0x31')](_0x517cbb['query']);_0x13a04a[_0x6fff('0x32')]=_[_0x6fff('0x33')](_0x13a04a[_0x6fff('0x2e')],_0x13a04a[_0x6fff('0x30')]);_0x49335b['attributes']=_[_0x6fff('0x33')](_0x13a04a[_0x6fff('0x2e')],qs['fields'](_0x517cbb[_0x6fff('0x30')][_0x6fff('0x34')]));_0x49335b[_0x6fff('0x35')]=_0x49335b['attributes'][_0x6fff('0x36')]?_0x49335b['attributes']:_0x13a04a['model'];if(!_0x517cbb['query']['hasOwnProperty'](_0x6fff('0x37'))){_0x49335b['limit']=qs[_0x6fff('0x1d')](_0x517cbb[_0x6fff('0x30')][_0x6fff('0x1d')]);_0x49335b[_0x6fff('0x1c')]=qs[_0x6fff('0x1c')](_0x517cbb['query'][_0x6fff('0x1c')]);}_0x49335b[_0x6fff('0x38')]=qs[_0x6fff('0x39')](_0x517cbb[_0x6fff('0x30')][_0x6fff('0x39')]);_0x49335b[_0x6fff('0x3a')]=qs['filters'](_[_0x6fff('0x3b')](_0x517cbb[_0x6fff('0x30')],_0x13a04a[_0x6fff('0x32')]),_0x4ee087);if(_0x517cbb[_0x6fff('0x30')][_0x6fff('0x3c')]){_0x49335b[_0x6fff('0x3a')]=_[_0x6fff('0x3d')](_0x49335b['where'],{'$or':_[_0x6fff('0x2f')](_0x4ee087,function(_0x85cb13){if(_0x85cb13[_0x6fff('0x2c')]!==_0x6fff('0x3e')){var _0x2474ab={};_0x2474ab[_0x85cb13['name']]={'$like':'%'+_0x517cbb[_0x6fff('0x30')][_0x6fff('0x3c')]+'%'};return _0x2474ab;}})});}_0x49335b=_['merge']({},_0x49335b,_0x517cbb[_0x6fff('0x3f')]);var _0x102aa2={'where':_0x49335b[_0x6fff('0x3a')]};return db[_0x6fff('0x40')][_0x6fff('0x1b')](_0x102aa2)[_0x6fff('0x24')](function(_0x5de9dc){_0x3caa12[_0x6fff('0x1b')]=_0x5de9dc;if(_0x517cbb[_0x6fff('0x30')][_0x6fff('0x41')]){_0x49335b['include']=[{'all':!![]}];}return db['JscriptyAnswerReport']['findAll'](_0x49335b);})['then'](function(_0x592f69){_0x3caa12['rows']=_0x592f69;return _0x3caa12;})[_0x6fff('0x24')](respondWithFilteredResult(_0x4ca537,_0x49335b))[_0x6fff('0x42')](handleError(_0x4ca537,null));};exports[_0x6fff('0x43')]=function(_0x14d831,_0x24c200){var _0x3ab615={'raw':!![],'where':{'id':_0x14d831[_0x6fff('0x44')]['id']}},_0x1d9fe9={};_0x1d9fe9[_0x6fff('0x2e')]=_['keys'](db[_0x6fff('0x40')]['rawAttributes']);_0x1d9fe9[_0x6fff('0x30')]=_['keys'](_0x14d831['query']);_0x1d9fe9['filters']=_[_0x6fff('0x33')](_0x1d9fe9[_0x6fff('0x2e')],_0x1d9fe9['query']);_0x3ab615[_0x6fff('0x35')]=_['intersection'](_0x1d9fe9[_0x6fff('0x2e')],qs[_0x6fff('0x34')](_0x14d831[_0x6fff('0x30')]['fields']));_0x3ab615[_0x6fff('0x35')]=_0x3ab615[_0x6fff('0x35')]['length']?_0x3ab615[_0x6fff('0x35')]:_0x1d9fe9['model'];if(_0x14d831[_0x6fff('0x30')][_0x6fff('0x41')]){_0x3ab615[_0x6fff('0x45')]=[{'all':!![]}];}_0x3ab615=_['merge']({},_0x3ab615,_0x14d831[_0x6fff('0x3f')]);return db[_0x6fff('0x40')][_0x6fff('0x46')](_0x3ab615)[_0x6fff('0x24')](handleEntityNotFound(_0x24c200,null))[_0x6fff('0x24')](respondWithResult(_0x24c200,null))[_0x6fff('0x42')](handleError(_0x24c200,null));};exports[_0x6fff('0x47')]=function(_0x45cfa3,_0x443785){return db['JscriptyAnswerReport'][_0x6fff('0x47')](_0x45cfa3[_0x6fff('0x48')],{})[_0x6fff('0x24')](respondWithResult(_0x443785,0xc9))[_0x6fff('0x42')](handleError(_0x443785,null));};exports[_0x6fff('0x23')]=function(_0x1d87bf,_0x4fdece){if(_0x1d87bf[_0x6fff('0x48')]['id']){delete _0x1d87bf['body']['id'];}return db[_0x6fff('0x40')][_0x6fff('0x46')]({'where':{'id':_0x1d87bf[_0x6fff('0x44')]['id']}})[_0x6fff('0x24')](handleEntityNotFound(_0x4fdece,null))['then'](saveUpdates(_0x1d87bf[_0x6fff('0x48')],null))[_0x6fff('0x24')](respondWithResult(_0x4fdece,null))['catch'](handleError(_0x4fdece,null));};exports[_0x6fff('0x25')]=function(_0x315649,_0x1e9f26){return db[_0x6fff('0x40')][_0x6fff('0x46')]({'where':{'id':_0x315649[_0x6fff('0x44')]['id']}})[_0x6fff('0x24')](handleEntityNotFound(_0x1e9f26,null))[_0x6fff('0x24')](removeEntity(_0x1e9f26,null))[_0x6fff('0x42')](handleError(_0x1e9f26,null));};exports[_0x6fff('0x49')]=function(_0x2e97c9,_0x2371d9){return db[_0x6fff('0x40')][_0x6fff('0x49')]()[_0x6fff('0x24')](respondWithResult(_0x2371d9,null))[_0x6fff('0x42')](handleError(_0x2371d9,null));};