d121e10a5be1eb3f7e093ef4716511f9b26adfc3
[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 _0xf194=['save','update','then','destroy','error','stack','name','index','map','JscriptyAnswerReport','fieldName','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','rawAttributes','keys','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','status','end','json','count','offset','limit','set','Content-Range','apply','reject'];(function(_0xd206ce,_0x3031d2){var _0x5b3ec6=function(_0x526993){while(--_0x526993){_0xd206ce['push'](_0xd206ce['shift']());}};_0x5b3ec6(++_0x3031d2);}(_0xf194,0x19b));var _0x4f19=function(_0x45389a,_0x37b5d3){_0x45389a=_0x45389a-0x0;var _0xd40295=_0xf194[_0x45389a];return _0xd40295;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4f19('0x0'));var rimraf=require(_0x4f19('0x1'));var zipdir=require(_0x4f19('0x2'));var jsonpatch=require(_0x4f19('0x3'));var rp=require(_0x4f19('0x4'));var moment=require('moment');var BPromise=require(_0x4f19('0x5'));var Mustache=require(_0x4f19('0x6'));var util=require('util');var path=require(_0x4f19('0x7'));var sox=require(_0x4f19('0x8'));var csv=require(_0x4f19('0x9'));var ejs=require(_0x4f19('0xa'));var fs=require('fs');var _=require(_0x4f19('0xb'));var squel=require(_0x4f19('0xc'));var crypto=require(_0x4f19('0xd'));var jsforce=require(_0x4f19('0xe'));var deskjs=require(_0x4f19('0xf'));var toCsv=require('to-csv');var querystring=require(_0x4f19('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x4f19('0x11'));var qs=require(_0x4f19('0x12'));var as=require(_0x4f19('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x4f19('0x14'));var utils=require(_0x4f19('0x15'));var config=require(_0x4f19('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1885f1,_0x41bf1f){_0x41bf1f=_0x41bf1f||0xcc;return function(_0x978cd2){if(_0x978cd2){return _0x1885f1['sendStatus'](_0x41bf1f);}return _0x1885f1[_0x4f19('0x17')](_0x41bf1f)[_0x4f19('0x18')]();};}function respondWithResult(_0x1fda83,_0x4e1c13){_0x4e1c13=_0x4e1c13||0xc8;return function(_0x3ed149){if(_0x3ed149){return _0x1fda83[_0x4f19('0x17')](_0x4e1c13)[_0x4f19('0x19')](_0x3ed149);}};}function respondWithFilteredResult(_0x82413d,_0xd9645f){return function(_0x4f5ab1){if(_0x4f5ab1){var _0x4d9b78=_0x4f5ab1[_0x4f19('0x1a')],_0x4a4acf=_0xd9645f[_0x4f19('0x1b')],_0x5cd9c1=_0xd9645f['offset']+_0xd9645f[_0x4f19('0x1c')],_0xe6d3c1;if(_0x5cd9c1>=_0x4d9b78){_0x5cd9c1=_0x4d9b78;_0xe6d3c1=0xc8;}else{_0xe6d3c1=0xce;}_0x82413d[_0x4f19('0x17')](_0xe6d3c1);return _0x82413d[_0x4f19('0x1d')](_0x4f19('0x1e'),_0x4a4acf+'-'+_0x5cd9c1+'/'+_0x4d9b78)[_0x4f19('0x19')](_0x4f5ab1);}return null;};}function patchUpdates(_0x3f43bd){return function(_0x42330c){try{jsonpatch[_0x4f19('0x1f')](_0x42330c,_0x3f43bd,!![]);}catch(_0x265172){return BPromise[_0x4f19('0x20')](_0x265172);}return _0x42330c[_0x4f19('0x21')]();};}function saveUpdates(_0x261e4f,_0x428e05){return function(_0x5c92ef){if(_0x5c92ef){return _0x5c92ef[_0x4f19('0x22')](_0x261e4f)[_0x4f19('0x23')](function(_0x2536af){return _0x2536af;});}return null;};}function removeEntity(_0x26b417,_0x44a56c){return function(_0x483ec6){if(_0x483ec6){return _0x483ec6[_0x4f19('0x24')]()[_0x4f19('0x23')](function(){_0x26b417[_0x4f19('0x17')](0xcc)[_0x4f19('0x18')]();});}};}function handleEntityNotFound(_0x375584,_0x13fbbd){return function(_0x496643){if(!_0x496643){_0x375584['sendStatus'](0x194);}return _0x496643;};}function handleError(_0x289937,_0x3e112e){_0x3e112e=_0x3e112e||0x1f4;return function(_0x1ef5a0){logger[_0x4f19('0x25')](_0x1ef5a0[_0x4f19('0x26')]);if(_0x1ef5a0[_0x4f19('0x27')]){delete _0x1ef5a0[_0x4f19('0x27')];}_0x289937[_0x4f19('0x17')](_0x3e112e)['send'](_0x1ef5a0);};}exports[_0x4f19('0x28')]=function(_0x2fc3c0,_0x2649dc){var _0x44c9e8={},_0x4b72e9={},_0x5904c3={'count':0x0,'rows':[]};var _0x5ce9ad=_[_0x4f19('0x29')](db[_0x4f19('0x2a')]['rawAttributes'],function(_0x5c7d1d){return{'name':_0x5c7d1d[_0x4f19('0x2b')],'type':_0x5c7d1d[_0x4f19('0x2c')][_0x4f19('0x2d')]};});_0x4b72e9[_0x4f19('0x2e')]=_['map'](_0x5ce9ad,_0x4f19('0x27'));_0x4b72e9[_0x4f19('0x2f')]=_['keys'](_0x2fc3c0[_0x4f19('0x2f')]);_0x4b72e9['filters']=_[_0x4f19('0x30')](_0x4b72e9[_0x4f19('0x2e')],_0x4b72e9['query']);_0x44c9e8[_0x4f19('0x31')]=_[_0x4f19('0x30')](_0x4b72e9['model'],qs[_0x4f19('0x32')](_0x2fc3c0[_0x4f19('0x2f')]['fields']));_0x44c9e8[_0x4f19('0x31')]=_0x44c9e8[_0x4f19('0x31')][_0x4f19('0x33')]?_0x44c9e8['attributes']:_0x4b72e9[_0x4f19('0x2e')];if(!_0x2fc3c0[_0x4f19('0x2f')][_0x4f19('0x34')](_0x4f19('0x35'))){_0x44c9e8[_0x4f19('0x1c')]=qs[_0x4f19('0x1c')](_0x2fc3c0[_0x4f19('0x2f')]['limit']);_0x44c9e8[_0x4f19('0x1b')]=qs['offset'](_0x2fc3c0[_0x4f19('0x2f')]['offset']);}_0x44c9e8[_0x4f19('0x36')]=qs[_0x4f19('0x37')](_0x2fc3c0[_0x4f19('0x2f')][_0x4f19('0x37')]);_0x44c9e8[_0x4f19('0x38')]=qs[_0x4f19('0x39')](_['pick'](_0x2fc3c0[_0x4f19('0x2f')],_0x4b72e9[_0x4f19('0x39')]));if(_0x2fc3c0['query'][_0x4f19('0x3a')]){_0x44c9e8[_0x4f19('0x38')]=_[_0x4f19('0x3b')](_0x44c9e8['where'],{'$or':_[_0x4f19('0x29')](_0x5ce9ad,function(_0x2ef2a4){if(_0x2ef2a4['type']!==_0x4f19('0x3c')){var _0x71a742={};_0x71a742[_0x2ef2a4[_0x4f19('0x27')]]={'$like':'%'+_0x2fc3c0[_0x4f19('0x2f')][_0x4f19('0x3a')]+'%'};return _0x71a742;}})});}_0x44c9e8=_['merge']({},_0x44c9e8,_0x2fc3c0[_0x4f19('0x3d')]);var _0x2ded77={'where':_0x44c9e8['where']};return db[_0x4f19('0x2a')][_0x4f19('0x1a')](_0x2ded77)[_0x4f19('0x23')](function(_0x357f0f){_0x5904c3['count']=_0x357f0f;if(_0x2fc3c0['query'][_0x4f19('0x3e')]){_0x44c9e8[_0x4f19('0x3f')]=[{'all':!![]}];}return db['JscriptyAnswerReport'][_0x4f19('0x40')](_0x44c9e8);})['then'](function(_0x5e618d){_0x5904c3['rows']=_0x5e618d;return _0x5904c3;})[_0x4f19('0x23')](respondWithFilteredResult(_0x2649dc,_0x44c9e8))[_0x4f19('0x41')](handleError(_0x2649dc,null));};exports[_0x4f19('0x42')]=function(_0x1b4849,_0xb4b7d6){var _0x11ab98={'raw':!![],'where':{'id':_0x1b4849[_0x4f19('0x43')]['id']}},_0x20eab7={};_0x20eab7[_0x4f19('0x2e')]=_['keys'](db[_0x4f19('0x2a')][_0x4f19('0x44')]);_0x20eab7[_0x4f19('0x2f')]=_[_0x4f19('0x45')](_0x1b4849[_0x4f19('0x2f')]);_0x20eab7[_0x4f19('0x39')]=_[_0x4f19('0x30')](_0x20eab7[_0x4f19('0x2e')],_0x20eab7['query']);_0x11ab98[_0x4f19('0x31')]=_[_0x4f19('0x30')](_0x20eab7[_0x4f19('0x2e')],qs[_0x4f19('0x32')](_0x1b4849[_0x4f19('0x2f')][_0x4f19('0x32')]));_0x11ab98[_0x4f19('0x31')]=_0x11ab98['attributes'][_0x4f19('0x33')]?_0x11ab98[_0x4f19('0x31')]:_0x20eab7[_0x4f19('0x2e')];if(_0x1b4849['query']['includeAll']){_0x11ab98[_0x4f19('0x3f')]=[{'all':!![]}];}_0x11ab98=_[_0x4f19('0x3b')]({},_0x11ab98,_0x1b4849[_0x4f19('0x3d')]);return db['JscriptyAnswerReport'][_0x4f19('0x46')](_0x11ab98)[_0x4f19('0x23')](handleEntityNotFound(_0xb4b7d6,null))[_0x4f19('0x23')](respondWithResult(_0xb4b7d6,null))[_0x4f19('0x41')](handleError(_0xb4b7d6,null));};exports[_0x4f19('0x47')]=function(_0x106c83,_0x42d154){return db['JscriptyAnswerReport'][_0x4f19('0x47')](_0x106c83[_0x4f19('0x48')],{})[_0x4f19('0x23')](respondWithResult(_0x42d154,0xc9))[_0x4f19('0x41')](handleError(_0x42d154,null));};exports[_0x4f19('0x22')]=function(_0x3829d5,_0x42661b){if(_0x3829d5[_0x4f19('0x48')]['id']){delete _0x3829d5['body']['id'];}return db[_0x4f19('0x2a')][_0x4f19('0x46')]({'where':{'id':_0x3829d5['params']['id']}})['then'](handleEntityNotFound(_0x42661b,null))[_0x4f19('0x23')](saveUpdates(_0x3829d5['body'],null))[_0x4f19('0x23')](respondWithResult(_0x42661b,null))[_0x4f19('0x41')](handleError(_0x42661b,null));};exports[_0x4f19('0x24')]=function(_0x5e677c,_0x3d79b1){return db['JscriptyAnswerReport'][_0x4f19('0x46')]({'where':{'id':_0x5e677c['params']['id']}})['then'](handleEntityNotFound(_0x3d79b1,null))[_0x4f19('0x23')](removeEntity(_0x3d79b1,null))[_0x4f19('0x41')](handleError(_0x3d79b1,null));};exports[_0x4f19('0x49')]=function(_0x4cac8c,_0x5560d6){return db[_0x4f19('0x2a')][_0x4f19('0x49')]()[_0x4f19('0x23')](respondWithResult(_0x5560d6,null))['catch'](handleError(_0x5560d6,null));};