Built motion from commit (unavailable).|2.5.22
[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 _0x28a1=['reject','save','update','then','destroy','error','stack','name','send','map','JscriptyAnswerReport','rawAttributes','fieldName','type','key','model','query','filters','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','include','rows','catch','params','keys','intersection','create','body','find','describe','html-pdf','eml-format','zip-dir','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','ioredis','../../components/auth/service','../../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'];(function(_0x1ce266,_0xf99ee4){var _0x2d08a6=function(_0x3a8be2){while(--_0x3a8be2){_0x1ce266['push'](_0x1ce266['shift']());}};_0x2d08a6(++_0xf99ee4);}(_0x28a1,0x152));var _0x128a=function(_0x4ab3fb,_0x776775){_0x4ab3fb=_0x4ab3fb-0x0;var _0x34fe1e=_0x28a1[_0x4ab3fb];return _0x34fe1e;};'use strict';var pdf=require(_0x128a('0x0'));var emlformat=require(_0x128a('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x128a('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x128a('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x128a('0x4'));var util=require(_0x128a('0x5'));var path=require(_0x128a('0x6'));var sox=require(_0x128a('0x7'));var csv=require(_0x128a('0x8'));var ejs=require(_0x128a('0x9'));var fs=require('fs');var _=require(_0x128a('0xa'));var squel=require(_0x128a('0xb'));var crypto=require(_0x128a('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x128a('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x128a('0xd'));var authService=require(_0x128a('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x128a('0xf'));var hardwareService=require(_0x128a('0x10'));var logger=require(_0x128a('0x11'))(_0x128a('0x12'));var utils=require(_0x128a('0x13'));var config=require(_0x128a('0x14'));var licenseUtil=require(_0x128a('0x15'));var db=require(_0x128a('0x16'))['db'];function respondWithStatusCode(_0x44a26c,_0x3fa25c){_0x3fa25c=_0x3fa25c||0xcc;return function(_0x4f0f67){if(_0x4f0f67){return _0x44a26c[_0x128a('0x17')](_0x3fa25c);}return _0x44a26c[_0x128a('0x18')](_0x3fa25c)[_0x128a('0x19')]();};}function respondWithResult(_0x396aed,_0x60dce0){_0x60dce0=_0x60dce0||0xc8;return function(_0x57c1df){if(_0x57c1df){return _0x396aed[_0x128a('0x18')](_0x60dce0)[_0x128a('0x1a')](_0x57c1df);}};}function respondWithFilteredResult(_0x881460,_0xb80f07){return function(_0x4e8d2b){if(_0x4e8d2b){var _0x39be2f=_0x4e8d2b[_0x128a('0x1b')],_0x1356eb=_0xb80f07[_0x128a('0x1c')],_0x146b1e=_0xb80f07[_0x128a('0x1c')]+_0xb80f07[_0x128a('0x1d')],_0x3ea648;if(_0x146b1e>=_0x39be2f){_0x146b1e=_0x39be2f;_0x3ea648=0xc8;}else{_0x3ea648=0xce;}_0x881460[_0x128a('0x18')](_0x3ea648);return _0x881460[_0x128a('0x1e')](_0x128a('0x1f'),_0x1356eb+'-'+_0x146b1e+'/'+_0x39be2f)[_0x128a('0x1a')](_0x4e8d2b);}return null;};}function patchUpdates(_0x1169d4){return function(_0x31abe8){try{jsonpatch['apply'](_0x31abe8,_0x1169d4,!![]);}catch(_0x2ff30a){return BPromise[_0x128a('0x20')](_0x2ff30a);}return _0x31abe8[_0x128a('0x21')]();};}function saveUpdates(_0xb3bc04,_0x20141e){return function(_0x1a4d47){if(_0x1a4d47){return _0x1a4d47[_0x128a('0x22')](_0xb3bc04)[_0x128a('0x23')](function(_0x3169a0){return _0x3169a0;});}return null;};}function removeEntity(_0x1266d9,_0x5e7da8){return function(_0x1f5f71){if(_0x1f5f71){return _0x1f5f71[_0x128a('0x24')]()['then'](function(){_0x1266d9[_0x128a('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x57faa8,_0x4bbb4d){return function(_0x43b8c4){if(!_0x43b8c4){_0x57faa8['sendStatus'](0x194);}return _0x43b8c4;};}function handleError(_0x2d042d,_0x42b729){_0x42b729=_0x42b729||0x1f4;return function(_0xfccafd){logger[_0x128a('0x25')](_0xfccafd[_0x128a('0x26')]);if(_0xfccafd[_0x128a('0x27')]){delete _0xfccafd[_0x128a('0x27')];}_0x2d042d[_0x128a('0x18')](_0x42b729)[_0x128a('0x28')](_0xfccafd);};}exports['index']=function(_0x22669e,_0x1deba0){var _0x105f1f={},_0x14d142={},_0x63baf8={'count':0x0,'rows':[]};var _0x426fa7=_[_0x128a('0x29')](db[_0x128a('0x2a')][_0x128a('0x2b')],function(_0x493f0c){return{'name':_0x493f0c[_0x128a('0x2c')],'type':_0x493f0c[_0x128a('0x2d')][_0x128a('0x2e')]};});_0x14d142[_0x128a('0x2f')]=_[_0x128a('0x29')](_0x426fa7,_0x128a('0x27'));_0x14d142[_0x128a('0x30')]=_['keys'](_0x22669e[_0x128a('0x30')]);_0x14d142[_0x128a('0x31')]=_['intersection'](_0x14d142[_0x128a('0x2f')],_0x14d142[_0x128a('0x30')]);_0x105f1f['attributes']=_['intersection'](_0x14d142[_0x128a('0x2f')],qs['fields'](_0x22669e['query'][_0x128a('0x32')]));_0x105f1f[_0x128a('0x33')]=_0x105f1f['attributes'][_0x128a('0x34')]?_0x105f1f[_0x128a('0x33')]:_0x14d142[_0x128a('0x2f')];if(!_0x22669e[_0x128a('0x30')][_0x128a('0x35')](_0x128a('0x36'))){_0x105f1f['limit']=qs[_0x128a('0x1d')](_0x22669e[_0x128a('0x30')][_0x128a('0x1d')]);_0x105f1f[_0x128a('0x1c')]=qs['offset'](_0x22669e[_0x128a('0x30')][_0x128a('0x1c')]);}_0x105f1f[_0x128a('0x37')]=qs[_0x128a('0x38')](_0x22669e[_0x128a('0x30')]['sort']);_0x105f1f[_0x128a('0x39')]=qs[_0x128a('0x31')](_[_0x128a('0x3a')](_0x22669e['query'],_0x14d142[_0x128a('0x31')]),_0x426fa7);if(_0x22669e[_0x128a('0x30')]['filter']){_0x105f1f[_0x128a('0x39')]=_[_0x128a('0x3b')](_0x105f1f['where'],{'$or':_[_0x128a('0x29')](_0x426fa7,function(_0x533da7){if(_0x533da7[_0x128a('0x2d')]!==_0x128a('0x3c')){var _0x55f516={};_0x55f516[_0x533da7[_0x128a('0x27')]]={'$like':'%'+_0x22669e[_0x128a('0x30')][_0x128a('0x3d')]+'%'};return _0x55f516;}})});}_0x105f1f=_['merge']({},_0x105f1f,_0x22669e[_0x128a('0x3e')]);var _0x4c3cb9={'where':_0x105f1f[_0x128a('0x39')]};return db[_0x128a('0x2a')][_0x128a('0x1b')](_0x4c3cb9)['then'](function(_0x4fe7c4){_0x63baf8[_0x128a('0x1b')]=_0x4fe7c4;if(_0x22669e[_0x128a('0x30')][_0x128a('0x3f')]){_0x105f1f[_0x128a('0x40')]=[{'all':!![]}];}return db['JscriptyAnswerReport']['findAll'](_0x105f1f);})[_0x128a('0x23')](function(_0x1401ef){_0x63baf8[_0x128a('0x41')]=_0x1401ef;return _0x63baf8;})['then'](respondWithFilteredResult(_0x1deba0,_0x105f1f))[_0x128a('0x42')](handleError(_0x1deba0,null));};exports['show']=function(_0x7f1220,_0x3b45d9){var _0x4510fc={'raw':!![],'where':{'id':_0x7f1220[_0x128a('0x43')]['id']}},_0x2eda0c={};_0x2eda0c[_0x128a('0x2f')]=_[_0x128a('0x44')](db['JscriptyAnswerReport']['rawAttributes']);_0x2eda0c['query']=_[_0x128a('0x44')](_0x7f1220['query']);_0x2eda0c[_0x128a('0x31')]=_[_0x128a('0x45')](_0x2eda0c[_0x128a('0x2f')],_0x2eda0c[_0x128a('0x30')]);_0x4510fc[_0x128a('0x33')]=_[_0x128a('0x45')](_0x2eda0c[_0x128a('0x2f')],qs[_0x128a('0x32')](_0x7f1220['query']['fields']));_0x4510fc[_0x128a('0x33')]=_0x4510fc['attributes'][_0x128a('0x34')]?_0x4510fc[_0x128a('0x33')]:_0x2eda0c[_0x128a('0x2f')];if(_0x7f1220['query'][_0x128a('0x3f')]){_0x4510fc[_0x128a('0x40')]=[{'all':!![]}];}_0x4510fc=_[_0x128a('0x3b')]({},_0x4510fc,_0x7f1220[_0x128a('0x3e')]);return db[_0x128a('0x2a')]['find'](_0x4510fc)[_0x128a('0x23')](handleEntityNotFound(_0x3b45d9,null))['then'](respondWithResult(_0x3b45d9,null))[_0x128a('0x42')](handleError(_0x3b45d9,null));};exports[_0x128a('0x46')]=function(_0x21deb8,_0x30ad53){return db[_0x128a('0x2a')]['create'](_0x21deb8[_0x128a('0x47')],{})[_0x128a('0x23')](respondWithResult(_0x30ad53,0xc9))[_0x128a('0x42')](handleError(_0x30ad53,null));};exports[_0x128a('0x22')]=function(_0x25d919,_0x1e9e00){if(_0x25d919[_0x128a('0x47')]['id']){delete _0x25d919[_0x128a('0x47')]['id'];}return db[_0x128a('0x2a')]['find']({'where':{'id':_0x25d919[_0x128a('0x43')]['id']}})[_0x128a('0x23')](handleEntityNotFound(_0x1e9e00,null))[_0x128a('0x23')](saveUpdates(_0x25d919[_0x128a('0x47')],null))[_0x128a('0x23')](respondWithResult(_0x1e9e00,null))[_0x128a('0x42')](handleError(_0x1e9e00,null));};exports[_0x128a('0x24')]=function(_0x57bfca,_0x596f8c){return db[_0x128a('0x2a')][_0x128a('0x48')]({'where':{'id':_0x57bfca[_0x128a('0x43')]['id']}})[_0x128a('0x23')](handleEntityNotFound(_0x596f8c,null))[_0x128a('0x23')](removeEntity(_0x596f8c,null))[_0x128a('0x42')](handleError(_0x596f8c,null));};exports['describe']=function(_0x260fa0,_0x1fc288){return db[_0x128a('0x2a')][_0x128a('0x49')]()[_0x128a('0x23')](respondWithResult(_0x1fc288,null))[_0x128a('0x42')](handleError(_0x1fc288,null));};