Built motion from commit 3c2ce842.|2.6.31
[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 _0x14f5=['limit','order','sort','filters','pick','filter','where','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','rimraf','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','count','offset','set','Content-Range','reject','update','destroy','then','error','stack','name','send','index','map','JscriptyAnswerReport','rawAttributes','key','query','keys','attributes','intersection','model','fields','length','hasOwnProperty'];(function(_0x4a76d8,_0x5a442f){var _0xcda2b6=function(_0x49f356){while(--_0x49f356){_0x4a76d8['push'](_0x4a76d8['shift']());}};_0xcda2b6(++_0x5a442f);}(_0x14f5,0xae));var _0x514f=function(_0x5008c8,_0x342e4a){_0x5008c8=_0x5008c8-0x0;var _0x28d778=_0x14f5[_0x5008c8];return _0x28d778;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x514f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x514f('0x1'));var rp=require(_0x514f('0x2'));var moment=require(_0x514f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x514f('0x4'));var util=require(_0x514f('0x5'));var path=require('path');var sox=require(_0x514f('0x6'));var csv=require(_0x514f('0x7'));var ejs=require(_0x514f('0x8'));var fs=require('fs');var fs_extra=require(_0x514f('0x9'));var _=require(_0x514f('0xa'));var squel=require(_0x514f('0xb'));var crypto=require(_0x514f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x514f('0xd'));var toCsv=require('to-csv');var querystring=require(_0x514f('0xe'));var Papa=require(_0x514f('0xf'));var Redis=require(_0x514f('0x10'));var authService=require(_0x514f('0x11'));var qs=require(_0x514f('0x12'));var as=require(_0x514f('0x13'));var hardwareService=require(_0x514f('0x14'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x514f('0x15'));var licenseUtil=require(_0x514f('0x16'));var db=require(_0x514f('0x17'))['db'];function respondWithStatusCode(_0x321914,_0x3eed49){_0x3eed49=_0x3eed49||0xcc;return function(_0x2ed1b7){if(_0x2ed1b7){return _0x321914[_0x514f('0x18')](_0x3eed49);}return _0x321914[_0x514f('0x19')](_0x3eed49)[_0x514f('0x1a')]();};}function respondWithResult(_0x4124bf,_0x46e552){_0x46e552=_0x46e552||0xc8;return function(_0x3fc905){if(_0x3fc905){return _0x4124bf[_0x514f('0x19')](_0x46e552)[_0x514f('0x1b')](_0x3fc905);}};}function respondWithFilteredResult(_0x1694b3,_0x5865d1){return function(_0x70d2b4){if(_0x70d2b4){var _0x1f0cbe=typeof _0x5865d1['offset']===_0x514f('0x1c')&&typeof _0x5865d1['limit']===_0x514f('0x1c');var _0x309ce0=_0x70d2b4[_0x514f('0x1d')];var _0x5a5641=_0x1f0cbe?0x0:_0x5865d1[_0x514f('0x1e')];var _0x3673a4=_0x1f0cbe?_0x70d2b4[_0x514f('0x1d')]:_0x5865d1[_0x514f('0x1e')]+_0x5865d1['limit'];var _0x4f9193;if(_0x3673a4>=_0x309ce0){_0x3673a4=_0x309ce0;_0x4f9193=0xc8;}else{_0x4f9193=0xce;}_0x1694b3[_0x514f('0x19')](_0x4f9193);return _0x1694b3[_0x514f('0x1f')](_0x514f('0x20'),_0x5a5641+'-'+_0x3673a4+'/'+_0x309ce0)['json'](_0x70d2b4);}return null;};}function patchUpdates(_0x43fcf9){return function(_0x7248e8){try{jsonpatch['apply'](_0x7248e8,_0x43fcf9,!![]);}catch(_0x186417){return BPromise[_0x514f('0x21')](_0x186417);}return _0x7248e8['save']();};}function saveUpdates(_0xd093a1,_0x18a430){return function(_0xd89aa2){if(_0xd89aa2){return _0xd89aa2[_0x514f('0x22')](_0xd093a1)['then'](function(_0x58861e){return _0x58861e;});}return null;};}function removeEntity(_0x4b0245,_0x5d80cb){return function(_0x1c16f9){if(_0x1c16f9){return _0x1c16f9[_0x514f('0x23')]()[_0x514f('0x24')](function(){_0x4b0245[_0x514f('0x19')](0xcc)[_0x514f('0x1a')]();});}};}function handleEntityNotFound(_0x26df04,_0x2c6bb1){return function(_0x101742){if(!_0x101742){_0x26df04[_0x514f('0x18')](0x194);}return _0x101742;};}function handleError(_0x5f2da2,_0x8c8bdf){_0x8c8bdf=_0x8c8bdf||0x1f4;return function(_0x37b3db){logger[_0x514f('0x25')](_0x37b3db[_0x514f('0x26')]);if(_0x37b3db[_0x514f('0x27')]){delete _0x37b3db[_0x514f('0x27')];}_0x5f2da2[_0x514f('0x19')](_0x8c8bdf)[_0x514f('0x28')](_0x37b3db);};}exports[_0x514f('0x29')]=function(_0x594a50,_0x2c4c4b){var _0x488c17={},_0x2b43e0={},_0x51beda={'count':0x0,'rows':[]};var _0x40ac5e=_[_0x514f('0x2a')](db[_0x514f('0x2b')][_0x514f('0x2c')],function(_0xdc0bcc){return{'name':_0xdc0bcc['fieldName'],'type':_0xdc0bcc['type'][_0x514f('0x2d')]};});_0x2b43e0['model']=_[_0x514f('0x2a')](_0x40ac5e,_0x514f('0x27'));_0x2b43e0[_0x514f('0x2e')]=_[_0x514f('0x2f')](_0x594a50[_0x514f('0x2e')]);_0x2b43e0['filters']=_['intersection'](_0x2b43e0['model'],_0x2b43e0[_0x514f('0x2e')]);_0x488c17[_0x514f('0x30')]=_[_0x514f('0x31')](_0x2b43e0[_0x514f('0x32')],qs[_0x514f('0x33')](_0x594a50[_0x514f('0x2e')][_0x514f('0x33')]));_0x488c17[_0x514f('0x30')]=_0x488c17[_0x514f('0x30')][_0x514f('0x34')]?_0x488c17['attributes']:_0x2b43e0['model'];if(!_0x594a50['query'][_0x514f('0x35')]('nolimit')){_0x488c17[_0x514f('0x36')]=qs['limit'](_0x594a50[_0x514f('0x2e')]['limit']);_0x488c17['offset']=qs[_0x514f('0x1e')](_0x594a50['query'][_0x514f('0x1e')]);}_0x488c17[_0x514f('0x37')]=qs[_0x514f('0x38')](_0x594a50[_0x514f('0x2e')][_0x514f('0x38')]);_0x488c17['where']=qs[_0x514f('0x39')](_[_0x514f('0x3a')](_0x594a50[_0x514f('0x2e')],_0x2b43e0[_0x514f('0x39')]),_0x40ac5e);if(_0x594a50['query'][_0x514f('0x3b')]){_0x488c17[_0x514f('0x3c')]=_[_0x514f('0x3d')](_0x488c17[_0x514f('0x3c')],{'$or':_['map'](_0x40ac5e,function(_0x1c1a24){if(_0x1c1a24[_0x514f('0x3e')]!==_0x514f('0x3f')){var _0x281d39={};_0x281d39[_0x1c1a24['name']]={'$like':'%'+_0x594a50[_0x514f('0x2e')]['filter']+'%'};return _0x281d39;}})});}_0x488c17=_[_0x514f('0x3d')]({},_0x488c17,_0x594a50[_0x514f('0x40')]);var _0x18969b={'where':_0x488c17['where']};return db['JscriptyAnswerReport'][_0x514f('0x1d')](_0x18969b)['then'](function(_0x10259a){_0x51beda[_0x514f('0x1d')]=_0x10259a;if(_0x594a50[_0x514f('0x2e')][_0x514f('0x41')]){_0x488c17[_0x514f('0x42')]=[{'all':!![]}];}return db[_0x514f('0x2b')][_0x514f('0x43')](_0x488c17);})['then'](function(_0x48914e){_0x51beda[_0x514f('0x44')]=_0x48914e;return _0x51beda;})['then'](respondWithFilteredResult(_0x2c4c4b,_0x488c17))[_0x514f('0x45')](handleError(_0x2c4c4b,null));};exports[_0x514f('0x46')]=function(_0x48d82a,_0x203af2){var _0x326ea6={'raw':!![],'where':{'id':_0x48d82a[_0x514f('0x47')]['id']}},_0x51e50b={};_0x51e50b['model']=_['keys'](db[_0x514f('0x2b')][_0x514f('0x2c')]);_0x51e50b[_0x514f('0x2e')]=_[_0x514f('0x2f')](_0x48d82a[_0x514f('0x2e')]);_0x51e50b['filters']=_['intersection'](_0x51e50b[_0x514f('0x32')],_0x51e50b[_0x514f('0x2e')]);_0x326ea6[_0x514f('0x30')]=_[_0x514f('0x31')](_0x51e50b[_0x514f('0x32')],qs['fields'](_0x48d82a[_0x514f('0x2e')]['fields']));_0x326ea6['attributes']=_0x326ea6[_0x514f('0x30')]['length']?_0x326ea6[_0x514f('0x30')]:_0x51e50b['model'];if(_0x48d82a['query'][_0x514f('0x41')]){_0x326ea6[_0x514f('0x42')]=[{'all':!![]}];}_0x326ea6=_['merge']({},_0x326ea6,_0x48d82a['options']);return db[_0x514f('0x2b')][_0x514f('0x48')](_0x326ea6)[_0x514f('0x24')](handleEntityNotFound(_0x203af2,null))[_0x514f('0x24')](respondWithResult(_0x203af2,null))[_0x514f('0x45')](handleError(_0x203af2,null));};exports[_0x514f('0x49')]=function(_0xa5259e,_0x1b33b2){return db[_0x514f('0x2b')]['create'](_0xa5259e[_0x514f('0x4a')],{})[_0x514f('0x24')](respondWithResult(_0x1b33b2,0xc9))[_0x514f('0x45')](handleError(_0x1b33b2,null));};exports[_0x514f('0x22')]=function(_0x33b658,_0x2e6971){if(_0x33b658[_0x514f('0x4a')]['id']){delete _0x33b658['body']['id'];}return db[_0x514f('0x2b')]['find']({'where':{'id':_0x33b658[_0x514f('0x47')]['id']}})[_0x514f('0x24')](handleEntityNotFound(_0x2e6971,null))[_0x514f('0x24')](saveUpdates(_0x33b658[_0x514f('0x4a')],null))[_0x514f('0x24')](respondWithResult(_0x2e6971,null))['catch'](handleError(_0x2e6971,null));};exports['destroy']=function(_0x38e237,_0x5e6e97){return db[_0x514f('0x2b')]['find']({'where':{'id':_0x38e237[_0x514f('0x47')]['id']}})[_0x514f('0x24')](handleEntityNotFound(_0x5e6e97,null))[_0x514f('0x24')](removeEntity(_0x5e6e97,null))['catch'](handleError(_0x5e6e97,null));};exports[_0x514f('0x4b')]=function(_0x41cb02,_0x2171e9){return db['JscriptyAnswerReport'][_0x514f('0x4b')]()[_0x514f('0x24')](respondWithResult(_0x2171e9,null))['catch'](handleError(_0x2171e9,null));};