Built motion from commit (unavailable).|2.5.25
[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 _0x7f9b=['desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','json','offset','limit','set','Content-Range','reject','save','then','destroy','status','end','error','stack','name','send','index','map','fieldName','type','key','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','filters','pick','filter','where','merge','VIRTUAL','options','JscriptyQuestionReport','count','includeAll','include','findAll','rows','catch','show','params','rawAttributes','keys','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto'];(function(_0x4c7fb5,_0x2548ef){var _0x2e10ac=function(_0xf7e27c){while(--_0xf7e27c){_0x4c7fb5['push'](_0x4c7fb5['shift']());}};_0x2e10ac(++_0x2548ef);}(_0x7f9b,0xd8));var _0xb7f9=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x7f9b[_0x3dd15e];return _0x231fd0;};'use strict';var pdf=require(_0xb7f9('0x0'));var emlformat=require(_0xb7f9('0x1'));var rimraf=require(_0xb7f9('0x2'));var zipdir=require(_0xb7f9('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb7f9('0x4'));var moment=require(_0xb7f9('0x5'));var BPromise=require(_0xb7f9('0x6'));var Mustache=require(_0xb7f9('0x7'));var util=require(_0xb7f9('0x8'));var path=require('path');var sox=require(_0xb7f9('0x9'));var csv=require(_0xb7f9('0xa'));var ejs=require(_0xb7f9('0xb'));var fs=require('fs');var _=require(_0xb7f9('0xc'));var squel=require(_0xb7f9('0xd'));var crypto=require(_0xb7f9('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xb7f9('0xf'));var toCsv=require(_0xb7f9('0xa'));var querystring=require('querystring');var Papa=require(_0xb7f9('0x10'));var Redis=require('ioredis');var authService=require(_0xb7f9('0x11'));var qs=require(_0xb7f9('0x12'));var as=require(_0xb7f9('0x13'));var hardwareService=require(_0xb7f9('0x14'));var logger=require(_0xb7f9('0x15'))('api');var utils=require('../../config/utils');var config=require(_0xb7f9('0x16'));var licenseUtil=require(_0xb7f9('0x17'));var db=require(_0xb7f9('0x18'))['db'];function respondWithStatusCode(_0x2bab02,_0x2e2777){_0x2e2777=_0x2e2777||0xcc;return function(_0x26ac7c){if(_0x26ac7c){return _0x2bab02[_0xb7f9('0x19')](_0x2e2777);}return _0x2bab02['status'](_0x2e2777)['end']();};}function respondWithResult(_0x125efc,_0x4486fe){_0x4486fe=_0x4486fe||0xc8;return function(_0x4c33c6){if(_0x4c33c6){return _0x125efc['status'](_0x4486fe)[_0xb7f9('0x1a')](_0x4c33c6);}};}function respondWithFilteredResult(_0x1fd79a,_0x25ed39){return function(_0x56c7ad){if(_0x56c7ad){var _0x3f5edd=_0x56c7ad['count'],_0x42f6a4=_0x25ed39[_0xb7f9('0x1b')],_0x526970=_0x25ed39[_0xb7f9('0x1b')]+_0x25ed39[_0xb7f9('0x1c')],_0x1870b7;if(_0x526970>=_0x3f5edd){_0x526970=_0x3f5edd;_0x1870b7=0xc8;}else{_0x1870b7=0xce;}_0x1fd79a['status'](_0x1870b7);return _0x1fd79a[_0xb7f9('0x1d')](_0xb7f9('0x1e'),_0x42f6a4+'-'+_0x526970+'/'+_0x3f5edd)['json'](_0x56c7ad);}return null;};}function patchUpdates(_0x51e677){return function(_0x3c001f){try{jsonpatch['apply'](_0x3c001f,_0x51e677,!![]);}catch(_0x2cd470){return BPromise[_0xb7f9('0x1f')](_0x2cd470);}return _0x3c001f[_0xb7f9('0x20')]();};}function saveUpdates(_0x42bba1,_0x3c6e34){return function(_0x29be49){if(_0x29be49){return _0x29be49['update'](_0x42bba1)[_0xb7f9('0x21')](function(_0x1d702b){return _0x1d702b;});}return null;};}function removeEntity(_0x1c2ec2,_0x35786e){return function(_0x3ed534){if(_0x3ed534){return _0x3ed534[_0xb7f9('0x22')]()[_0xb7f9('0x21')](function(){_0x1c2ec2[_0xb7f9('0x23')](0xcc)[_0xb7f9('0x24')]();});}};}function handleEntityNotFound(_0x4c210d,_0x2d6f99){return function(_0xafcf5a){if(!_0xafcf5a){_0x4c210d[_0xb7f9('0x19')](0x194);}return _0xafcf5a;};}function handleError(_0x21af3b,_0x520c0c){_0x520c0c=_0x520c0c||0x1f4;return function(_0x324a35){logger[_0xb7f9('0x25')](_0x324a35[_0xb7f9('0x26')]);if(_0x324a35[_0xb7f9('0x27')]){delete _0x324a35['name'];}_0x21af3b[_0xb7f9('0x23')](_0x520c0c)[_0xb7f9('0x28')](_0x324a35);};}exports[_0xb7f9('0x29')]=function(_0x58d1d2,_0x118719){var _0x1eb7df={},_0x20fd30={},_0x40d56a={'count':0x0,'rows':[]};var _0x14ca3a=_[_0xb7f9('0x2a')](db['JscriptyQuestionReport']['rawAttributes'],function(_0x8f7424){return{'name':_0x8f7424[_0xb7f9('0x2b')],'type':_0x8f7424[_0xb7f9('0x2c')][_0xb7f9('0x2d')]};});_0x20fd30['model']=_[_0xb7f9('0x2a')](_0x14ca3a,_0xb7f9('0x27'));_0x20fd30[_0xb7f9('0x2e')]=_['keys'](_0x58d1d2[_0xb7f9('0x2e')]);_0x20fd30['filters']=_[_0xb7f9('0x2f')](_0x20fd30[_0xb7f9('0x30')],_0x20fd30['query']);_0x1eb7df[_0xb7f9('0x31')]=_[_0xb7f9('0x2f')](_0x20fd30[_0xb7f9('0x30')],qs[_0xb7f9('0x32')](_0x58d1d2[_0xb7f9('0x2e')][_0xb7f9('0x32')]));_0x1eb7df[_0xb7f9('0x31')]=_0x1eb7df[_0xb7f9('0x31')][_0xb7f9('0x33')]?_0x1eb7df[_0xb7f9('0x31')]:_0x20fd30['model'];if(!_0x58d1d2[_0xb7f9('0x2e')][_0xb7f9('0x34')](_0xb7f9('0x35'))){_0x1eb7df[_0xb7f9('0x1c')]=qs[_0xb7f9('0x1c')](_0x58d1d2['query'][_0xb7f9('0x1c')]);_0x1eb7df[_0xb7f9('0x1b')]=qs['offset'](_0x58d1d2['query'][_0xb7f9('0x1b')]);}_0x1eb7df['order']=qs[_0xb7f9('0x36')](_0x58d1d2[_0xb7f9('0x2e')][_0xb7f9('0x36')]);_0x1eb7df['where']=qs[_0xb7f9('0x37')](_[_0xb7f9('0x38')](_0x58d1d2[_0xb7f9('0x2e')],_0x20fd30['filters']),_0x14ca3a);if(_0x58d1d2[_0xb7f9('0x2e')][_0xb7f9('0x39')]){_0x1eb7df[_0xb7f9('0x3a')]=_[_0xb7f9('0x3b')](_0x1eb7df[_0xb7f9('0x3a')],{'$or':_[_0xb7f9('0x2a')](_0x14ca3a,function(_0x32dfff){if(_0x32dfff[_0xb7f9('0x2c')]!==_0xb7f9('0x3c')){var _0x5ad6c3={};_0x5ad6c3[_0x32dfff[_0xb7f9('0x27')]]={'$like':'%'+_0x58d1d2[_0xb7f9('0x2e')][_0xb7f9('0x39')]+'%'};return _0x5ad6c3;}})});}_0x1eb7df=_['merge']({},_0x1eb7df,_0x58d1d2[_0xb7f9('0x3d')]);var _0x5b1042={'where':_0x1eb7df[_0xb7f9('0x3a')]};return db[_0xb7f9('0x3e')][_0xb7f9('0x3f')](_0x5b1042)[_0xb7f9('0x21')](function(_0x5814ae){_0x40d56a[_0xb7f9('0x3f')]=_0x5814ae;if(_0x58d1d2[_0xb7f9('0x2e')][_0xb7f9('0x40')]){_0x1eb7df[_0xb7f9('0x41')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xb7f9('0x42')](_0x1eb7df);})[_0xb7f9('0x21')](function(_0x115d6d){_0x40d56a[_0xb7f9('0x43')]=_0x115d6d;return _0x40d56a;})['then'](respondWithFilteredResult(_0x118719,_0x1eb7df))[_0xb7f9('0x44')](handleError(_0x118719,null));};exports[_0xb7f9('0x45')]=function(_0x5968f2,_0x98268a){var _0x5dc8d8={'raw':!![],'where':{'id':_0x5968f2[_0xb7f9('0x46')]['id']}},_0x5ae0d4={};_0x5ae0d4['model']=_['keys'](db['JscriptyQuestionReport'][_0xb7f9('0x47')]);_0x5ae0d4[_0xb7f9('0x2e')]=_[_0xb7f9('0x48')](_0x5968f2[_0xb7f9('0x2e')]);_0x5ae0d4[_0xb7f9('0x37')]=_[_0xb7f9('0x2f')](_0x5ae0d4['model'],_0x5ae0d4[_0xb7f9('0x2e')]);_0x5dc8d8[_0xb7f9('0x31')]=_['intersection'](_0x5ae0d4['model'],qs[_0xb7f9('0x32')](_0x5968f2[_0xb7f9('0x2e')]['fields']));_0x5dc8d8[_0xb7f9('0x31')]=_0x5dc8d8['attributes']['length']?_0x5dc8d8[_0xb7f9('0x31')]:_0x5ae0d4[_0xb7f9('0x30')];if(_0x5968f2[_0xb7f9('0x2e')][_0xb7f9('0x40')]){_0x5dc8d8[_0xb7f9('0x41')]=[{'all':!![]}];}_0x5dc8d8=_[_0xb7f9('0x3b')]({},_0x5dc8d8,_0x5968f2[_0xb7f9('0x3d')]);return db[_0xb7f9('0x3e')][_0xb7f9('0x49')](_0x5dc8d8)['then'](handleEntityNotFound(_0x98268a,null))[_0xb7f9('0x21')](respondWithResult(_0x98268a,null))[_0xb7f9('0x44')](handleError(_0x98268a,null));};exports[_0xb7f9('0x4a')]=function(_0x23e0a1,_0x41b47c){return db[_0xb7f9('0x3e')][_0xb7f9('0x4a')](_0x23e0a1[_0xb7f9('0x4b')],{})['then'](respondWithResult(_0x41b47c,0xc9))[_0xb7f9('0x44')](handleError(_0x41b47c,null));};exports['update']=function(_0x44be03,_0x669d3f){if(_0x44be03[_0xb7f9('0x4b')]['id']){delete _0x44be03[_0xb7f9('0x4b')]['id'];}return db['JscriptyQuestionReport']['find']({'where':{'id':_0x44be03['params']['id']}})['then'](handleEntityNotFound(_0x669d3f,null))['then'](saveUpdates(_0x44be03[_0xb7f9('0x4b')],null))[_0xb7f9('0x21')](respondWithResult(_0x669d3f,null))[_0xb7f9('0x44')](handleError(_0x669d3f,null));};exports[_0xb7f9('0x22')]=function(_0x545358,_0x45f41c){return db[_0xb7f9('0x3e')][_0xb7f9('0x49')]({'where':{'id':_0x545358[_0xb7f9('0x46')]['id']}})['then'](handleEntityNotFound(_0x45f41c,null))['then'](removeEntity(_0x45f41c,null))[_0xb7f9('0x44')](handleError(_0x45f41c,null));};exports[_0xb7f9('0x4c')]=function(_0x575f6d,_0x2f111a){return db[_0xb7f9('0x3e')][_0xb7f9('0x4c')]()[_0xb7f9('0x21')](respondWithResult(_0x2f111a,null))[_0xb7f9('0x44')](handleError(_0x2f111a,null));};