Built motion from commit (unavailable).|2.4.18
[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 _0x7510=['hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','show','params','length','find','catch','create','body','describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','limit','set','apply','reject','update','then','destroy','end','error','stack','name','send','index','map','JscriptyAnswerReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields'];(function(_0x2d99a2,_0x1c9ac7){var _0x3c40ef=function(_0x5037cb){while(--_0x5037cb){_0x2d99a2['push'](_0x2d99a2['shift']());}};_0x3c40ef(++_0x1c9ac7);}(_0x7510,0xa9));var _0x0751=function(_0x1facfa,_0x1acf7d){_0x1facfa=_0x1facfa-0x0;var _0x9ec701=_0x7510[_0x1facfa];return _0x9ec701;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x0751('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x0751('0x1'));var jsonpatch=require(_0x0751('0x2'));var rp=require(_0x0751('0x3'));var moment=require('moment');var BPromise=require(_0x0751('0x4'));var Mustache=require(_0x0751('0x5'));var util=require(_0x0751('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x0751('0x7'));var squel=require('squel');var crypto=require(_0x0751('0x8'));var jsforce=require(_0x0751('0x9'));var deskjs=require(_0x0751('0xa'));var toCsv=require(_0x0751('0xb'));var querystring=require(_0x0751('0xc'));var Papa=require(_0x0751('0xd'));var Redis=require(_0x0751('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x0751('0xf'));var as=require(_0x0751('0x10'));var hardwareService=require(_0x0751('0x11'));var logger=require(_0x0751('0x12'))(_0x0751('0x13'));var utils=require('../../config/utils');var config=require(_0x0751('0x14'));var db=require(_0x0751('0x15'))['db'];function respondWithStatusCode(_0x7f8f87,_0x16b239){_0x16b239=_0x16b239||0xcc;return function(_0x340a1d){if(_0x340a1d){return _0x7f8f87[_0x0751('0x16')](_0x16b239);}return _0x7f8f87['status'](_0x16b239)['end']();};}function respondWithResult(_0x244b35,_0x12110b){_0x12110b=_0x12110b||0xc8;return function(_0x1dc807){if(_0x1dc807){return _0x244b35[_0x0751('0x17')](_0x12110b)[_0x0751('0x18')](_0x1dc807);}};}function respondWithFilteredResult(_0x3bd842,_0x4a3c0e){return function(_0x459c8f){if(_0x459c8f){var _0x56c928=_0x459c8f[_0x0751('0x19')],_0x1a3e87=_0x4a3c0e[_0x0751('0x1a')],_0x6545db=_0x4a3c0e[_0x0751('0x1a')]+_0x4a3c0e[_0x0751('0x1b')],_0xea2eec;if(_0x6545db>=_0x56c928){_0x6545db=_0x56c928;_0xea2eec=0xc8;}else{_0xea2eec=0xce;}_0x3bd842[_0x0751('0x17')](_0xea2eec);return _0x3bd842[_0x0751('0x1c')]('Content-Range',_0x1a3e87+'-'+_0x6545db+'/'+_0x56c928)[_0x0751('0x18')](_0x459c8f);}return null;};}function patchUpdates(_0x24d034){return function(_0x305efd){try{jsonpatch[_0x0751('0x1d')](_0x305efd,_0x24d034,!![]);}catch(_0x3ddad2){return BPromise[_0x0751('0x1e')](_0x3ddad2);}return _0x305efd['save']();};}function saveUpdates(_0x5d84a9,_0x13500f){return function(_0x153564){if(_0x153564){return _0x153564[_0x0751('0x1f')](_0x5d84a9)[_0x0751('0x20')](function(_0x5c8414){return _0x5c8414;});}return null;};}function removeEntity(_0x2630cb,_0x2e72a8){return function(_0x2eacee){if(_0x2eacee){return _0x2eacee[_0x0751('0x21')]()[_0x0751('0x20')](function(){_0x2630cb[_0x0751('0x17')](0xcc)[_0x0751('0x22')]();});}};}function handleEntityNotFound(_0x459058,_0x34734a){return function(_0x578172){if(!_0x578172){_0x459058[_0x0751('0x16')](0x194);}return _0x578172;};}function handleError(_0x1efb3d,_0x20b055){_0x20b055=_0x20b055||0x1f4;return function(_0x5a237d){logger[_0x0751('0x23')](_0x5a237d[_0x0751('0x24')]);if(_0x5a237d[_0x0751('0x25')]){delete _0x5a237d[_0x0751('0x25')];}_0x1efb3d[_0x0751('0x17')](_0x20b055)[_0x0751('0x26')](_0x5a237d);};}exports[_0x0751('0x27')]=function(_0x5a9852,_0x165c59){var _0x4bc374={},_0x507b41={},_0x2c5130={'count':0x0,'rows':[]};var _0x448d93=_[_0x0751('0x28')](db[_0x0751('0x29')][_0x0751('0x2a')],function(_0x24bfe4){return{'name':_0x24bfe4[_0x0751('0x2b')],'type':_0x24bfe4[_0x0751('0x2c')][_0x0751('0x2d')]};});_0x507b41[_0x0751('0x2e')]=_['map'](_0x448d93,_0x0751('0x25'));_0x507b41[_0x0751('0x2f')]=_[_0x0751('0x30')](_0x5a9852[_0x0751('0x2f')]);_0x507b41[_0x0751('0x31')]=_[_0x0751('0x32')](_0x507b41[_0x0751('0x2e')],_0x507b41[_0x0751('0x2f')]);_0x4bc374[_0x0751('0x33')]=_['intersection'](_0x507b41[_0x0751('0x2e')],qs[_0x0751('0x34')](_0x5a9852[_0x0751('0x2f')]['fields']));_0x4bc374[_0x0751('0x33')]=_0x4bc374[_0x0751('0x33')]['length']?_0x4bc374[_0x0751('0x33')]:_0x507b41[_0x0751('0x2e')];if(!_0x5a9852[_0x0751('0x2f')][_0x0751('0x35')](_0x0751('0x36'))){_0x4bc374[_0x0751('0x1b')]=qs['limit'](_0x5a9852[_0x0751('0x2f')][_0x0751('0x1b')]);_0x4bc374[_0x0751('0x1a')]=qs[_0x0751('0x1a')](_0x5a9852['query'][_0x0751('0x1a')]);}_0x4bc374[_0x0751('0x37')]=qs[_0x0751('0x38')](_0x5a9852['query'][_0x0751('0x38')]);_0x4bc374[_0x0751('0x39')]=qs['filters'](_[_0x0751('0x3a')](_0x5a9852[_0x0751('0x2f')],_0x507b41[_0x0751('0x31')]));if(_0x5a9852[_0x0751('0x2f')][_0x0751('0x3b')]){_0x4bc374[_0x0751('0x39')]=_[_0x0751('0x3c')](_0x4bc374['where'],{'$or':_[_0x0751('0x28')](_0x448d93,function(_0x194e8c){if(_0x194e8c[_0x0751('0x2c')]!=='VIRTUAL'){var _0x5db57a={};_0x5db57a[_0x194e8c[_0x0751('0x25')]]={'$like':'%'+_0x5a9852[_0x0751('0x2f')][_0x0751('0x3b')]+'%'};return _0x5db57a;}})});}_0x4bc374=_[_0x0751('0x3c')]({},_0x4bc374,_0x5a9852[_0x0751('0x3d')]);var _0x16368a={'where':_0x4bc374[_0x0751('0x39')]};return db[_0x0751('0x29')][_0x0751('0x19')](_0x16368a)[_0x0751('0x20')](function(_0x5733ba){_0x2c5130['count']=_0x5733ba;if(_0x5a9852[_0x0751('0x2f')][_0x0751('0x3e')]){_0x4bc374[_0x0751('0x3f')]=[{'all':!![]}];}return db[_0x0751('0x29')][_0x0751('0x40')](_0x4bc374);})[_0x0751('0x20')](function(_0x263509){_0x2c5130[_0x0751('0x41')]=_0x263509;return _0x2c5130;})[_0x0751('0x20')](respondWithFilteredResult(_0x165c59,_0x4bc374))['catch'](handleError(_0x165c59,null));};exports[_0x0751('0x42')]=function(_0x2accc9,_0x2717d2){var _0x53524b={'raw':!![],'where':{'id':_0x2accc9[_0x0751('0x43')]['id']}},_0xf123c3={};_0xf123c3['model']=_[_0x0751('0x30')](db['JscriptyAnswerReport'][_0x0751('0x2a')]);_0xf123c3[_0x0751('0x2f')]=_['keys'](_0x2accc9['query']);_0xf123c3[_0x0751('0x31')]=_[_0x0751('0x32')](_0xf123c3['model'],_0xf123c3[_0x0751('0x2f')]);_0x53524b[_0x0751('0x33')]=_['intersection'](_0xf123c3[_0x0751('0x2e')],qs[_0x0751('0x34')](_0x2accc9['query'][_0x0751('0x34')]));_0x53524b['attributes']=_0x53524b[_0x0751('0x33')][_0x0751('0x44')]?_0x53524b[_0x0751('0x33')]:_0xf123c3[_0x0751('0x2e')];if(_0x2accc9[_0x0751('0x2f')][_0x0751('0x3e')]){_0x53524b[_0x0751('0x3f')]=[{'all':!![]}];}_0x53524b=_[_0x0751('0x3c')]({},_0x53524b,_0x2accc9[_0x0751('0x3d')]);return db[_0x0751('0x29')][_0x0751('0x45')](_0x53524b)[_0x0751('0x20')](handleEntityNotFound(_0x2717d2,null))[_0x0751('0x20')](respondWithResult(_0x2717d2,null))[_0x0751('0x46')](handleError(_0x2717d2,null));};exports[_0x0751('0x47')]=function(_0x220bf5,_0x1bf1fa){return db['JscriptyAnswerReport'][_0x0751('0x47')](_0x220bf5[_0x0751('0x48')],{})[_0x0751('0x20')](respondWithResult(_0x1bf1fa,0xc9))['catch'](handleError(_0x1bf1fa,null));};exports[_0x0751('0x1f')]=function(_0x386c5b,_0x414ac6){if(_0x386c5b[_0x0751('0x48')]['id']){delete _0x386c5b[_0x0751('0x48')]['id'];}return db[_0x0751('0x29')]['find']({'where':{'id':_0x386c5b[_0x0751('0x43')]['id']}})[_0x0751('0x20')](handleEntityNotFound(_0x414ac6,null))[_0x0751('0x20')](saveUpdates(_0x386c5b[_0x0751('0x48')],null))[_0x0751('0x20')](respondWithResult(_0x414ac6,null))[_0x0751('0x46')](handleError(_0x414ac6,null));};exports[_0x0751('0x21')]=function(_0x40af96,_0x1ab7d6){return db[_0x0751('0x29')][_0x0751('0x45')]({'where':{'id':_0x40af96[_0x0751('0x43')]['id']}})[_0x0751('0x20')](handleEntityNotFound(_0x1ab7d6,null))['then'](removeEntity(_0x1ab7d6,null))[_0x0751('0x46')](handleError(_0x1ab7d6,null));};exports[_0x0751('0x49')]=function(_0x928afc,_0x458389){return db['JscriptyAnswerReport'][_0x0751('0x49')]()[_0x0751('0x20')](respondWithResult(_0x458389,null))[_0x0751('0x46')](handleError(_0x458389,null));};