1fe3ef3f5b91fbba9470d12eb4f52d2f11bfb95d
[motion2.git] / server / api / jscriptyAnswerReport / jscriptyAnswerReport.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 _0x53e4=['html-pdf','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','sendStatus','status','offset','limit','set','Content-Range','json','apply','reject','save','update','then','error','stack','name','send','index','JscriptyAnswerReport','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','order','sort','where','filter','merge','map','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','params','find','create','body','destroy','describe'];(function(_0x3ac4f1,_0x37fbef){var _0x347699=function(_0x4fb641){while(--_0x4fb641){_0x3ac4f1['push'](_0x3ac4f1['shift']());}};_0x347699(++_0x37fbef);}(_0x53e4,0xd5));var _0x453e=function(_0x18894b,_0xb20093){_0x18894b=_0x18894b-0x0;var _0x4b3230=_0x53e4[_0x18894b];return _0x4b3230;};'use strict';var pdf=require(_0x453e('0x0'));var emlformat=require(_0x453e('0x1'));var rimraf=require(_0x453e('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x453e('0x3'));var rp=require(_0x453e('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x453e('0x5'));var util=require(_0x453e('0x6'));var path=require(_0x453e('0x7'));var sox=require(_0x453e('0x8'));var csv=require('to-csv');var ejs=require(_0x453e('0x9'));var fs=require('fs');var _=require(_0x453e('0xa'));var squel=require(_0x453e('0xb'));var crypto=require(_0x453e('0xc'));var jsforce=require(_0x453e('0xd'));var deskjs=require(_0x453e('0xe'));var toCsv=require(_0x453e('0xf'));var querystring=require(_0x453e('0x10'));var Papa=require('papaparse');var Redis=require(_0x453e('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x453e('0x12'));var as=require(_0x453e('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x453e('0x14'))(_0x453e('0x15'));var utils=require('../../config/utils');var config=require(_0x453e('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3f51be,_0x269046){_0x269046=_0x269046||0xcc;return function(_0x1c9294){if(_0x1c9294){return _0x3f51be[_0x453e('0x17')](_0x269046);}return _0x3f51be['status'](_0x269046)['end']();};}function respondWithResult(_0x27a04c,_0x52c97b){_0x52c97b=_0x52c97b||0xc8;return function(_0x2f7c40){if(_0x2f7c40){return _0x27a04c[_0x453e('0x18')](_0x52c97b)['json'](_0x2f7c40);}};}function respondWithFilteredResult(_0x49a889,_0x35cd46){return function(_0x5b7759){if(_0x5b7759){var _0x4b74ff=_0x5b7759['count'],_0x2e8f57=_0x35cd46[_0x453e('0x19')],_0x376420=_0x35cd46[_0x453e('0x19')]+_0x35cd46[_0x453e('0x1a')],_0x3e6c1d;if(_0x376420>=_0x4b74ff){_0x376420=_0x4b74ff;_0x3e6c1d=0xc8;}else{_0x3e6c1d=0xce;}_0x49a889[_0x453e('0x18')](_0x3e6c1d);return _0x49a889[_0x453e('0x1b')](_0x453e('0x1c'),_0x2e8f57+'-'+_0x376420+'/'+_0x4b74ff)[_0x453e('0x1d')](_0x5b7759);}return null;};}function patchUpdates(_0x910ef3){return function(_0x10eaa6){try{jsonpatch[_0x453e('0x1e')](_0x10eaa6,_0x910ef3,!![]);}catch(_0x202eea){return BPromise[_0x453e('0x1f')](_0x202eea);}return _0x10eaa6[_0x453e('0x20')]();};}function saveUpdates(_0x51dfc7,_0x44e7b6){return function(_0x5c98f8){if(_0x5c98f8){return _0x5c98f8[_0x453e('0x21')](_0x51dfc7)[_0x453e('0x22')](function(_0x3638e0){return _0x3638e0;});}return null;};}function removeEntity(_0x9a3544,_0x4539a8){return function(_0x48acfa){if(_0x48acfa){return _0x48acfa['destroy']()[_0x453e('0x22')](function(){_0x9a3544[_0x453e('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x59f42d,_0x555549){return function(_0x5ac56c){if(!_0x5ac56c){_0x59f42d[_0x453e('0x17')](0x194);}return _0x5ac56c;};}function handleError(_0x40baae,_0xa4a0c7){_0xa4a0c7=_0xa4a0c7||0x1f4;return function(_0x5c0452){logger[_0x453e('0x23')](_0x5c0452[_0x453e('0x24')]);if(_0x5c0452[_0x453e('0x25')]){delete _0x5c0452[_0x453e('0x25')];}_0x40baae[_0x453e('0x18')](_0xa4a0c7)[_0x453e('0x26')](_0x5c0452);};}exports[_0x453e('0x27')]=function(_0x2c70aa,_0x3f0b7c){var _0x3b4e01={},_0x36816d={},_0x3009b2={'count':0x0,'rows':[]};var _0x3e62da=_['map'](db[_0x453e('0x28')][_0x453e('0x29')],function(_0x4f9148){return{'name':_0x4f9148['fieldName'],'type':_0x4f9148[_0x453e('0x2a')][_0x453e('0x2b')]};});_0x36816d[_0x453e('0x2c')]=_['map'](_0x3e62da,_0x453e('0x25'));_0x36816d[_0x453e('0x2d')]=_[_0x453e('0x2e')](_0x2c70aa[_0x453e('0x2d')]);_0x36816d[_0x453e('0x2f')]=_[_0x453e('0x30')](_0x36816d[_0x453e('0x2c')],_0x36816d[_0x453e('0x2d')]);_0x3b4e01[_0x453e('0x31')]=_[_0x453e('0x30')](_0x36816d[_0x453e('0x2c')],qs[_0x453e('0x32')](_0x2c70aa[_0x453e('0x2d')]['fields']));_0x3b4e01[_0x453e('0x31')]=_0x3b4e01[_0x453e('0x31')]['length']?_0x3b4e01[_0x453e('0x31')]:_0x36816d[_0x453e('0x2c')];if(!_0x2c70aa[_0x453e('0x2d')]['hasOwnProperty']('nolimit')){_0x3b4e01[_0x453e('0x1a')]=qs['limit'](_0x2c70aa[_0x453e('0x2d')][_0x453e('0x1a')]);_0x3b4e01['offset']=qs[_0x453e('0x19')](_0x2c70aa[_0x453e('0x2d')][_0x453e('0x19')]);}_0x3b4e01[_0x453e('0x33')]=qs[_0x453e('0x34')](_0x2c70aa[_0x453e('0x2d')][_0x453e('0x34')]);_0x3b4e01[_0x453e('0x35')]=qs[_0x453e('0x2f')](_['pick'](_0x2c70aa[_0x453e('0x2d')],_0x36816d[_0x453e('0x2f')]),_0x3e62da);if(_0x2c70aa[_0x453e('0x2d')][_0x453e('0x36')]){_0x3b4e01[_0x453e('0x35')]=_[_0x453e('0x37')](_0x3b4e01[_0x453e('0x35')],{'$or':_[_0x453e('0x38')](_0x3e62da,function(_0x3930b9){if(_0x3930b9['type']!==_0x453e('0x39')){var _0x2bd34a={};_0x2bd34a[_0x3930b9[_0x453e('0x25')]]={'$like':'%'+_0x2c70aa[_0x453e('0x2d')][_0x453e('0x36')]+'%'};return _0x2bd34a;}})});}_0x3b4e01=_[_0x453e('0x37')]({},_0x3b4e01,_0x2c70aa[_0x453e('0x3a')]);var _0x2e8e74={'where':_0x3b4e01[_0x453e('0x35')]};return db[_0x453e('0x28')][_0x453e('0x3b')](_0x2e8e74)[_0x453e('0x22')](function(_0x1802a9){_0x3009b2[_0x453e('0x3b')]=_0x1802a9;if(_0x2c70aa[_0x453e('0x2d')][_0x453e('0x3c')]){_0x3b4e01[_0x453e('0x3d')]=[{'all':!![]}];}return db[_0x453e('0x28')][_0x453e('0x3e')](_0x3b4e01);})['then'](function(_0x10f595){_0x3009b2[_0x453e('0x3f')]=_0x10f595;return _0x3009b2;})['then'](respondWithFilteredResult(_0x3f0b7c,_0x3b4e01))[_0x453e('0x40')](handleError(_0x3f0b7c,null));};exports['show']=function(_0x22ef9f,_0x36f0b3){var _0x3f2549={'raw':!![],'where':{'id':_0x22ef9f[_0x453e('0x41')]['id']}},_0x1c817c={};_0x1c817c[_0x453e('0x2c')]=_[_0x453e('0x2e')](db[_0x453e('0x28')][_0x453e('0x29')]);_0x1c817c['query']=_['keys'](_0x22ef9f['query']);_0x1c817c[_0x453e('0x2f')]=_['intersection'](_0x1c817c[_0x453e('0x2c')],_0x1c817c['query']);_0x3f2549[_0x453e('0x31')]=_[_0x453e('0x30')](_0x1c817c[_0x453e('0x2c')],qs[_0x453e('0x32')](_0x22ef9f['query']['fields']));_0x3f2549[_0x453e('0x31')]=_0x3f2549['attributes']['length']?_0x3f2549[_0x453e('0x31')]:_0x1c817c[_0x453e('0x2c')];if(_0x22ef9f[_0x453e('0x2d')][_0x453e('0x3c')]){_0x3f2549['include']=[{'all':!![]}];}_0x3f2549=_['merge']({},_0x3f2549,_0x22ef9f['options']);return db[_0x453e('0x28')][_0x453e('0x42')](_0x3f2549)[_0x453e('0x22')](handleEntityNotFound(_0x36f0b3,null))[_0x453e('0x22')](respondWithResult(_0x36f0b3,null))[_0x453e('0x40')](handleError(_0x36f0b3,null));};exports[_0x453e('0x43')]=function(_0x5d83b6,_0x3ecce6){return db['JscriptyAnswerReport']['create'](_0x5d83b6[_0x453e('0x44')],{})[_0x453e('0x22')](respondWithResult(_0x3ecce6,0xc9))[_0x453e('0x40')](handleError(_0x3ecce6,null));};exports[_0x453e('0x21')]=function(_0x34073c,_0x9497e8){if(_0x34073c[_0x453e('0x44')]['id']){delete _0x34073c[_0x453e('0x44')]['id'];}return db[_0x453e('0x28')][_0x453e('0x42')]({'where':{'id':_0x34073c[_0x453e('0x41')]['id']}})[_0x453e('0x22')](handleEntityNotFound(_0x9497e8,null))[_0x453e('0x22')](saveUpdates(_0x34073c[_0x453e('0x44')],null))[_0x453e('0x22')](respondWithResult(_0x9497e8,null))[_0x453e('0x40')](handleError(_0x9497e8,null));};exports[_0x453e('0x45')]=function(_0x416cd3,_0x41ff66){return db['JscriptyAnswerReport'][_0x453e('0x42')]({'where':{'id':_0x416cd3[_0x453e('0x41')]['id']}})[_0x453e('0x22')](handleEntityNotFound(_0x41ff66,null))['then'](removeEntity(_0x41ff66,null))['catch'](handleError(_0x41ff66,null));};exports[_0x453e('0x46')]=function(_0x179cd6,_0x101b47){return db['JscriptyAnswerReport'][_0x453e('0x46')]()[_0x453e('0x22')](respondWithResult(_0x101b47,null))[_0x453e('0x40')](handleError(_0x101b47,null));};