e328ae324a1e7b40cce756aed9c8ac7e5c1aac4b
[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 _0xbb22=['catch','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','offset','count','limit','set','Content-Range','json','apply','reject','update','then','destroy','end','error','stack','name','send','index','map','JscriptyQuestionReport','rawAttributes','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','include','find'];(function(_0x2fd481,_0x5f11de){var _0x4cf32f=function(_0x4afae4){while(--_0x4afae4){_0x2fd481['push'](_0x2fd481['shift']());}};_0x4cf32f(++_0x5f11de);}(_0xbb22,0xe8));var _0x2bb2=function(_0x1a7eff,_0x3c4d2c){_0x1a7eff=_0x1a7eff-0x0;var _0x5e9e63=_0xbb22[_0x1a7eff];return _0x5e9e63;};'use strict';var emlformat=require(_0x2bb2('0x0'));var rimraf=require(_0x2bb2('0x1'));var zipdir=require(_0x2bb2('0x2'));var jsonpatch=require(_0x2bb2('0x3'));var rp=require(_0x2bb2('0x4'));var moment=require(_0x2bb2('0x5'));var BPromise=require(_0x2bb2('0x6'));var Mustache=require(_0x2bb2('0x7'));var util=require(_0x2bb2('0x8'));var path=require(_0x2bb2('0x9'));var sox=require(_0x2bb2('0xa'));var csv=require(_0x2bb2('0xb'));var ejs=require(_0x2bb2('0xc'));var fs=require('fs');var fs_extra=require(_0x2bb2('0xd'));var _=require('lodash');var squel=require(_0x2bb2('0xe'));var crypto=require(_0x2bb2('0xf'));var jsforce=require(_0x2bb2('0x10'));var deskjs=require(_0x2bb2('0x11'));var toCsv=require(_0x2bb2('0xb'));var querystring=require(_0x2bb2('0x12'));var Papa=require(_0x2bb2('0x13'));var Redis=require(_0x2bb2('0x14'));var authService=require('../../components/auth/service');var qs=require(_0x2bb2('0x15'));var as=require(_0x2bb2('0x16'));var hardwareService=require(_0x2bb2('0x17'));var logger=require(_0x2bb2('0x18'))('api');var utils=require(_0x2bb2('0x19'));var config=require(_0x2bb2('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0x2bb2('0x1b'))['db'];function respondWithStatusCode(_0x34cf9c,_0x4f3a2a){_0x4f3a2a=_0x4f3a2a||0xcc;return function(_0x4c9810){if(_0x4c9810){return _0x34cf9c[_0x2bb2('0x1c')](_0x4f3a2a);}return _0x34cf9c[_0x2bb2('0x1d')](_0x4f3a2a)['end']();};}function respondWithResult(_0x19db69,_0x9b1865){_0x9b1865=_0x9b1865||0xc8;return function(_0x20b757){if(_0x20b757){return _0x19db69[_0x2bb2('0x1d')](_0x9b1865)['json'](_0x20b757);}};}function respondWithFilteredResult(_0x535ca9,_0x22f1eb){return function(_0x1b04ac){if(_0x1b04ac){var _0x5b983c=typeof _0x22f1eb[_0x2bb2('0x1e')]==='undefined'&&typeof _0x22f1eb['limit']==='undefined';var _0x20ebce=_0x1b04ac[_0x2bb2('0x1f')];var _0x4dfd62=_0x5b983c?0x0:_0x22f1eb['offset'];var _0x87cd04=_0x5b983c?_0x1b04ac[_0x2bb2('0x1f')]:_0x22f1eb['offset']+_0x22f1eb[_0x2bb2('0x20')];var _0x23f253;if(_0x87cd04>=_0x20ebce){_0x87cd04=_0x20ebce;_0x23f253=0xc8;}else{_0x23f253=0xce;}_0x535ca9['status'](_0x23f253);return _0x535ca9[_0x2bb2('0x21')](_0x2bb2('0x22'),_0x4dfd62+'-'+_0x87cd04+'/'+_0x20ebce)[_0x2bb2('0x23')](_0x1b04ac);}return null;};}function patchUpdates(_0x57df82){return function(_0x3fd04f){try{jsonpatch[_0x2bb2('0x24')](_0x3fd04f,_0x57df82,!![]);}catch(_0x577eef){return BPromise[_0x2bb2('0x25')](_0x577eef);}return _0x3fd04f['save']();};}function saveUpdates(_0x111353,_0x207518){return function(_0x3e5b5c){if(_0x3e5b5c){return _0x3e5b5c[_0x2bb2('0x26')](_0x111353)[_0x2bb2('0x27')](function(_0x188c04){return _0x188c04;});}return null;};}function removeEntity(_0x801a4c,_0x11073a){return function(_0x416540){if(_0x416540){return _0x416540[_0x2bb2('0x28')]()[_0x2bb2('0x27')](function(){_0x801a4c['status'](0xcc)[_0x2bb2('0x29')]();});}};}function handleEntityNotFound(_0x4074a3,_0x5f75df){return function(_0x10c31b){if(!_0x10c31b){_0x4074a3[_0x2bb2('0x1c')](0x194);}return _0x10c31b;};}function handleError(_0x46c299,_0x3eba55){_0x3eba55=_0x3eba55||0x1f4;return function(_0x32d17b){logger[_0x2bb2('0x2a')](_0x32d17b[_0x2bb2('0x2b')]);if(_0x32d17b[_0x2bb2('0x2c')]){delete _0x32d17b[_0x2bb2('0x2c')];}_0x46c299[_0x2bb2('0x1d')](_0x3eba55)[_0x2bb2('0x2d')](_0x32d17b);};}exports[_0x2bb2('0x2e')]=function(_0x53fcb4,_0x2370a4){var _0x17ff47={},_0x5104a1={},_0x31bdaa={'count':0x0,'rows':[]};var _0x46707e=_[_0x2bb2('0x2f')](db[_0x2bb2('0x30')][_0x2bb2('0x31')],function(_0x3c9c7a){return{'name':_0x3c9c7a[_0x2bb2('0x32')],'type':_0x3c9c7a[_0x2bb2('0x33')][_0x2bb2('0x34')]};});_0x5104a1[_0x2bb2('0x35')]=_[_0x2bb2('0x2f')](_0x46707e,'name');_0x5104a1[_0x2bb2('0x36')]=_['keys'](_0x53fcb4[_0x2bb2('0x36')]);_0x5104a1[_0x2bb2('0x37')]=_[_0x2bb2('0x38')](_0x5104a1[_0x2bb2('0x35')],_0x5104a1['query']);_0x17ff47['attributes']=_[_0x2bb2('0x38')](_0x5104a1['model'],qs['fields'](_0x53fcb4[_0x2bb2('0x36')][_0x2bb2('0x39')]));_0x17ff47[_0x2bb2('0x3a')]=_0x17ff47['attributes'][_0x2bb2('0x3b')]?_0x17ff47[_0x2bb2('0x3a')]:_0x5104a1[_0x2bb2('0x35')];if(!_0x53fcb4[_0x2bb2('0x36')][_0x2bb2('0x3c')](_0x2bb2('0x3d'))){_0x17ff47[_0x2bb2('0x20')]=qs[_0x2bb2('0x20')](_0x53fcb4[_0x2bb2('0x36')][_0x2bb2('0x20')]);_0x17ff47[_0x2bb2('0x1e')]=qs[_0x2bb2('0x1e')](_0x53fcb4['query'][_0x2bb2('0x1e')]);}_0x17ff47[_0x2bb2('0x3e')]=qs[_0x2bb2('0x3f')](_0x53fcb4[_0x2bb2('0x36')][_0x2bb2('0x3f')]);_0x17ff47[_0x2bb2('0x40')]=qs[_0x2bb2('0x37')](_['pick'](_0x53fcb4[_0x2bb2('0x36')],_0x5104a1['filters']),_0x46707e);if(_0x53fcb4['query'][_0x2bb2('0x41')]){_0x17ff47['where']=_[_0x2bb2('0x42')](_0x17ff47[_0x2bb2('0x40')],{'$or':_[_0x2bb2('0x2f')](_0x46707e,function(_0x151205){if(_0x151205[_0x2bb2('0x33')]!==_0x2bb2('0x43')){var _0x398d29={};_0x398d29[_0x151205[_0x2bb2('0x2c')]]={'$like':'%'+_0x53fcb4[_0x2bb2('0x36')][_0x2bb2('0x41')]+'%'};return _0x398d29;}})});}_0x17ff47=_[_0x2bb2('0x42')]({},_0x17ff47,_0x53fcb4[_0x2bb2('0x44')]);var _0x22aac8={'where':_0x17ff47[_0x2bb2('0x40')]};return db['JscriptyQuestionReport'][_0x2bb2('0x1f')](_0x22aac8)[_0x2bb2('0x27')](function(_0x2ee3ab){_0x31bdaa['count']=_0x2ee3ab;if(_0x53fcb4['query'][_0x2bb2('0x45')]){_0x17ff47[_0x2bb2('0x46')]=[{'all':!![]}];}return db['JscriptyQuestionReport']['findAll'](_0x17ff47);})[_0x2bb2('0x27')](function(_0x183ddf){_0x31bdaa['rows']=_0x183ddf;return _0x31bdaa;})[_0x2bb2('0x27')](respondWithFilteredResult(_0x2370a4,_0x17ff47))['catch'](handleError(_0x2370a4,null));};exports['show']=function(_0x5f05fb,_0x6a1d14){var _0x2854c0={'raw':!![],'where':{'id':_0x5f05fb['params']['id']}},_0x3032a3={};_0x3032a3[_0x2bb2('0x35')]=_['keys'](db[_0x2bb2('0x30')]['rawAttributes']);_0x3032a3['query']=_['keys'](_0x5f05fb[_0x2bb2('0x36')]);_0x3032a3['filters']=_[_0x2bb2('0x38')](_0x3032a3['model'],_0x3032a3['query']);_0x2854c0['attributes']=_[_0x2bb2('0x38')](_0x3032a3['model'],qs[_0x2bb2('0x39')](_0x5f05fb[_0x2bb2('0x36')][_0x2bb2('0x39')]));_0x2854c0[_0x2bb2('0x3a')]=_0x2854c0[_0x2bb2('0x3a')]['length']?_0x2854c0[_0x2bb2('0x3a')]:_0x3032a3[_0x2bb2('0x35')];if(_0x5f05fb[_0x2bb2('0x36')][_0x2bb2('0x45')]){_0x2854c0[_0x2bb2('0x46')]=[{'all':!![]}];}_0x2854c0=_[_0x2bb2('0x42')]({},_0x2854c0,_0x5f05fb[_0x2bb2('0x44')]);return db[_0x2bb2('0x30')][_0x2bb2('0x47')](_0x2854c0)[_0x2bb2('0x27')](handleEntityNotFound(_0x6a1d14,null))['then'](respondWithResult(_0x6a1d14,null))[_0x2bb2('0x48')](handleError(_0x6a1d14,null));};exports['create']=function(_0xc0beeb,_0xf627db){return db[_0x2bb2('0x30')]['create'](_0xc0beeb[_0x2bb2('0x49')],{})['then'](respondWithResult(_0xf627db,0xc9))[_0x2bb2('0x48')](handleError(_0xf627db,null));};exports[_0x2bb2('0x26')]=function(_0x42d2a8,_0x19c2c9){if(_0x42d2a8['body']['id']){delete _0x42d2a8['body']['id'];}return db['JscriptyQuestionReport']['find']({'where':{'id':_0x42d2a8['params']['id']}})[_0x2bb2('0x27')](handleEntityNotFound(_0x19c2c9,null))[_0x2bb2('0x27')](saveUpdates(_0x42d2a8[_0x2bb2('0x49')],null))[_0x2bb2('0x27')](respondWithResult(_0x19c2c9,null))[_0x2bb2('0x48')](handleError(_0x19c2c9,null));};exports[_0x2bb2('0x28')]=function(_0x4672aa,_0x3b5f7f){return db['JscriptyQuestionReport'][_0x2bb2('0x47')]({'where':{'id':_0x4672aa[_0x2bb2('0x4a')]['id']}})[_0x2bb2('0x27')](handleEntityNotFound(_0x3b5f7f,null))[_0x2bb2('0x27')](removeEntity(_0x3b5f7f,null))[_0x2bb2('0x48')](handleError(_0x3b5f7f,null));};exports[_0x2bb2('0x4b')]=function(_0x2b7f6b,_0x3b6b79){return db[_0x2bb2('0x30')]['describe']()[_0x2bb2('0x27')](respondWithResult(_0x3b6b79,null))[_0x2bb2('0x48')](handleError(_0x3b6b79,null));};