a2ae02126991a4d71e587a4017d48a954b80c1db
[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 _0x3fe0=['stack','name','send','index','map','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','filter','where','merge','VIRTUAL','options','JscriptyQuestionReport','count','includeAll','findAll','rows','catch','show','params','keys','include','find','create','body','destroy','describe','eml-format','rimraf','request-promise','bluebird','mustache','util','to-csv','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','Content-Range','apply','reject','save','then','end','error'];(function(_0x2ff739,_0x1c8e0f){var _0x12dc13=function(_0x26fc97){while(--_0x26fc97){_0x2ff739['push'](_0x2ff739['shift']());}};_0x12dc13(++_0x1c8e0f);}(_0x3fe0,0x77));var _0x03fe=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0x3fe0[_0xa464c9];return _0x3d73c4;};'use strict';var emlformat=require(_0x03fe('0x0'));var rimraf=require(_0x03fe('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x03fe('0x2'));var moment=require('moment');var BPromise=require(_0x03fe('0x3'));var Mustache=require(_0x03fe('0x4'));var util=require(_0x03fe('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0x03fe('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x03fe('0x7'));var _=require('lodash');var squel=require(_0x03fe('0x8'));var crypto=require(_0x03fe('0x9'));var jsforce=require(_0x03fe('0xa'));var deskjs=require(_0x03fe('0xb'));var toCsv=require(_0x03fe('0x6'));var querystring=require(_0x03fe('0xc'));var Papa=require(_0x03fe('0xd'));var Redis=require(_0x03fe('0xe'));var authService=require(_0x03fe('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x03fe('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x03fe('0x11'))(_0x03fe('0x12'));var utils=require(_0x03fe('0x13'));var config=require(_0x03fe('0x14'));var licenseUtil=require(_0x03fe('0x15'));var db=require(_0x03fe('0x16'))['db'];function respondWithStatusCode(_0x4b0939,_0x5197b4){_0x5197b4=_0x5197b4||0xcc;return function(_0x29aa34){if(_0x29aa34){return _0x4b0939[_0x03fe('0x17')](_0x5197b4);}return _0x4b0939[_0x03fe('0x18')](_0x5197b4)['end']();};}function respondWithResult(_0x41b776,_0x3ef371){_0x3ef371=_0x3ef371||0xc8;return function(_0x49eab9){if(_0x49eab9){return _0x41b776['status'](_0x3ef371)[_0x03fe('0x19')](_0x49eab9);}};}function respondWithFilteredResult(_0x3184b3,_0x3fbc6e){return function(_0x3adb9f){if(_0x3adb9f){var _0x313830=typeof _0x3fbc6e[_0x03fe('0x1a')]==='undefined'&&typeof _0x3fbc6e['limit']===_0x03fe('0x1b');var _0x325e8c=_0x3adb9f['count'];var _0x3f4070=_0x313830?0x0:_0x3fbc6e[_0x03fe('0x1a')];var _0x335363=_0x313830?_0x3adb9f['count']:_0x3fbc6e[_0x03fe('0x1a')]+_0x3fbc6e['limit'];var _0x1f748a;if(_0x335363>=_0x325e8c){_0x335363=_0x325e8c;_0x1f748a=0xc8;}else{_0x1f748a=0xce;}_0x3184b3[_0x03fe('0x18')](_0x1f748a);return _0x3184b3['set'](_0x03fe('0x1c'),_0x3f4070+'-'+_0x335363+'/'+_0x325e8c)['json'](_0x3adb9f);}return null;};}function patchUpdates(_0x5e532f){return function(_0x32449e){try{jsonpatch[_0x03fe('0x1d')](_0x32449e,_0x5e532f,!![]);}catch(_0x1525fe){return BPromise[_0x03fe('0x1e')](_0x1525fe);}return _0x32449e[_0x03fe('0x1f')]();};}function saveUpdates(_0x1643c6,_0x2f7032){return function(_0x167f84){if(_0x167f84){return _0x167f84['update'](_0x1643c6)[_0x03fe('0x20')](function(_0x256829){return _0x256829;});}return null;};}function removeEntity(_0x22977d,_0x101304){return function(_0x355f7b){if(_0x355f7b){return _0x355f7b['destroy']()['then'](function(){_0x22977d[_0x03fe('0x18')](0xcc)[_0x03fe('0x21')]();});}};}function handleEntityNotFound(_0x57b4ca,_0x327a48){return function(_0x5774ef){if(!_0x5774ef){_0x57b4ca[_0x03fe('0x17')](0x194);}return _0x5774ef;};}function handleError(_0x961410,_0x27c09a){_0x27c09a=_0x27c09a||0x1f4;return function(_0x5af892){logger[_0x03fe('0x22')](_0x5af892[_0x03fe('0x23')]);if(_0x5af892[_0x03fe('0x24')]){delete _0x5af892[_0x03fe('0x24')];}_0x961410['status'](_0x27c09a)[_0x03fe('0x25')](_0x5af892);};}exports[_0x03fe('0x26')]=function(_0x3ea2b6,_0x4fa061){var _0x2f9ca7={},_0x1e4e2b={},_0x45f664={'count':0x0,'rows':[]};var _0x69c373=_[_0x03fe('0x27')](db['JscriptyQuestionReport'][_0x03fe('0x28')],function(_0x298039){return{'name':_0x298039[_0x03fe('0x29')],'type':_0x298039[_0x03fe('0x2a')][_0x03fe('0x2b')]};});_0x1e4e2b['model']=_[_0x03fe('0x27')](_0x69c373,_0x03fe('0x24'));_0x1e4e2b['query']=_['keys'](_0x3ea2b6[_0x03fe('0x2c')]);_0x1e4e2b[_0x03fe('0x2d')]=_[_0x03fe('0x2e')](_0x1e4e2b[_0x03fe('0x2f')],_0x1e4e2b['query']);_0x2f9ca7[_0x03fe('0x30')]=_['intersection'](_0x1e4e2b['model'],qs['fields'](_0x3ea2b6[_0x03fe('0x2c')][_0x03fe('0x31')]));_0x2f9ca7[_0x03fe('0x30')]=_0x2f9ca7[_0x03fe('0x30')][_0x03fe('0x32')]?_0x2f9ca7[_0x03fe('0x30')]:_0x1e4e2b[_0x03fe('0x2f')];if(!_0x3ea2b6[_0x03fe('0x2c')][_0x03fe('0x33')](_0x03fe('0x34'))){_0x2f9ca7['limit']=qs[_0x03fe('0x35')](_0x3ea2b6[_0x03fe('0x2c')]['limit']);_0x2f9ca7[_0x03fe('0x1a')]=qs['offset'](_0x3ea2b6[_0x03fe('0x2c')][_0x03fe('0x1a')]);}_0x2f9ca7[_0x03fe('0x36')]=qs[_0x03fe('0x37')](_0x3ea2b6[_0x03fe('0x2c')][_0x03fe('0x37')]);_0x2f9ca7['where']=qs[_0x03fe('0x2d')](_[_0x03fe('0x38')](_0x3ea2b6[_0x03fe('0x2c')],_0x1e4e2b[_0x03fe('0x2d')]),_0x69c373);if(_0x3ea2b6[_0x03fe('0x2c')][_0x03fe('0x39')]){_0x2f9ca7[_0x03fe('0x3a')]=_[_0x03fe('0x3b')](_0x2f9ca7[_0x03fe('0x3a')],{'$or':_['map'](_0x69c373,function(_0xac72e6){if(_0xac72e6[_0x03fe('0x2a')]!==_0x03fe('0x3c')){var _0x52ae66={};_0x52ae66[_0xac72e6[_0x03fe('0x24')]]={'$like':'%'+_0x3ea2b6['query'][_0x03fe('0x39')]+'%'};return _0x52ae66;}})});}_0x2f9ca7=_[_0x03fe('0x3b')]({},_0x2f9ca7,_0x3ea2b6[_0x03fe('0x3d')]);var _0x44b0fe={'where':_0x2f9ca7[_0x03fe('0x3a')]};return db[_0x03fe('0x3e')][_0x03fe('0x3f')](_0x44b0fe)[_0x03fe('0x20')](function(_0x5f13c2){_0x45f664[_0x03fe('0x3f')]=_0x5f13c2;if(_0x3ea2b6[_0x03fe('0x2c')][_0x03fe('0x40')]){_0x2f9ca7['include']=[{'all':!![]}];}return db[_0x03fe('0x3e')][_0x03fe('0x41')](_0x2f9ca7);})[_0x03fe('0x20')](function(_0xce0807){_0x45f664[_0x03fe('0x42')]=_0xce0807;return _0x45f664;})[_0x03fe('0x20')](respondWithFilteredResult(_0x4fa061,_0x2f9ca7))[_0x03fe('0x43')](handleError(_0x4fa061,null));};exports[_0x03fe('0x44')]=function(_0x4b6635,_0x5ef85a){var _0x2d303b={'raw':!![],'where':{'id':_0x4b6635[_0x03fe('0x45')]['id']}},_0x58d693={};_0x58d693[_0x03fe('0x2f')]=_[_0x03fe('0x46')](db[_0x03fe('0x3e')]['rawAttributes']);_0x58d693[_0x03fe('0x2c')]=_[_0x03fe('0x46')](_0x4b6635[_0x03fe('0x2c')]);_0x58d693[_0x03fe('0x2d')]=_[_0x03fe('0x2e')](_0x58d693[_0x03fe('0x2f')],_0x58d693[_0x03fe('0x2c')]);_0x2d303b[_0x03fe('0x30')]=_[_0x03fe('0x2e')](_0x58d693[_0x03fe('0x2f')],qs[_0x03fe('0x31')](_0x4b6635['query']['fields']));_0x2d303b['attributes']=_0x2d303b[_0x03fe('0x30')][_0x03fe('0x32')]?_0x2d303b['attributes']:_0x58d693[_0x03fe('0x2f')];if(_0x4b6635[_0x03fe('0x2c')][_0x03fe('0x40')]){_0x2d303b[_0x03fe('0x47')]=[{'all':!![]}];}_0x2d303b=_['merge']({},_0x2d303b,_0x4b6635[_0x03fe('0x3d')]);return db[_0x03fe('0x3e')][_0x03fe('0x48')](_0x2d303b)[_0x03fe('0x20')](handleEntityNotFound(_0x5ef85a,null))['then'](respondWithResult(_0x5ef85a,null))[_0x03fe('0x43')](handleError(_0x5ef85a,null));};exports[_0x03fe('0x49')]=function(_0x58a3b5,_0xd90b23){return db['JscriptyQuestionReport'][_0x03fe('0x49')](_0x58a3b5['body'],{})[_0x03fe('0x20')](respondWithResult(_0xd90b23,0xc9))[_0x03fe('0x43')](handleError(_0xd90b23,null));};exports['update']=function(_0x1e05f9,_0x1d36be){if(_0x1e05f9['body']['id']){delete _0x1e05f9[_0x03fe('0x4a')]['id'];}return db[_0x03fe('0x3e')][_0x03fe('0x48')]({'where':{'id':_0x1e05f9[_0x03fe('0x45')]['id']}})[_0x03fe('0x20')](handleEntityNotFound(_0x1d36be,null))[_0x03fe('0x20')](saveUpdates(_0x1e05f9['body'],null))[_0x03fe('0x20')](respondWithResult(_0x1d36be,null))['catch'](handleError(_0x1d36be,null));};exports[_0x03fe('0x4b')]=function(_0x1f3d36,_0x831dee){return db[_0x03fe('0x3e')]['find']({'where':{'id':_0x1f3d36[_0x03fe('0x45')]['id']}})[_0x03fe('0x20')](handleEntityNotFound(_0x831dee,null))[_0x03fe('0x20')](removeEntity(_0x831dee,null))[_0x03fe('0x43')](handleError(_0x831dee,null));};exports[_0x03fe('0x4c')]=function(_0x580c20,_0x4d8a2f){return db[_0x03fe('0x3e')][_0x03fe('0x4c')]()[_0x03fe('0x20')](respondWithResult(_0x4d8a2f,null))[_0x03fe('0x43')](handleError(_0x4d8a2f,null));};