aaefdb51fdc60404270f7ccfb3ad5051832a7b51
[motion2.git] / server / api / chatTransferReport / chatTransferReport.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 _0xf0e9=['name','send','map','ChatTransferReport','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','findAll','show','rawAttributes','include','find','catch','create','body','params','describe','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','sox','ejs','fs-extra','lodash','crypto','to-csv','querystring','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','status','json','limit','undefined','count','offset','Content-Range','apply','reject','update','then','destroy','sendStatus','error','stack'];(function(_0x53d29c,_0x16a6e1){var _0x1d0211=function(_0x1debef){while(--_0x1debef){_0x53d29c['push'](_0x53d29c['shift']());}};_0x1d0211(++_0x16a6e1);}(_0xf0e9,0xf2));var _0x9f0e=function(_0x389928,_0x5b0c08){_0x389928=_0x389928-0x0;var _0x41b3d9=_0xf0e9[_0x389928];return _0x41b3d9;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9f0e('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9f0e('0x1'));var rp=require(_0x9f0e('0x2'));var moment=require('moment');var BPromise=require(_0x9f0e('0x3'));var Mustache=require(_0x9f0e('0x4'));var util=require('util');var path=require(_0x9f0e('0x5'));var sox=require(_0x9f0e('0x6'));var csv=require('to-csv');var ejs=require(_0x9f0e('0x7'));var fs=require('fs');var fs_extra=require(_0x9f0e('0x8'));var _=require(_0x9f0e('0x9'));var squel=require('squel');var crypto=require(_0x9f0e('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x9f0e('0xb'));var querystring=require(_0x9f0e('0xc'));var Papa=require('papaparse');var Redis=require(_0x9f0e('0xd'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x9f0e('0xe'));var hardwareService=require(_0x9f0e('0xf'));var logger=require('../../config/logger')(_0x9f0e('0x10'));var utils=require('../../config/utils');var config=require(_0x9f0e('0x11'));var licenseUtil=require('../../config/license/util');var db=require(_0x9f0e('0x12'))['db'];function respondWithStatusCode(_0x4b5f97,_0x289438){_0x289438=_0x289438||0xcc;return function(_0x59b596){if(_0x59b596){return _0x4b5f97['sendStatus'](_0x289438);}return _0x4b5f97[_0x9f0e('0x13')](_0x289438)['end']();};}function respondWithResult(_0x3e24e9,_0x1c0686){_0x1c0686=_0x1c0686||0xc8;return function(_0xe31cb8){if(_0xe31cb8){return _0x3e24e9[_0x9f0e('0x13')](_0x1c0686)[_0x9f0e('0x14')](_0xe31cb8);}};}function respondWithFilteredResult(_0x18d5af,_0x1a77ec){return function(_0x279f9b){if(_0x279f9b){var _0x37e885=typeof _0x1a77ec['offset']==='undefined'&&typeof _0x1a77ec[_0x9f0e('0x15')]===_0x9f0e('0x16');var _0x1d078c=_0x279f9b[_0x9f0e('0x17')];var _0x16ac7a=_0x37e885?0x0:_0x1a77ec[_0x9f0e('0x18')];var _0x5ef2ba=_0x37e885?_0x279f9b[_0x9f0e('0x17')]:_0x1a77ec['offset']+_0x1a77ec[_0x9f0e('0x15')];var _0x4330f0;if(_0x5ef2ba>=_0x1d078c){_0x5ef2ba=_0x1d078c;_0x4330f0=0xc8;}else{_0x4330f0=0xce;}_0x18d5af[_0x9f0e('0x13')](_0x4330f0);return _0x18d5af['set'](_0x9f0e('0x19'),_0x16ac7a+'-'+_0x5ef2ba+'/'+_0x1d078c)[_0x9f0e('0x14')](_0x279f9b);}return null;};}function patchUpdates(_0x4b4998){return function(_0x33445d){try{jsonpatch[_0x9f0e('0x1a')](_0x33445d,_0x4b4998,!![]);}catch(_0x326379){return BPromise[_0x9f0e('0x1b')](_0x326379);}return _0x33445d['save']();};}function saveUpdates(_0x571197,_0x3dd8de){return function(_0x34a10f){if(_0x34a10f){return _0x34a10f[_0x9f0e('0x1c')](_0x571197)[_0x9f0e('0x1d')](function(_0x2fcb27){return _0x2fcb27;});}return null;};}function removeEntity(_0x3ec414,_0x174bea){return function(_0x34b7da){if(_0x34b7da){return _0x34b7da[_0x9f0e('0x1e')]()['then'](function(){_0x3ec414[_0x9f0e('0x13')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3d6632,_0x1d4a73){return function(_0x2808f4){if(!_0x2808f4){_0x3d6632[_0x9f0e('0x1f')](0x194);}return _0x2808f4;};}function handleError(_0x5d40a9,_0x1f4338){_0x1f4338=_0x1f4338||0x1f4;return function(_0x2c85dc){logger[_0x9f0e('0x20')](_0x2c85dc[_0x9f0e('0x21')]);if(_0x2c85dc[_0x9f0e('0x22')]){delete _0x2c85dc[_0x9f0e('0x22')];}_0x5d40a9[_0x9f0e('0x13')](_0x1f4338)[_0x9f0e('0x23')](_0x2c85dc);};}exports['index']=function(_0x162125,_0x3e4214){var _0x150c39={},_0x25077b={},_0x16f82e={'count':0x0,'rows':[]};var _0x158bc6=_[_0x9f0e('0x24')](db[_0x9f0e('0x25')]['rawAttributes'],function(_0x25f36d){return{'name':_0x25f36d[_0x9f0e('0x26')],'type':_0x25f36d[_0x9f0e('0x27')][_0x9f0e('0x28')]};});_0x25077b[_0x9f0e('0x29')]=_['map'](_0x158bc6,_0x9f0e('0x22'));_0x25077b[_0x9f0e('0x2a')]=_[_0x9f0e('0x2b')](_0x162125[_0x9f0e('0x2a')]);_0x25077b['filters']=_[_0x9f0e('0x2c')](_0x25077b['model'],_0x25077b[_0x9f0e('0x2a')]);_0x150c39[_0x9f0e('0x2d')]=_['intersection'](_0x25077b[_0x9f0e('0x29')],qs[_0x9f0e('0x2e')](_0x162125[_0x9f0e('0x2a')][_0x9f0e('0x2e')]));_0x150c39[_0x9f0e('0x2d')]=_0x150c39[_0x9f0e('0x2d')][_0x9f0e('0x2f')]?_0x150c39[_0x9f0e('0x2d')]:_0x25077b[_0x9f0e('0x29')];if(!_0x162125[_0x9f0e('0x2a')][_0x9f0e('0x30')](_0x9f0e('0x31'))){_0x150c39['limit']=qs['limit'](_0x162125[_0x9f0e('0x2a')][_0x9f0e('0x15')]);_0x150c39[_0x9f0e('0x18')]=qs[_0x9f0e('0x18')](_0x162125[_0x9f0e('0x2a')][_0x9f0e('0x18')]);}_0x150c39['order']=qs[_0x9f0e('0x32')](_0x162125['query'][_0x9f0e('0x32')]);_0x150c39[_0x9f0e('0x33')]=qs['filters'](_[_0x9f0e('0x34')](_0x162125[_0x9f0e('0x2a')],_0x25077b[_0x9f0e('0x35')]),_0x158bc6);if(_0x162125['query'][_0x9f0e('0x36')]){_0x150c39[_0x9f0e('0x33')]=_[_0x9f0e('0x37')](_0x150c39[_0x9f0e('0x33')],{'$or':_[_0x9f0e('0x24')](_0x158bc6,function(_0x2077ce){if(_0x2077ce[_0x9f0e('0x27')]!==_0x9f0e('0x38')){var _0x7c8b69={};_0x7c8b69[_0x2077ce['name']]={'$like':'%'+_0x162125[_0x9f0e('0x2a')]['filter']+'%'};return _0x7c8b69;}})});}_0x150c39=_[_0x9f0e('0x37')]({},_0x150c39,_0x162125[_0x9f0e('0x39')]);var _0x2897dd={'where':_0x150c39[_0x9f0e('0x33')]};return db[_0x9f0e('0x25')]['count'](_0x2897dd)[_0x9f0e('0x1d')](function(_0x19246f){_0x16f82e['count']=_0x19246f;if(_0x162125['query'][_0x9f0e('0x3a')]){_0x150c39['include']=[{'all':!![]}];}return db['ChatTransferReport'][_0x9f0e('0x3b')](_0x150c39);})[_0x9f0e('0x1d')](function(_0x38af7b){_0x16f82e['rows']=_0x38af7b;return _0x16f82e;})[_0x9f0e('0x1d')](respondWithFilteredResult(_0x3e4214,_0x150c39))['catch'](handleError(_0x3e4214,null));};exports[_0x9f0e('0x3c')]=function(_0x4f1765,_0x43db67){var _0x39f2c6={'raw':!![],'where':{'id':_0x4f1765['params']['id']}},_0x32e27c={};_0x32e27c[_0x9f0e('0x29')]=_[_0x9f0e('0x2b')](db[_0x9f0e('0x25')][_0x9f0e('0x3d')]);_0x32e27c[_0x9f0e('0x2a')]=_[_0x9f0e('0x2b')](_0x4f1765['query']);_0x32e27c[_0x9f0e('0x35')]=_[_0x9f0e('0x2c')](_0x32e27c['model'],_0x32e27c[_0x9f0e('0x2a')]);_0x39f2c6[_0x9f0e('0x2d')]=_[_0x9f0e('0x2c')](_0x32e27c[_0x9f0e('0x29')],qs[_0x9f0e('0x2e')](_0x4f1765['query'][_0x9f0e('0x2e')]));_0x39f2c6[_0x9f0e('0x2d')]=_0x39f2c6['attributes'][_0x9f0e('0x2f')]?_0x39f2c6[_0x9f0e('0x2d')]:_0x32e27c[_0x9f0e('0x29')];if(_0x4f1765['query'][_0x9f0e('0x3a')]){_0x39f2c6[_0x9f0e('0x3e')]=[{'all':!![]}];}_0x39f2c6=_['merge']({},_0x39f2c6,_0x4f1765[_0x9f0e('0x39')]);return db['ChatTransferReport'][_0x9f0e('0x3f')](_0x39f2c6)[_0x9f0e('0x1d')](handleEntityNotFound(_0x43db67,null))[_0x9f0e('0x1d')](respondWithResult(_0x43db67,null))[_0x9f0e('0x40')](handleError(_0x43db67,null));};exports['create']=function(_0x4b3f2f,_0x1a1b22){return db[_0x9f0e('0x25')][_0x9f0e('0x41')](_0x4b3f2f['body'],{})[_0x9f0e('0x1d')](respondWithResult(_0x1a1b22,0xc9))['catch'](handleError(_0x1a1b22,null));};exports['update']=function(_0x439ef8,_0x2f8256){if(_0x439ef8[_0x9f0e('0x42')]['id']){delete _0x439ef8[_0x9f0e('0x42')]['id'];}return db[_0x9f0e('0x25')][_0x9f0e('0x3f')]({'where':{'id':_0x439ef8[_0x9f0e('0x43')]['id']}})[_0x9f0e('0x1d')](handleEntityNotFound(_0x2f8256,null))[_0x9f0e('0x1d')](saveUpdates(_0x439ef8[_0x9f0e('0x42')],null))[_0x9f0e('0x1d')](respondWithResult(_0x2f8256,null))['catch'](handleError(_0x2f8256,null));};exports['destroy']=function(_0x3f359b,_0x4a1532){return db['ChatTransferReport'][_0x9f0e('0x3f')]({'where':{'id':_0x3f359b[_0x9f0e('0x43')]['id']}})[_0x9f0e('0x1d')](handleEntityNotFound(_0x4a1532,null))['then'](removeEntity(_0x4a1532,null))[_0x9f0e('0x40')](handleError(_0x4a1532,null));};exports[_0x9f0e('0x44')]=function(_0x19775e,_0x3fa4a2){return db['ChatTransferReport'][_0x9f0e('0x44')]()['then'](respondWithResult(_0x3fa4a2,null))[_0x9f0e('0x40')](handleError(_0x3fa4a2,null));};