Built motion from commit 092f8824.|2.5.49
[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 _0x38fb=['options','JscriptyQuestionReport','includeAll','include','findAll','catch','show','params','keys','length','create','body','find','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','undefined','count','set','apply','reject','save','update','then','destroy','end','error','name','send','index','map','rawAttributes','fieldName','type','model','query','filters','intersection','attributes','fields','sort','where','pick','merge','VIRTUAL','filter'];(function(_0x5aa9fd,_0x1dd5c9){var _0xe0b403=function(_0x426ac9){while(--_0x426ac9){_0x5aa9fd['push'](_0x5aa9fd['shift']());}};_0xe0b403(++_0x1dd5c9);}(_0x38fb,0xf8));var _0xb38f=function(_0x3158d2,_0x277d23){_0x3158d2=_0x3158d2-0x0;var _0x57c15a=_0x38fb[_0x3158d2];return _0x57c15a;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb38f('0x0'));var zipdir=require(_0xb38f('0x1'));var jsonpatch=require(_0xb38f('0x2'));var rp=require(_0xb38f('0x3'));var moment=require(_0xb38f('0x4'));var BPromise=require(_0xb38f('0x5'));var Mustache=require(_0xb38f('0x6'));var util=require(_0xb38f('0x7'));var path=require(_0xb38f('0x8'));var sox=require(_0xb38f('0x9'));var csv=require(_0xb38f('0xa'));var ejs=require(_0xb38f('0xb'));var fs=require('fs');var fs_extra=require(_0xb38f('0xc'));var _=require(_0xb38f('0xd'));var squel=require(_0xb38f('0xe'));var crypto=require(_0xb38f('0xf'));var jsforce=require(_0xb38f('0x10'));var deskjs=require(_0xb38f('0x11'));var toCsv=require(_0xb38f('0xa'));var querystring=require(_0xb38f('0x12'));var Papa=require(_0xb38f('0x13'));var Redis=require(_0xb38f('0x14'));var authService=require(_0xb38f('0x15'));var qs=require(_0xb38f('0x16'));var as=require(_0xb38f('0x17'));var hardwareService=require(_0xb38f('0x18'));var logger=require('../../config/logger')(_0xb38f('0x19'));var utils=require(_0xb38f('0x1a'));var config=require('../../config/environment');var licenseUtil=require(_0xb38f('0x1b'));var db=require(_0xb38f('0x1c'))['db'];function respondWithStatusCode(_0x126951,_0x5ac843){_0x5ac843=_0x5ac843||0xcc;return function(_0x7361b3){if(_0x7361b3){return _0x126951[_0xb38f('0x1d')](_0x5ac843);}return _0x126951[_0xb38f('0x1e')](_0x5ac843)['end']();};}function respondWithResult(_0x37a5a1,_0x33e91b){_0x33e91b=_0x33e91b||0xc8;return function(_0x50eb20){if(_0x50eb20){return _0x37a5a1[_0xb38f('0x1e')](_0x33e91b)[_0xb38f('0x1f')](_0x50eb20);}};}function respondWithFilteredResult(_0x3ac6e3,_0x1f4a38){return function(_0x196ea8){if(_0x196ea8){var _0x5880c7=typeof _0x1f4a38[_0xb38f('0x20')]==='undefined'&&typeof _0x1f4a38[_0xb38f('0x21')]===_0xb38f('0x22');var _0x5afe98=_0x196ea8[_0xb38f('0x23')];var _0x1bf61e=_0x5880c7?0x0:_0x1f4a38[_0xb38f('0x20')];var _0xeaddfa=_0x5880c7?_0x196ea8['count']:_0x1f4a38[_0xb38f('0x20')]+_0x1f4a38[_0xb38f('0x21')];var _0x31304f;if(_0xeaddfa>=_0x5afe98){_0xeaddfa=_0x5afe98;_0x31304f=0xc8;}else{_0x31304f=0xce;}_0x3ac6e3[_0xb38f('0x1e')](_0x31304f);return _0x3ac6e3[_0xb38f('0x24')]('Content-Range',_0x1bf61e+'-'+_0xeaddfa+'/'+_0x5afe98)[_0xb38f('0x1f')](_0x196ea8);}return null;};}function patchUpdates(_0x1a4a11){return function(_0x33a6f8){try{jsonpatch[_0xb38f('0x25')](_0x33a6f8,_0x1a4a11,!![]);}catch(_0xc18be4){return BPromise[_0xb38f('0x26')](_0xc18be4);}return _0x33a6f8[_0xb38f('0x27')]();};}function saveUpdates(_0x5dd9f0,_0x498d98){return function(_0x22a1e5){if(_0x22a1e5){return _0x22a1e5[_0xb38f('0x28')](_0x5dd9f0)[_0xb38f('0x29')](function(_0x3d8ab9){return _0x3d8ab9;});}return null;};}function removeEntity(_0x4dc9ba,_0x943a07){return function(_0x31e5e5){if(_0x31e5e5){return _0x31e5e5[_0xb38f('0x2a')]()[_0xb38f('0x29')](function(){_0x4dc9ba[_0xb38f('0x1e')](0xcc)[_0xb38f('0x2b')]();});}};}function handleEntityNotFound(_0x1d642a,_0x5e7a2c){return function(_0xcfcdb6){if(!_0xcfcdb6){_0x1d642a[_0xb38f('0x1d')](0x194);}return _0xcfcdb6;};}function handleError(_0x3f1e83,_0x3e746d){_0x3e746d=_0x3e746d||0x1f4;return function(_0x1ba44e){logger[_0xb38f('0x2c')](_0x1ba44e['stack']);if(_0x1ba44e[_0xb38f('0x2d')]){delete _0x1ba44e[_0xb38f('0x2d')];}_0x3f1e83[_0xb38f('0x1e')](_0x3e746d)[_0xb38f('0x2e')](_0x1ba44e);};}exports[_0xb38f('0x2f')]=function(_0xe332df,_0x243f84){var _0x563495={},_0x8f486b={},_0x2a1313={'count':0x0,'rows':[]};var _0x17e27e=_[_0xb38f('0x30')](db['JscriptyQuestionReport'][_0xb38f('0x31')],function(_0x1820a6){return{'name':_0x1820a6[_0xb38f('0x32')],'type':_0x1820a6[_0xb38f('0x33')]['key']};});_0x8f486b[_0xb38f('0x34')]=_[_0xb38f('0x30')](_0x17e27e,'name');_0x8f486b[_0xb38f('0x35')]=_['keys'](_0xe332df[_0xb38f('0x35')]);_0x8f486b[_0xb38f('0x36')]=_[_0xb38f('0x37')](_0x8f486b[_0xb38f('0x34')],_0x8f486b[_0xb38f('0x35')]);_0x563495[_0xb38f('0x38')]=_[_0xb38f('0x37')](_0x8f486b[_0xb38f('0x34')],qs[_0xb38f('0x39')](_0xe332df['query'][_0xb38f('0x39')]));_0x563495['attributes']=_0x563495['attributes']['length']?_0x563495[_0xb38f('0x38')]:_0x8f486b[_0xb38f('0x34')];if(!_0xe332df[_0xb38f('0x35')]['hasOwnProperty']('nolimit')){_0x563495[_0xb38f('0x21')]=qs[_0xb38f('0x21')](_0xe332df[_0xb38f('0x35')][_0xb38f('0x21')]);_0x563495[_0xb38f('0x20')]=qs[_0xb38f('0x20')](_0xe332df[_0xb38f('0x35')][_0xb38f('0x20')]);}_0x563495['order']=qs['sort'](_0xe332df[_0xb38f('0x35')][_0xb38f('0x3a')]);_0x563495[_0xb38f('0x3b')]=qs[_0xb38f('0x36')](_[_0xb38f('0x3c')](_0xe332df[_0xb38f('0x35')],_0x8f486b['filters']),_0x17e27e);if(_0xe332df['query']['filter']){_0x563495[_0xb38f('0x3b')]=_[_0xb38f('0x3d')](_0x563495['where'],{'$or':_[_0xb38f('0x30')](_0x17e27e,function(_0x19e971){if(_0x19e971[_0xb38f('0x33')]!==_0xb38f('0x3e')){var _0x179afa={};_0x179afa[_0x19e971[_0xb38f('0x2d')]]={'$like':'%'+_0xe332df[_0xb38f('0x35')][_0xb38f('0x3f')]+'%'};return _0x179afa;}})});}_0x563495=_[_0xb38f('0x3d')]({},_0x563495,_0xe332df[_0xb38f('0x40')]);var _0x16253c={'where':_0x563495[_0xb38f('0x3b')]};return db[_0xb38f('0x41')][_0xb38f('0x23')](_0x16253c)[_0xb38f('0x29')](function(_0x5f2d9){_0x2a1313[_0xb38f('0x23')]=_0x5f2d9;if(_0xe332df[_0xb38f('0x35')][_0xb38f('0x42')]){_0x563495[_0xb38f('0x43')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xb38f('0x44')](_0x563495);})[_0xb38f('0x29')](function(_0x3a0942){_0x2a1313['rows']=_0x3a0942;return _0x2a1313;})['then'](respondWithFilteredResult(_0x243f84,_0x563495))[_0xb38f('0x45')](handleError(_0x243f84,null));};exports[_0xb38f('0x46')]=function(_0x556639,_0x3b48bf){var _0x32d2a6={'raw':!![],'where':{'id':_0x556639[_0xb38f('0x47')]['id']}},_0x305827={};_0x305827['model']=_[_0xb38f('0x48')](db[_0xb38f('0x41')][_0xb38f('0x31')]);_0x305827[_0xb38f('0x35')]=_[_0xb38f('0x48')](_0x556639['query']);_0x305827[_0xb38f('0x36')]=_[_0xb38f('0x37')](_0x305827[_0xb38f('0x34')],_0x305827[_0xb38f('0x35')]);_0x32d2a6['attributes']=_[_0xb38f('0x37')](_0x305827[_0xb38f('0x34')],qs[_0xb38f('0x39')](_0x556639[_0xb38f('0x35')]['fields']));_0x32d2a6['attributes']=_0x32d2a6['attributes'][_0xb38f('0x49')]?_0x32d2a6['attributes']:_0x305827['model'];if(_0x556639[_0xb38f('0x35')][_0xb38f('0x42')]){_0x32d2a6[_0xb38f('0x43')]=[{'all':!![]}];}_0x32d2a6=_['merge']({},_0x32d2a6,_0x556639[_0xb38f('0x40')]);return db[_0xb38f('0x41')]['find'](_0x32d2a6)[_0xb38f('0x29')](handleEntityNotFound(_0x3b48bf,null))['then'](respondWithResult(_0x3b48bf,null))[_0xb38f('0x45')](handleError(_0x3b48bf,null));};exports['create']=function(_0x750b8d,_0x38b477){return db[_0xb38f('0x41')][_0xb38f('0x4a')](_0x750b8d[_0xb38f('0x4b')],{})['then'](respondWithResult(_0x38b477,0xc9))['catch'](handleError(_0x38b477,null));};exports['update']=function(_0x26b405,_0x275d47){if(_0x26b405[_0xb38f('0x4b')]['id']){delete _0x26b405[_0xb38f('0x4b')]['id'];}return db[_0xb38f('0x41')][_0xb38f('0x4c')]({'where':{'id':_0x26b405[_0xb38f('0x47')]['id']}})[_0xb38f('0x29')](handleEntityNotFound(_0x275d47,null))['then'](saveUpdates(_0x26b405['body'],null))['then'](respondWithResult(_0x275d47,null))[_0xb38f('0x45')](handleError(_0x275d47,null));};exports[_0xb38f('0x2a')]=function(_0x2ebdf0,_0x538fac){return db['JscriptyQuestionReport']['find']({'where':{'id':_0x2ebdf0[_0xb38f('0x47')]['id']}})[_0xb38f('0x29')](handleEntityNotFound(_0x538fac,null))[_0xb38f('0x29')](removeEntity(_0x538fac,null))['catch'](handleError(_0x538fac,null));};exports[_0xb38f('0x4d')]=function(_0x5da861,_0x18428e){return db['JscriptyQuestionReport']['describe']()[_0xb38f('0x29')](respondWithResult(_0x18428e,null))[_0xb38f('0x45')](handleError(_0x18428e,null));};