d9a87f7faf10f784dd1db8f30ab9334d2750996f
[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 _0xa86e=['find','catch','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','end','sendStatus','stack','name','index','map','JscriptyQuestionReport','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','show'];(function(_0x53e4b5,_0x25c646){var _0xe40d4=function(_0x3ce854){while(--_0x3ce854){_0x53e4b5['push'](_0x53e4b5['shift']());}};_0xe40d4(++_0x25c646);}(_0xa86e,0x1c7));var _0xea86=function(_0x18700f,_0x2e2c4b){_0x18700f=_0x18700f-0x0;var _0x45302d=_0xa86e[_0x18700f];return _0x45302d;};'use strict';var emlformat=require(_0xea86('0x0'));var rimraf=require(_0xea86('0x1'));var zipdir=require(_0xea86('0x2'));var jsonpatch=require(_0xea86('0x3'));var rp=require(_0xea86('0x4'));var moment=require('moment');var BPromise=require(_0xea86('0x5'));var Mustache=require(_0xea86('0x6'));var util=require('util');var path=require(_0xea86('0x7'));var sox=require(_0xea86('0x8'));var csv=require(_0xea86('0x9'));var ejs=require(_0xea86('0xa'));var fs=require('fs');var fs_extra=require(_0xea86('0xb'));var _=require(_0xea86('0xc'));var squel=require(_0xea86('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xea86('0xe'));var toCsv=require('to-csv');var querystring=require(_0xea86('0xf'));var Papa=require(_0xea86('0x10'));var Redis=require('ioredis');var authService=require(_0xea86('0x11'));var qs=require(_0xea86('0x12'));var as=require(_0xea86('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xea86('0x14'));var utils=require(_0xea86('0x15'));var config=require(_0xea86('0x16'));var licenseUtil=require(_0xea86('0x17'));var db=require(_0xea86('0x18'))['db'];function respondWithStatusCode(_0x433a32,_0xc68d40){_0xc68d40=_0xc68d40||0xcc;return function(_0x4a1b0c){if(_0x4a1b0c){return _0x433a32['sendStatus'](_0xc68d40);}return _0x433a32[_0xea86('0x19')](_0xc68d40)['end']();};}function respondWithResult(_0x5c7d8f,_0x26345d){_0x26345d=_0x26345d||0xc8;return function(_0x4ccaf0){if(_0x4ccaf0){return _0x5c7d8f[_0xea86('0x19')](_0x26345d)['json'](_0x4ccaf0);}};}function respondWithFilteredResult(_0x189fea,_0x2a48c0){return function(_0xaa4458){if(_0xaa4458){var _0x14f3d0=typeof _0x2a48c0[_0xea86('0x1a')]===_0xea86('0x1b')&&typeof _0x2a48c0[_0xea86('0x1c')]===_0xea86('0x1b');var _0x4e3fe3=_0xaa4458[_0xea86('0x1d')];var _0x2c6aa0=_0x14f3d0?0x0:_0x2a48c0[_0xea86('0x1a')];var _0x418150=_0x14f3d0?_0xaa4458[_0xea86('0x1d')]:_0x2a48c0[_0xea86('0x1a')]+_0x2a48c0['limit'];var _0x21bf9e;if(_0x418150>=_0x4e3fe3){_0x418150=_0x4e3fe3;_0x21bf9e=0xc8;}else{_0x21bf9e=0xce;}_0x189fea['status'](_0x21bf9e);return _0x189fea[_0xea86('0x1e')](_0xea86('0x1f'),_0x2c6aa0+'-'+_0x418150+'/'+_0x4e3fe3)['json'](_0xaa4458);}return null;};}function patchUpdates(_0x55d54b){return function(_0x55ae60){try{jsonpatch[_0xea86('0x20')](_0x55ae60,_0x55d54b,!![]);}catch(_0x1bdf1b){return BPromise[_0xea86('0x21')](_0x1bdf1b);}return _0x55ae60[_0xea86('0x22')]();};}function saveUpdates(_0x20724a,_0x4336e1){return function(_0x4b50e4){if(_0x4b50e4){return _0x4b50e4[_0xea86('0x23')](_0x20724a)['then'](function(_0x42b2ad){return _0x42b2ad;});}return null;};}function removeEntity(_0x56490a,_0x5ea8a9){return function(_0x1bc115){if(_0x1bc115){return _0x1bc115[_0xea86('0x24')]()[_0xea86('0x25')](function(){_0x56490a['status'](0xcc)[_0xea86('0x26')]();});}};}function handleEntityNotFound(_0x142e0b,_0x4e98c5){return function(_0x57412e){if(!_0x57412e){_0x142e0b[_0xea86('0x27')](0x194);}return _0x57412e;};}function handleError(_0x1c3c71,_0x3b6c23){_0x3b6c23=_0x3b6c23||0x1f4;return function(_0x4c8a23){logger['error'](_0x4c8a23[_0xea86('0x28')]);if(_0x4c8a23[_0xea86('0x29')]){delete _0x4c8a23[_0xea86('0x29')];}_0x1c3c71[_0xea86('0x19')](_0x3b6c23)['send'](_0x4c8a23);};}exports[_0xea86('0x2a')]=function(_0x94d7d1,_0x3145c3){var _0x4d3851={},_0xd11b9={},_0x270ff1={'count':0x0,'rows':[]};var _0x5d0ab5=_[_0xea86('0x2b')](db[_0xea86('0x2c')][_0xea86('0x2d')],function(_0x5ed09b){return{'name':_0x5ed09b[_0xea86('0x2e')],'type':_0x5ed09b[_0xea86('0x2f')]['key']};});_0xd11b9['model']=_['map'](_0x5d0ab5,_0xea86('0x29'));_0xd11b9[_0xea86('0x30')]=_[_0xea86('0x31')](_0x94d7d1['query']);_0xd11b9[_0xea86('0x32')]=_[_0xea86('0x33')](_0xd11b9[_0xea86('0x34')],_0xd11b9['query']);_0x4d3851[_0xea86('0x35')]=_[_0xea86('0x33')](_0xd11b9[_0xea86('0x34')],qs[_0xea86('0x36')](_0x94d7d1[_0xea86('0x30')][_0xea86('0x36')]));_0x4d3851['attributes']=_0x4d3851[_0xea86('0x35')][_0xea86('0x37')]?_0x4d3851[_0xea86('0x35')]:_0xd11b9['model'];if(!_0x94d7d1[_0xea86('0x30')][_0xea86('0x38')](_0xea86('0x39'))){_0x4d3851[_0xea86('0x1c')]=qs[_0xea86('0x1c')](_0x94d7d1[_0xea86('0x30')]['limit']);_0x4d3851[_0xea86('0x1a')]=qs[_0xea86('0x1a')](_0x94d7d1['query'][_0xea86('0x1a')]);}_0x4d3851[_0xea86('0x3a')]=qs['sort'](_0x94d7d1[_0xea86('0x30')][_0xea86('0x3b')]);_0x4d3851[_0xea86('0x3c')]=qs[_0xea86('0x32')](_[_0xea86('0x3d')](_0x94d7d1['query'],_0xd11b9[_0xea86('0x32')]),_0x5d0ab5);if(_0x94d7d1[_0xea86('0x30')][_0xea86('0x3e')]){_0x4d3851[_0xea86('0x3c')]=_[_0xea86('0x3f')](_0x4d3851[_0xea86('0x3c')],{'$or':_[_0xea86('0x2b')](_0x5d0ab5,function(_0x171069){if(_0x171069[_0xea86('0x2f')]!==_0xea86('0x40')){var _0x54075a={};_0x54075a[_0x171069[_0xea86('0x29')]]={'$like':'%'+_0x94d7d1[_0xea86('0x30')][_0xea86('0x3e')]+'%'};return _0x54075a;}})});}_0x4d3851=_['merge']({},_0x4d3851,_0x94d7d1[_0xea86('0x41')]);var _0x20a9a4={'where':_0x4d3851['where']};return db[_0xea86('0x2c')][_0xea86('0x1d')](_0x20a9a4)[_0xea86('0x25')](function(_0x35f702){_0x270ff1[_0xea86('0x1d')]=_0x35f702;if(_0x94d7d1[_0xea86('0x30')][_0xea86('0x42')]){_0x4d3851[_0xea86('0x43')]=[{'all':!![]}];}return db['JscriptyQuestionReport'][_0xea86('0x44')](_0x4d3851);})[_0xea86('0x25')](function(_0x1e02bf){_0x270ff1['rows']=_0x1e02bf;return _0x270ff1;})[_0xea86('0x25')](respondWithFilteredResult(_0x3145c3,_0x4d3851))['catch'](handleError(_0x3145c3,null));};exports[_0xea86('0x45')]=function(_0x587f9c,_0x9ed255){var _0xc79708={'raw':!![],'where':{'id':_0x587f9c['params']['id']}},_0x3f196d={};_0x3f196d[_0xea86('0x34')]=_[_0xea86('0x31')](db[_0xea86('0x2c')][_0xea86('0x2d')]);_0x3f196d[_0xea86('0x30')]=_[_0xea86('0x31')](_0x587f9c['query']);_0x3f196d[_0xea86('0x32')]=_[_0xea86('0x33')](_0x3f196d[_0xea86('0x34')],_0x3f196d[_0xea86('0x30')]);_0xc79708['attributes']=_[_0xea86('0x33')](_0x3f196d[_0xea86('0x34')],qs[_0xea86('0x36')](_0x587f9c['query'][_0xea86('0x36')]));_0xc79708[_0xea86('0x35')]=_0xc79708['attributes'][_0xea86('0x37')]?_0xc79708[_0xea86('0x35')]:_0x3f196d[_0xea86('0x34')];if(_0x587f9c[_0xea86('0x30')][_0xea86('0x42')]){_0xc79708[_0xea86('0x43')]=[{'all':!![]}];}_0xc79708=_[_0xea86('0x3f')]({},_0xc79708,_0x587f9c[_0xea86('0x41')]);return db[_0xea86('0x2c')][_0xea86('0x46')](_0xc79708)[_0xea86('0x25')](handleEntityNotFound(_0x9ed255,null))[_0xea86('0x25')](respondWithResult(_0x9ed255,null))[_0xea86('0x47')](handleError(_0x9ed255,null));};exports[_0xea86('0x48')]=function(_0x30589d,_0x2eccb4){return db['JscriptyQuestionReport'][_0xea86('0x48')](_0x30589d[_0xea86('0x49')],{})[_0xea86('0x25')](respondWithResult(_0x2eccb4,0xc9))['catch'](handleError(_0x2eccb4,null));};exports[_0xea86('0x23')]=function(_0xa3c10a,_0x2c7083){if(_0xa3c10a[_0xea86('0x49')]['id']){delete _0xa3c10a['body']['id'];}return db['JscriptyQuestionReport'][_0xea86('0x46')]({'where':{'id':_0xa3c10a['params']['id']}})[_0xea86('0x25')](handleEntityNotFound(_0x2c7083,null))['then'](saveUpdates(_0xa3c10a[_0xea86('0x49')],null))[_0xea86('0x25')](respondWithResult(_0x2c7083,null))[_0xea86('0x47')](handleError(_0x2c7083,null));};exports[_0xea86('0x24')]=function(_0x26a806,_0x4733aa){return db[_0xea86('0x2c')][_0xea86('0x46')]({'where':{'id':_0x26a806['params']['id']}})[_0xea86('0x25')](handleEntityNotFound(_0x4733aa,null))[_0xea86('0x25')](removeEntity(_0x4733aa,null))[_0xea86('0x47')](handleError(_0x4733aa,null));};exports[_0xea86('0x4a')]=function(_0x149cb4,_0x2e6cb0){return db[_0xea86('0x2c')][_0xea86('0x4a')]()['then'](respondWithResult(_0x2e6cb0,null))[_0xea86('0x47')](handleError(_0x2e6cb0,null));};