Built motion from commit (unavailable).|2.5.19
[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 _0x5c8e=['key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','where','merge','VIRTUAL','filter','include','findAll','rows','show','params','find','catch','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','crypto','desk.js','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','index','map','JscriptyQuestionReport','rawAttributes','fieldName','type'];(function(_0xce3d93,_0x504f1c){var _0x16bcf8=function(_0xff82f3){while(--_0xff82f3){_0xce3d93['push'](_0xce3d93['shift']());}};_0x16bcf8(++_0x504f1c);}(_0x5c8e,0x14f));var _0xe5c8=function(_0x24a2f8,_0x14aaa7){_0x24a2f8=_0x24a2f8-0x0;var _0x42960c=_0x5c8e[_0x24a2f8];return _0x42960c;};'use strict';var pdf=require(_0xe5c8('0x0'));var emlformat=require(_0xe5c8('0x1'));var rimraf=require(_0xe5c8('0x2'));var zipdir=require(_0xe5c8('0x3'));var jsonpatch=require(_0xe5c8('0x4'));var rp=require('request-promise');var moment=require(_0xe5c8('0x5'));var BPromise=require(_0xe5c8('0x6'));var Mustache=require(_0xe5c8('0x7'));var util=require(_0xe5c8('0x8'));var path=require(_0xe5c8('0x9'));var sox=require(_0xe5c8('0xa'));var csv=require(_0xe5c8('0xb'));var ejs=require(_0xe5c8('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0xe5c8('0xd'));var crypto=require(_0xe5c8('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xe5c8('0xf'));var toCsv=require('to-csv');var querystring=require(_0xe5c8('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xe5c8('0x11'));var as=require(_0xe5c8('0x12'));var hardwareService=require(_0xe5c8('0x13'));var logger=require(_0xe5c8('0x14'))(_0xe5c8('0x15'));var utils=require(_0xe5c8('0x16'));var config=require(_0xe5c8('0x17'));var licenseUtil=require(_0xe5c8('0x18'));var db=require(_0xe5c8('0x19'))['db'];function respondWithStatusCode(_0x20b374,_0x587baf){_0x587baf=_0x587baf||0xcc;return function(_0x365b00){if(_0x365b00){return _0x20b374[_0xe5c8('0x1a')](_0x587baf);}return _0x20b374[_0xe5c8('0x1b')](_0x587baf)[_0xe5c8('0x1c')]();};}function respondWithResult(_0x5310c1,_0x2b3900){_0x2b3900=_0x2b3900||0xc8;return function(_0x1b993f){if(_0x1b993f){return _0x5310c1[_0xe5c8('0x1b')](_0x2b3900)[_0xe5c8('0x1d')](_0x1b993f);}};}function respondWithFilteredResult(_0x43a15b,_0x2131e0){return function(_0x5da9c9){if(_0x5da9c9){var _0x16ce13=_0x5da9c9[_0xe5c8('0x1e')],_0x3ba75e=_0x2131e0[_0xe5c8('0x1f')],_0x4e496e=_0x2131e0[_0xe5c8('0x1f')]+_0x2131e0[_0xe5c8('0x20')],_0x1b986c;if(_0x4e496e>=_0x16ce13){_0x4e496e=_0x16ce13;_0x1b986c=0xc8;}else{_0x1b986c=0xce;}_0x43a15b[_0xe5c8('0x1b')](_0x1b986c);return _0x43a15b[_0xe5c8('0x21')](_0xe5c8('0x22'),_0x3ba75e+'-'+_0x4e496e+'/'+_0x16ce13)[_0xe5c8('0x1d')](_0x5da9c9);}return null;};}function patchUpdates(_0x126bba){return function(_0x17a9cc){try{jsonpatch[_0xe5c8('0x23')](_0x17a9cc,_0x126bba,!![]);}catch(_0x4b338e){return BPromise[_0xe5c8('0x24')](_0x4b338e);}return _0x17a9cc['save']();};}function saveUpdates(_0x3d390c,_0x50f54f){return function(_0x492b32){if(_0x492b32){return _0x492b32[_0xe5c8('0x25')](_0x3d390c)[_0xe5c8('0x26')](function(_0x56cf80){return _0x56cf80;});}return null;};}function removeEntity(_0x451c8c,_0x269c5d){return function(_0x3efcb9){if(_0x3efcb9){return _0x3efcb9[_0xe5c8('0x27')]()[_0xe5c8('0x26')](function(){_0x451c8c[_0xe5c8('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x20c5a7,_0x394e9c){return function(_0x25b9ac){if(!_0x25b9ac){_0x20c5a7[_0xe5c8('0x1a')](0x194);}return _0x25b9ac;};}function handleError(_0x2ffe99,_0x82771c){_0x82771c=_0x82771c||0x1f4;return function(_0x1be391){logger[_0xe5c8('0x28')](_0x1be391[_0xe5c8('0x29')]);if(_0x1be391[_0xe5c8('0x2a')]){delete _0x1be391[_0xe5c8('0x2a')];}_0x2ffe99['status'](_0x82771c)[_0xe5c8('0x2b')](_0x1be391);};}exports[_0xe5c8('0x2c')]=function(_0x2cb622,_0x49048f){var _0x5d7755={},_0x891631={},_0xedda={'count':0x0,'rows':[]};var _0x36523d=_[_0xe5c8('0x2d')](db[_0xe5c8('0x2e')][_0xe5c8('0x2f')],function(_0x33ca70){return{'name':_0x33ca70[_0xe5c8('0x30')],'type':_0x33ca70[_0xe5c8('0x31')][_0xe5c8('0x32')]};});_0x891631[_0xe5c8('0x33')]=_[_0xe5c8('0x2d')](_0x36523d,_0xe5c8('0x2a'));_0x891631[_0xe5c8('0x34')]=_[_0xe5c8('0x35')](_0x2cb622[_0xe5c8('0x34')]);_0x891631[_0xe5c8('0x36')]=_[_0xe5c8('0x37')](_0x891631[_0xe5c8('0x33')],_0x891631[_0xe5c8('0x34')]);_0x5d7755[_0xe5c8('0x38')]=_[_0xe5c8('0x37')](_0x891631[_0xe5c8('0x33')],qs[_0xe5c8('0x39')](_0x2cb622[_0xe5c8('0x34')][_0xe5c8('0x39')]));_0x5d7755[_0xe5c8('0x38')]=_0x5d7755[_0xe5c8('0x38')]['length']?_0x5d7755[_0xe5c8('0x38')]:_0x891631[_0xe5c8('0x33')];if(!_0x2cb622[_0xe5c8('0x34')][_0xe5c8('0x3a')](_0xe5c8('0x3b'))){_0x5d7755['limit']=qs['limit'](_0x2cb622[_0xe5c8('0x34')][_0xe5c8('0x20')]);_0x5d7755[_0xe5c8('0x1f')]=qs[_0xe5c8('0x1f')](_0x2cb622['query'][_0xe5c8('0x1f')]);}_0x5d7755[_0xe5c8('0x3c')]=qs[_0xe5c8('0x3d')](_0x2cb622[_0xe5c8('0x34')][_0xe5c8('0x3d')]);_0x5d7755['where']=qs[_0xe5c8('0x36')](_[_0xe5c8('0x3e')](_0x2cb622[_0xe5c8('0x34')],_0x891631[_0xe5c8('0x36')]),_0x36523d);if(_0x2cb622['query']['filter']){_0x5d7755[_0xe5c8('0x3f')]=_[_0xe5c8('0x40')](_0x5d7755[_0xe5c8('0x3f')],{'$or':_[_0xe5c8('0x2d')](_0x36523d,function(_0x1217cc){if(_0x1217cc['type']!==_0xe5c8('0x41')){var _0x1a43a1={};_0x1a43a1[_0x1217cc['name']]={'$like':'%'+_0x2cb622[_0xe5c8('0x34')][_0xe5c8('0x42')]+'%'};return _0x1a43a1;}})});}_0x5d7755=_[_0xe5c8('0x40')]({},_0x5d7755,_0x2cb622['options']);var _0x5f278={'where':_0x5d7755[_0xe5c8('0x3f')]};return db[_0xe5c8('0x2e')][_0xe5c8('0x1e')](_0x5f278)[_0xe5c8('0x26')](function(_0x5262af){_0xedda['count']=_0x5262af;if(_0x2cb622['query']['includeAll']){_0x5d7755[_0xe5c8('0x43')]=[{'all':!![]}];}return db[_0xe5c8('0x2e')][_0xe5c8('0x44')](_0x5d7755);})[_0xe5c8('0x26')](function(_0x1d21f8){_0xedda[_0xe5c8('0x45')]=_0x1d21f8;return _0xedda;})['then'](respondWithFilteredResult(_0x49048f,_0x5d7755))['catch'](handleError(_0x49048f,null));};exports[_0xe5c8('0x46')]=function(_0x203ecc,_0x52ddc5){var _0x2fd111={'raw':!![],'where':{'id':_0x203ecc[_0xe5c8('0x47')]['id']}},_0x327dd1={};_0x327dd1[_0xe5c8('0x33')]=_[_0xe5c8('0x35')](db[_0xe5c8('0x2e')][_0xe5c8('0x2f')]);_0x327dd1[_0xe5c8('0x34')]=_[_0xe5c8('0x35')](_0x203ecc['query']);_0x327dd1[_0xe5c8('0x36')]=_[_0xe5c8('0x37')](_0x327dd1[_0xe5c8('0x33')],_0x327dd1['query']);_0x2fd111[_0xe5c8('0x38')]=_[_0xe5c8('0x37')](_0x327dd1[_0xe5c8('0x33')],qs[_0xe5c8('0x39')](_0x203ecc[_0xe5c8('0x34')][_0xe5c8('0x39')]));_0x2fd111['attributes']=_0x2fd111[_0xe5c8('0x38')]['length']?_0x2fd111[_0xe5c8('0x38')]:_0x327dd1[_0xe5c8('0x33')];if(_0x203ecc[_0xe5c8('0x34')]['includeAll']){_0x2fd111[_0xe5c8('0x43')]=[{'all':!![]}];}_0x2fd111=_[_0xe5c8('0x40')]({},_0x2fd111,_0x203ecc['options']);return db[_0xe5c8('0x2e')][_0xe5c8('0x48')](_0x2fd111)[_0xe5c8('0x26')](handleEntityNotFound(_0x52ddc5,null))[_0xe5c8('0x26')](respondWithResult(_0x52ddc5,null))[_0xe5c8('0x49')](handleError(_0x52ddc5,null));};exports[_0xe5c8('0x4a')]=function(_0x57169b,_0x548275){return db[_0xe5c8('0x2e')][_0xe5c8('0x4a')](_0x57169b[_0xe5c8('0x4b')],{})[_0xe5c8('0x26')](respondWithResult(_0x548275,0xc9))[_0xe5c8('0x49')](handleError(_0x548275,null));};exports['update']=function(_0x46029a,_0x935f2){if(_0x46029a[_0xe5c8('0x4b')]['id']){delete _0x46029a[_0xe5c8('0x4b')]['id'];}return db['JscriptyQuestionReport']['find']({'where':{'id':_0x46029a[_0xe5c8('0x47')]['id']}})['then'](handleEntityNotFound(_0x935f2,null))['then'](saveUpdates(_0x46029a['body'],null))[_0xe5c8('0x26')](respondWithResult(_0x935f2,null))['catch'](handleError(_0x935f2,null));};exports[_0xe5c8('0x27')]=function(_0x24c82c,_0x540097){return db[_0xe5c8('0x2e')][_0xe5c8('0x48')]({'where':{'id':_0x24c82c['params']['id']}})[_0xe5c8('0x26')](handleEntityNotFound(_0x540097,null))[_0xe5c8('0x26')](removeEntity(_0x540097,null))[_0xe5c8('0x49')](handleError(_0x540097,null));};exports[_0xe5c8('0x4c')]=function(_0x397dd6,_0x5038d7){return db[_0xe5c8('0x2e')][_0xe5c8('0x4c')]()[_0xe5c8('0x26')](respondWithResult(_0x5038d7,null))[_0xe5c8('0x49')](handleError(_0x5038d7,null));};