Built motion from commit (unavailable).|2.5.30
[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 _0x65cb=['findAll','rows','show','params','fields','includeAll','catch','create','body','find','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','length','nolimit','order','sort','where','filter','merge','options','JscriptyAnswerReport','include'];(function(_0x55e1d1,_0x3c9376){var _0x1165db=function(_0x5b0120){while(--_0x5b0120){_0x55e1d1['push'](_0x55e1d1['shift']());}};_0x1165db(++_0x3c9376);}(_0x65cb,0xa4));var _0xb65c=function(_0x516d6b,_0x372b12){_0x516d6b=_0x516d6b-0x0;var _0x1d6a16=_0x65cb[_0x516d6b];return _0x1d6a16;};'use strict';var emlformat=require(_0xb65c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xb65c('0x1'));var jsonpatch=require(_0xb65c('0x2'));var rp=require(_0xb65c('0x3'));var moment=require('moment');var BPromise=require(_0xb65c('0x4'));var Mustache=require(_0xb65c('0x5'));var util=require(_0xb65c('0x6'));var path=require(_0xb65c('0x7'));var sox=require(_0xb65c('0x8'));var csv=require('to-csv');var ejs=require(_0xb65c('0x9'));var fs=require('fs');var fs_extra=require(_0xb65c('0xa'));var _=require(_0xb65c('0xb'));var squel=require(_0xb65c('0xc'));var crypto=require(_0xb65c('0xd'));var jsforce=require(_0xb65c('0xe'));var deskjs=require(_0xb65c('0xf'));var toCsv=require(_0xb65c('0x10'));var querystring=require('querystring');var Papa=require(_0xb65c('0x11'));var Redis=require(_0xb65c('0x12'));var authService=require(_0xb65c('0x13'));var qs=require(_0xb65c('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb65c('0x15'));var logger=require('../../config/logger')(_0xb65c('0x16'));var utils=require(_0xb65c('0x17'));var config=require(_0xb65c('0x18'));var licenseUtil=require(_0xb65c('0x19'));var db=require(_0xb65c('0x1a'))['db'];function respondWithStatusCode(_0xbab2df,_0x4eb271){_0x4eb271=_0x4eb271||0xcc;return function(_0x340e60){if(_0x340e60){return _0xbab2df[_0xb65c('0x1b')](_0x4eb271);}return _0xbab2df[_0xb65c('0x1c')](_0x4eb271)[_0xb65c('0x1d')]();};}function respondWithResult(_0x3f1e8b,_0x11ebca){_0x11ebca=_0x11ebca||0xc8;return function(_0x2821e2){if(_0x2821e2){return _0x3f1e8b['status'](_0x11ebca)[_0xb65c('0x1e')](_0x2821e2);}};}function respondWithFilteredResult(_0x22eb85,_0x5a4354){return function(_0x288314){if(_0x288314){var _0x5c6d66=typeof _0x5a4354[_0xb65c('0x1f')]===_0xb65c('0x20')&&typeof _0x5a4354[_0xb65c('0x21')]===_0xb65c('0x20');var _0x24c1e2=_0x288314[_0xb65c('0x22')];var _0x1bca9d=_0x5c6d66?0x0:_0x5a4354[_0xb65c('0x1f')];var _0x199b13=_0x5c6d66?_0x288314[_0xb65c('0x22')]:_0x5a4354[_0xb65c('0x1f')]+_0x5a4354[_0xb65c('0x21')];var _0x2fe603;if(_0x199b13>=_0x24c1e2){_0x199b13=_0x24c1e2;_0x2fe603=0xc8;}else{_0x2fe603=0xce;}_0x22eb85[_0xb65c('0x1c')](_0x2fe603);return _0x22eb85[_0xb65c('0x23')]('Content-Range',_0x1bca9d+'-'+_0x199b13+'/'+_0x24c1e2)[_0xb65c('0x1e')](_0x288314);}return null;};}function patchUpdates(_0x2733c6){return function(_0x45b7e9){try{jsonpatch[_0xb65c('0x24')](_0x45b7e9,_0x2733c6,!![]);}catch(_0x37b944){return BPromise[_0xb65c('0x25')](_0x37b944);}return _0x45b7e9[_0xb65c('0x26')]();};}function saveUpdates(_0x2727cc,_0x248364){return function(_0x33fa4c){if(_0x33fa4c){return _0x33fa4c[_0xb65c('0x27')](_0x2727cc)[_0xb65c('0x28')](function(_0xd04d5){return _0xd04d5;});}return null;};}function removeEntity(_0x33961d,_0xe16c8f){return function(_0x5ed03){if(_0x5ed03){return _0x5ed03[_0xb65c('0x29')]()['then'](function(){_0x33961d[_0xb65c('0x1c')](0xcc)[_0xb65c('0x1d')]();});}};}function handleEntityNotFound(_0x29c0c0,_0x585f93){return function(_0x1b7e00){if(!_0x1b7e00){_0x29c0c0[_0xb65c('0x1b')](0x194);}return _0x1b7e00;};}function handleError(_0x49035e,_0x5a34c7){_0x5a34c7=_0x5a34c7||0x1f4;return function(_0x4033bd){logger[_0xb65c('0x2a')](_0x4033bd[_0xb65c('0x2b')]);if(_0x4033bd[_0xb65c('0x2c')]){delete _0x4033bd['name'];}_0x49035e[_0xb65c('0x1c')](_0x5a34c7)[_0xb65c('0x2d')](_0x4033bd);};}exports[_0xb65c('0x2e')]=function(_0x21cb9c,_0x1ffc77){var _0x11b562={},_0x5158d9={},_0x2e06df={'count':0x0,'rows':[]};var _0x2c83aa=_[_0xb65c('0x2f')](db['JscriptyAnswerReport'][_0xb65c('0x30')],function(_0x5f5ca7){return{'name':_0x5f5ca7[_0xb65c('0x31')],'type':_0x5f5ca7[_0xb65c('0x32')]['key']};});_0x5158d9[_0xb65c('0x33')]=_[_0xb65c('0x2f')](_0x2c83aa,_0xb65c('0x2c'));_0x5158d9[_0xb65c('0x34')]=_[_0xb65c('0x35')](_0x21cb9c[_0xb65c('0x34')]);_0x5158d9[_0xb65c('0x36')]=_[_0xb65c('0x37')](_0x5158d9['model'],_0x5158d9[_0xb65c('0x34')]);_0x11b562[_0xb65c('0x38')]=_[_0xb65c('0x37')](_0x5158d9['model'],qs['fields'](_0x21cb9c[_0xb65c('0x34')]['fields']));_0x11b562[_0xb65c('0x38')]=_0x11b562['attributes'][_0xb65c('0x39')]?_0x11b562[_0xb65c('0x38')]:_0x5158d9[_0xb65c('0x33')];if(!_0x21cb9c[_0xb65c('0x34')]['hasOwnProperty'](_0xb65c('0x3a'))){_0x11b562['limit']=qs[_0xb65c('0x21')](_0x21cb9c['query'][_0xb65c('0x21')]);_0x11b562[_0xb65c('0x1f')]=qs[_0xb65c('0x1f')](_0x21cb9c[_0xb65c('0x34')]['offset']);}_0x11b562[_0xb65c('0x3b')]=qs[_0xb65c('0x3c')](_0x21cb9c[_0xb65c('0x34')]['sort']);_0x11b562[_0xb65c('0x3d')]=qs[_0xb65c('0x36')](_['pick'](_0x21cb9c['query'],_0x5158d9[_0xb65c('0x36')]),_0x2c83aa);if(_0x21cb9c[_0xb65c('0x34')][_0xb65c('0x3e')]){_0x11b562[_0xb65c('0x3d')]=_['merge'](_0x11b562[_0xb65c('0x3d')],{'$or':_[_0xb65c('0x2f')](_0x2c83aa,function(_0x2f3125){if(_0x2f3125[_0xb65c('0x32')]!=='VIRTUAL'){var _0x12c685={};_0x12c685[_0x2f3125[_0xb65c('0x2c')]]={'$like':'%'+_0x21cb9c[_0xb65c('0x34')][_0xb65c('0x3e')]+'%'};return _0x12c685;}})});}_0x11b562=_[_0xb65c('0x3f')]({},_0x11b562,_0x21cb9c[_0xb65c('0x40')]);var _0x2c11ae={'where':_0x11b562[_0xb65c('0x3d')]};return db[_0xb65c('0x41')][_0xb65c('0x22')](_0x2c11ae)[_0xb65c('0x28')](function(_0x16c859){_0x2e06df[_0xb65c('0x22')]=_0x16c859;if(_0x21cb9c['query']['includeAll']){_0x11b562[_0xb65c('0x42')]=[{'all':!![]}];}return db[_0xb65c('0x41')][_0xb65c('0x43')](_0x11b562);})['then'](function(_0x42acd6){_0x2e06df[_0xb65c('0x44')]=_0x42acd6;return _0x2e06df;})['then'](respondWithFilteredResult(_0x1ffc77,_0x11b562))['catch'](handleError(_0x1ffc77,null));};exports[_0xb65c('0x45')]=function(_0x18a4da,_0x150ffb){var _0x215e62={'raw':!![],'where':{'id':_0x18a4da[_0xb65c('0x46')]['id']}},_0x199625={};_0x199625['model']=_[_0xb65c('0x35')](db[_0xb65c('0x41')][_0xb65c('0x30')]);_0x199625[_0xb65c('0x34')]=_[_0xb65c('0x35')](_0x18a4da[_0xb65c('0x34')]);_0x199625['filters']=_[_0xb65c('0x37')](_0x199625[_0xb65c('0x33')],_0x199625[_0xb65c('0x34')]);_0x215e62[_0xb65c('0x38')]=_[_0xb65c('0x37')](_0x199625['model'],qs[_0xb65c('0x47')](_0x18a4da[_0xb65c('0x34')][_0xb65c('0x47')]));_0x215e62[_0xb65c('0x38')]=_0x215e62[_0xb65c('0x38')]['length']?_0x215e62['attributes']:_0x199625[_0xb65c('0x33')];if(_0x18a4da[_0xb65c('0x34')][_0xb65c('0x48')]){_0x215e62[_0xb65c('0x42')]=[{'all':!![]}];}_0x215e62=_['merge']({},_0x215e62,_0x18a4da[_0xb65c('0x40')]);return db[_0xb65c('0x41')]['find'](_0x215e62)[_0xb65c('0x28')](handleEntityNotFound(_0x150ffb,null))['then'](respondWithResult(_0x150ffb,null))[_0xb65c('0x49')](handleError(_0x150ffb,null));};exports[_0xb65c('0x4a')]=function(_0x2ad35c,_0x1af087){return db['JscriptyAnswerReport'][_0xb65c('0x4a')](_0x2ad35c[_0xb65c('0x4b')],{})[_0xb65c('0x28')](respondWithResult(_0x1af087,0xc9))[_0xb65c('0x49')](handleError(_0x1af087,null));};exports[_0xb65c('0x27')]=function(_0x5e81e2,_0x481d4d){if(_0x5e81e2[_0xb65c('0x4b')]['id']){delete _0x5e81e2[_0xb65c('0x4b')]['id'];}return db[_0xb65c('0x41')]['find']({'where':{'id':_0x5e81e2[_0xb65c('0x46')]['id']}})['then'](handleEntityNotFound(_0x481d4d,null))[_0xb65c('0x28')](saveUpdates(_0x5e81e2['body'],null))['then'](respondWithResult(_0x481d4d,null))['catch'](handleError(_0x481d4d,null));};exports[_0xb65c('0x29')]=function(_0x5b374c,_0x5e74a8){return db[_0xb65c('0x41')][_0xb65c('0x4c')]({'where':{'id':_0x5b374c[_0xb65c('0x46')]['id']}})[_0xb65c('0x28')](handleEntityNotFound(_0x5e74a8,null))[_0xb65c('0x28')](removeEntity(_0x5e74a8,null))[_0xb65c('0x49')](handleError(_0x5e74a8,null));};exports['describe']=function(_0x51eb3a,_0x27fa35){return db[_0xb65c('0x41')]['describe']()[_0xb65c('0x28')](respondWithResult(_0x27fa35,null))[_0xb65c('0x49')](handleError(_0x27fa35,null));};