Built motion from commit (unavailable).|2.5.14
[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 _0x41ff=['hasOwnProperty','nolimit','order','sort','where','filter','merge','options','JscriptyQuestionReport','includeAll','include','findAll','rows','show','params','find','catch','create','body','describe','html-pdf','eml-format','fast-json-patch','moment','bluebird','mustache','util','path','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../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','save','update','then','destroy','error','name','send','fieldName','key','map','query','filters','attributes','intersection','model','fields','length'];(function(_0x5546aa,_0x44fdaa){var _0x1f11b2=function(_0x5be4b4){while(--_0x5be4b4){_0x5546aa['push'](_0x5546aa['shift']());}};_0x1f11b2(++_0x44fdaa);}(_0x41ff,0x181));var _0xf41f=function(_0x5976ed,_0x2e1bb7){_0x5976ed=_0x5976ed-0x0;var _0x31b613=_0x41ff[_0x5976ed];return _0x31b613;};'use strict';var pdf=require(_0xf41f('0x0'));var emlformat=require(_0xf41f('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf41f('0x2'));var rp=require('request-promise');var moment=require(_0xf41f('0x3'));var BPromise=require(_0xf41f('0x4'));var Mustache=require(_0xf41f('0x5'));var util=require(_0xf41f('0x6'));var path=require(_0xf41f('0x7'));var sox=require('sox');var csv=require(_0xf41f('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xf41f('0x9'));var crypto=require(_0xf41f('0xa'));var jsforce=require(_0xf41f('0xb'));var deskjs=require(_0xf41f('0xc'));var toCsv=require('to-csv');var querystring=require(_0xf41f('0xd'));var Papa=require(_0xf41f('0xe'));var Redis=require(_0xf41f('0xf'));var authService=require(_0xf41f('0x10'));var qs=require(_0xf41f('0x11'));var as=require(_0xf41f('0x12'));var hardwareService=require(_0xf41f('0x13'));var logger=require(_0xf41f('0x14'))(_0xf41f('0x15'));var utils=require(_0xf41f('0x16'));var config=require(_0xf41f('0x17'));var licenseUtil=require(_0xf41f('0x18'));var db=require(_0xf41f('0x19'))['db'];function respondWithStatusCode(_0x1777cb,_0x3936c1){_0x3936c1=_0x3936c1||0xcc;return function(_0x4ab512){if(_0x4ab512){return _0x1777cb[_0xf41f('0x1a')](_0x3936c1);}return _0x1777cb[_0xf41f('0x1b')](_0x3936c1)[_0xf41f('0x1c')]();};}function respondWithResult(_0x5c181f,_0x58b871){_0x58b871=_0x58b871||0xc8;return function(_0x3ede8b){if(_0x3ede8b){return _0x5c181f[_0xf41f('0x1b')](_0x58b871)[_0xf41f('0x1d')](_0x3ede8b);}};}function respondWithFilteredResult(_0x575e36,_0x6b2704){return function(_0x2b04ca){if(_0x2b04ca){var _0x44923d=_0x2b04ca[_0xf41f('0x1e')],_0x3876a9=_0x6b2704['offset'],_0x303c24=_0x6b2704[_0xf41f('0x1f')]+_0x6b2704[_0xf41f('0x20')],_0x5a555f;if(_0x303c24>=_0x44923d){_0x303c24=_0x44923d;_0x5a555f=0xc8;}else{_0x5a555f=0xce;}_0x575e36['status'](_0x5a555f);return _0x575e36[_0xf41f('0x21')](_0xf41f('0x22'),_0x3876a9+'-'+_0x303c24+'/'+_0x44923d)['json'](_0x2b04ca);}return null;};}function patchUpdates(_0x3d7e9d){return function(_0xf85c8b){try{jsonpatch[_0xf41f('0x23')](_0xf85c8b,_0x3d7e9d,!![]);}catch(_0x26c55d){return BPromise['reject'](_0x26c55d);}return _0xf85c8b[_0xf41f('0x24')]();};}function saveUpdates(_0x56a41e,_0x499486){return function(_0x482a9d){if(_0x482a9d){return _0x482a9d[_0xf41f('0x25')](_0x56a41e)[_0xf41f('0x26')](function(_0x1f638b){return _0x1f638b;});}return null;};}function removeEntity(_0x10584d,_0x32e36d){return function(_0x2a85b3){if(_0x2a85b3){return _0x2a85b3[_0xf41f('0x27')]()[_0xf41f('0x26')](function(){_0x10584d[_0xf41f('0x1b')](0xcc)[_0xf41f('0x1c')]();});}};}function handleEntityNotFound(_0x1956f2,_0x3d7567){return function(_0x4bf3de){if(!_0x4bf3de){_0x1956f2[_0xf41f('0x1a')](0x194);}return _0x4bf3de;};}function handleError(_0x176c2c,_0x43102c){_0x43102c=_0x43102c||0x1f4;return function(_0x597971){logger[_0xf41f('0x28')](_0x597971['stack']);if(_0x597971[_0xf41f('0x29')]){delete _0x597971[_0xf41f('0x29')];}_0x176c2c[_0xf41f('0x1b')](_0x43102c)[_0xf41f('0x2a')](_0x597971);};}exports['index']=function(_0x466f34,_0x5de415){var _0x23de05={},_0x4b0af1={},_0x512c6c={'count':0x0,'rows':[]};var _0x2c1825=_['map'](db['JscriptyQuestionReport']['rawAttributes'],function(_0x12d887){return{'name':_0x12d887[_0xf41f('0x2b')],'type':_0x12d887['type'][_0xf41f('0x2c')]};});_0x4b0af1['model']=_[_0xf41f('0x2d')](_0x2c1825,_0xf41f('0x29'));_0x4b0af1[_0xf41f('0x2e')]=_['keys'](_0x466f34['query']);_0x4b0af1[_0xf41f('0x2f')]=_['intersection'](_0x4b0af1['model'],_0x4b0af1[_0xf41f('0x2e')]);_0x23de05[_0xf41f('0x30')]=_[_0xf41f('0x31')](_0x4b0af1[_0xf41f('0x32')],qs[_0xf41f('0x33')](_0x466f34[_0xf41f('0x2e')][_0xf41f('0x33')]));_0x23de05[_0xf41f('0x30')]=_0x23de05[_0xf41f('0x30')][_0xf41f('0x34')]?_0x23de05[_0xf41f('0x30')]:_0x4b0af1['model'];if(!_0x466f34[_0xf41f('0x2e')][_0xf41f('0x35')](_0xf41f('0x36'))){_0x23de05[_0xf41f('0x20')]=qs['limit'](_0x466f34[_0xf41f('0x2e')][_0xf41f('0x20')]);_0x23de05[_0xf41f('0x1f')]=qs['offset'](_0x466f34[_0xf41f('0x2e')]['offset']);}_0x23de05[_0xf41f('0x37')]=qs[_0xf41f('0x38')](_0x466f34[_0xf41f('0x2e')][_0xf41f('0x38')]);_0x23de05[_0xf41f('0x39')]=qs[_0xf41f('0x2f')](_['pick'](_0x466f34[_0xf41f('0x2e')],_0x4b0af1[_0xf41f('0x2f')]),_0x2c1825);if(_0x466f34[_0xf41f('0x2e')][_0xf41f('0x3a')]){_0x23de05[_0xf41f('0x39')]=_[_0xf41f('0x3b')](_0x23de05['where'],{'$or':_[_0xf41f('0x2d')](_0x2c1825,function(_0x5666a1){if(_0x5666a1['type']!=='VIRTUAL'){var _0x427752={};_0x427752[_0x5666a1[_0xf41f('0x29')]]={'$like':'%'+_0x466f34[_0xf41f('0x2e')][_0xf41f('0x3a')]+'%'};return _0x427752;}})});}_0x23de05=_[_0xf41f('0x3b')]({},_0x23de05,_0x466f34[_0xf41f('0x3c')]);var _0xe505f3={'where':_0x23de05['where']};return db[_0xf41f('0x3d')]['count'](_0xe505f3)['then'](function(_0x276285){_0x512c6c[_0xf41f('0x1e')]=_0x276285;if(_0x466f34['query'][_0xf41f('0x3e')]){_0x23de05[_0xf41f('0x3f')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xf41f('0x40')](_0x23de05);})[_0xf41f('0x26')](function(_0x5d8dc1){_0x512c6c[_0xf41f('0x41')]=_0x5d8dc1;return _0x512c6c;})[_0xf41f('0x26')](respondWithFilteredResult(_0x5de415,_0x23de05))['catch'](handleError(_0x5de415,null));};exports[_0xf41f('0x42')]=function(_0x594110,_0x5cec47){var _0x1a0f3d={'raw':!![],'where':{'id':_0x594110[_0xf41f('0x43')]['id']}},_0x1f3ee3={};_0x1f3ee3[_0xf41f('0x32')]=_['keys'](db[_0xf41f('0x3d')]['rawAttributes']);_0x1f3ee3[_0xf41f('0x2e')]=_['keys'](_0x594110['query']);_0x1f3ee3['filters']=_['intersection'](_0x1f3ee3[_0xf41f('0x32')],_0x1f3ee3[_0xf41f('0x2e')]);_0x1a0f3d[_0xf41f('0x30')]=_[_0xf41f('0x31')](_0x1f3ee3[_0xf41f('0x32')],qs[_0xf41f('0x33')](_0x594110[_0xf41f('0x2e')][_0xf41f('0x33')]));_0x1a0f3d[_0xf41f('0x30')]=_0x1a0f3d[_0xf41f('0x30')][_0xf41f('0x34')]?_0x1a0f3d[_0xf41f('0x30')]:_0x1f3ee3[_0xf41f('0x32')];if(_0x594110[_0xf41f('0x2e')][_0xf41f('0x3e')]){_0x1a0f3d['include']=[{'all':!![]}];}_0x1a0f3d=_['merge']({},_0x1a0f3d,_0x594110[_0xf41f('0x3c')]);return db[_0xf41f('0x3d')][_0xf41f('0x44')](_0x1a0f3d)['then'](handleEntityNotFound(_0x5cec47,null))[_0xf41f('0x26')](respondWithResult(_0x5cec47,null))[_0xf41f('0x45')](handleError(_0x5cec47,null));};exports[_0xf41f('0x46')]=function(_0x3a8bfd,_0x1a9168){return db[_0xf41f('0x3d')][_0xf41f('0x46')](_0x3a8bfd['body'],{})['then'](respondWithResult(_0x1a9168,0xc9))[_0xf41f('0x45')](handleError(_0x1a9168,null));};exports['update']=function(_0x382330,_0x3837b8){if(_0x382330['body']['id']){delete _0x382330[_0xf41f('0x47')]['id'];}return db['JscriptyQuestionReport'][_0xf41f('0x44')]({'where':{'id':_0x382330[_0xf41f('0x43')]['id']}})[_0xf41f('0x26')](handleEntityNotFound(_0x3837b8,null))[_0xf41f('0x26')](saveUpdates(_0x382330['body'],null))[_0xf41f('0x26')](respondWithResult(_0x3837b8,null))['catch'](handleError(_0x3837b8,null));};exports[_0xf41f('0x27')]=function(_0x2032ae,_0x2f3c17){return db[_0xf41f('0x3d')][_0xf41f('0x44')]({'where':{'id':_0x2032ae['params']['id']}})[_0xf41f('0x26')](handleEntityNotFound(_0x2f3c17,null))['then'](removeEntity(_0x2f3c17,null))['catch'](handleError(_0x2f3c17,null));};exports['describe']=function(_0xf98422,_0x59fcc8){return db[_0xf41f('0x3d')][_0xf41f('0x48')]()[_0xf41f('0x26')](respondWithResult(_0x59fcc8,null))[_0xf41f('0x45')](handleError(_0x59fcc8,null));};