9bf22c2b45f0a2f65f2423cbd66386af4a296f18
[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 _0xfe41=['body','contact','agent','interaction','account','index','rawAttributes','fieldName','type','map','query','keys','model','attributes','intersection','fields','length','nolimit','order','where','filters','pick','VIRTUAL','filter','ChatTransferReport','include','findAll','rows','catch','show','params','includeAll','create','find','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../mysqldb','end','status','json','offset','undefined','limit','count','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','render','merge'];(function(_0x3dbd50,_0x99ad82){var _0x1c1da0=function(_0x19a0bb){while(--_0x19a0bb){_0x3dbd50['push'](_0x3dbd50['shift']());}};_0x1c1da0(++_0x99ad82);}(_0xfe41,0x10a));var _0x1fe4=function(_0x49b14d,_0x578d07){_0x49b14d=_0x49b14d-0x0;var _0x3d2488=_0xfe41[_0x49b14d];return _0x3d2488;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1fe4('0x0'));var zipdir=require(_0x1fe4('0x1'));var jsonpatch=require(_0x1fe4('0x2'));var rp=require(_0x1fe4('0x3'));var moment=require(_0x1fe4('0x4'));var BPromise=require(_0x1fe4('0x5'));var Mustache=require(_0x1fe4('0x6'));var util=require(_0x1fe4('0x7'));var path=require('path');var sox=require(_0x1fe4('0x8'));var csv=require(_0x1fe4('0x9'));var ejs=require(_0x1fe4('0xa'));var fs=require('fs');var fs_extra=require(_0x1fe4('0xb'));var _=require(_0x1fe4('0xc'));var squel=require(_0x1fe4('0xd'));var crypto=require(_0x1fe4('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x1fe4('0xf'));var toCsv=require(_0x1fe4('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x1fe4('0x10'));var authService=require(_0x1fe4('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x1fe4('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x1fe4('0x13'))(_0x1fe4('0x14'));var utils=require('../../config/utils');var config=require(_0x1fe4('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x1fe4('0x16'))['db'];function respondWithStatusCode(_0x4414a2,_0x4e108c){_0x4e108c=_0x4e108c||0xcc;return function(_0x504263){if(_0x504263){return _0x4414a2['sendStatus'](_0x4e108c);}return _0x4414a2['status'](_0x4e108c)[_0x1fe4('0x17')]();};}function respondWithResult(_0x28f810,_0x26cab9){_0x26cab9=_0x26cab9||0xc8;return function(_0x462372){if(_0x462372){return _0x28f810[_0x1fe4('0x18')](_0x26cab9)[_0x1fe4('0x19')](_0x462372);}};}function respondWithFilteredResult(_0xedd23c,_0x3ece07){return function(_0x1484f3){if(_0x1484f3){var _0x57a8ea=typeof _0x3ece07[_0x1fe4('0x1a')]===_0x1fe4('0x1b')&&typeof _0x3ece07[_0x1fe4('0x1c')]===_0x1fe4('0x1b');var _0xa38ea3=_0x1484f3[_0x1fe4('0x1d')];var _0x20052a=_0x57a8ea?0x0:_0x3ece07[_0x1fe4('0x1a')];var _0x47f9ba=_0x57a8ea?_0x1484f3[_0x1fe4('0x1d')]:_0x3ece07[_0x1fe4('0x1a')]+_0x3ece07[_0x1fe4('0x1c')];var _0x4ba9ec;if(_0x47f9ba>=_0xa38ea3){_0x47f9ba=_0xa38ea3;_0x4ba9ec=0xc8;}else{_0x4ba9ec=0xce;}_0xedd23c[_0x1fe4('0x18')](_0x4ba9ec);return _0xedd23c['set'](_0x1fe4('0x1e'),_0x20052a+'-'+_0x47f9ba+'/'+_0xa38ea3)[_0x1fe4('0x19')](_0x1484f3);}return null;};}function patchUpdates(_0x4c590a){return function(_0xb41c98){try{jsonpatch[_0x1fe4('0x1f')](_0xb41c98,_0x4c590a,!![]);}catch(_0x1bfd8c){return BPromise[_0x1fe4('0x20')](_0x1bfd8c);}return _0xb41c98['save']();};}function saveUpdates(_0x240155,_0x41360c){return function(_0x9410fc){if(_0x9410fc){return _0x9410fc[_0x1fe4('0x21')](_0x240155)[_0x1fe4('0x22')](function(_0x472b5a){return _0x472b5a;});}return null;};}function removeEntity(_0x362284,_0x1c07f7){return function(_0x17ea79){if(_0x17ea79){return _0x17ea79[_0x1fe4('0x23')]()[_0x1fe4('0x22')](function(){_0x362284[_0x1fe4('0x18')](0xcc)[_0x1fe4('0x17')]();});}};}function handleEntityNotFound(_0x2966f6,_0x48b8cc){return function(_0x14bb41){if(!_0x14bb41){_0x2966f6['sendStatus'](0x194);}return _0x14bb41;};}function handleError(_0xefb67a,_0x595585){_0x595585=_0x595585||0x1f4;return function(_0x5d93eb){logger[_0x1fe4('0x24')](_0x5d93eb[_0x1fe4('0x25')]);if(_0x5d93eb[_0x1fe4('0x26')]){delete _0x5d93eb['name'];}_0xefb67a['status'](_0x595585)[_0x1fe4('0x27')](_0x5d93eb);};}function getMustacheRender(_0x51204f,_0x5a5ac6){return Mustache[_0x1fe4('0x28')](_0x51204f,_[_0x1fe4('0x29')](_0x5a5ac6[_0x1fe4('0x2a')],{'contact':_0x5a5ac6[_0x1fe4('0x2b')],'message':_0x5a5ac6['message'],'agent':_0x5a5ac6[_0x1fe4('0x2c')],'interaction':_0x5a5ac6[_0x1fe4('0x2d')],'account':_0x5a5ac6[_0x1fe4('0x2e')]}))||'';}exports[_0x1fe4('0x2f')]=function(_0x4f1579,_0xcd5a31){var _0x45d42b={},_0x4170ff={},_0x403b12={'count':0x0,'rows':[]};var _0x476c1f=_['map'](db['ChatTransferReport'][_0x1fe4('0x30')],function(_0x322b83){return{'name':_0x322b83[_0x1fe4('0x31')],'type':_0x322b83[_0x1fe4('0x32')]['key']};});_0x4170ff['model']=_[_0x1fe4('0x33')](_0x476c1f,_0x1fe4('0x26'));_0x4170ff[_0x1fe4('0x34')]=_[_0x1fe4('0x35')](_0x4f1579['query']);_0x4170ff['filters']=_['intersection'](_0x4170ff[_0x1fe4('0x36')],_0x4170ff[_0x1fe4('0x34')]);_0x45d42b[_0x1fe4('0x37')]=_[_0x1fe4('0x38')](_0x4170ff[_0x1fe4('0x36')],qs[_0x1fe4('0x39')](_0x4f1579[_0x1fe4('0x34')]['fields']));_0x45d42b[_0x1fe4('0x37')]=_0x45d42b[_0x1fe4('0x37')][_0x1fe4('0x3a')]?_0x45d42b[_0x1fe4('0x37')]:_0x4170ff[_0x1fe4('0x36')];if(!_0x4f1579[_0x1fe4('0x34')]['hasOwnProperty'](_0x1fe4('0x3b'))){_0x45d42b[_0x1fe4('0x1c')]=qs['limit'](_0x4f1579['query'][_0x1fe4('0x1c')]);_0x45d42b[_0x1fe4('0x1a')]=qs[_0x1fe4('0x1a')](_0x4f1579[_0x1fe4('0x34')][_0x1fe4('0x1a')]);}_0x45d42b[_0x1fe4('0x3c')]=qs['sort'](_0x4f1579[_0x1fe4('0x34')]['sort']);_0x45d42b[_0x1fe4('0x3d')]=qs[_0x1fe4('0x3e')](_[_0x1fe4('0x3f')](_0x4f1579['query'],_0x4170ff[_0x1fe4('0x3e')]),_0x476c1f);if(_0x4f1579[_0x1fe4('0x34')]['filter']){_0x45d42b[_0x1fe4('0x3d')]=_[_0x1fe4('0x29')](_0x45d42b[_0x1fe4('0x3d')],{'$or':_['map'](_0x476c1f,function(_0x11ed6f){if(_0x11ed6f[_0x1fe4('0x32')]!==_0x1fe4('0x40')){var _0x2c948e={};_0x2c948e[_0x11ed6f[_0x1fe4('0x26')]]={'$like':'%'+_0x4f1579[_0x1fe4('0x34')][_0x1fe4('0x41')]+'%'};return _0x2c948e;}})});}_0x45d42b=_[_0x1fe4('0x29')]({},_0x45d42b,_0x4f1579['options']);var _0x1429be={'where':_0x45d42b[_0x1fe4('0x3d')]};return db[_0x1fe4('0x42')][_0x1fe4('0x1d')](_0x1429be)[_0x1fe4('0x22')](function(_0x2f13d4){_0x403b12[_0x1fe4('0x1d')]=_0x2f13d4;if(_0x4f1579[_0x1fe4('0x34')]['includeAll']){_0x45d42b[_0x1fe4('0x43')]=[{'all':!![]}];}return db['ChatTransferReport'][_0x1fe4('0x44')](_0x45d42b);})[_0x1fe4('0x22')](function(_0x5cf77c){_0x403b12[_0x1fe4('0x45')]=_0x5cf77c;return _0x403b12;})[_0x1fe4('0x22')](respondWithFilteredResult(_0xcd5a31,_0x45d42b))[_0x1fe4('0x46')](handleError(_0xcd5a31,null));};exports[_0x1fe4('0x47')]=function(_0x42c57d,_0x1e5610){var _0x327e6c={'raw':!![],'where':{'id':_0x42c57d[_0x1fe4('0x48')]['id']}},_0x528d92={};_0x528d92[_0x1fe4('0x36')]=_['keys'](db['ChatTransferReport']['rawAttributes']);_0x528d92[_0x1fe4('0x34')]=_[_0x1fe4('0x35')](_0x42c57d['query']);_0x528d92[_0x1fe4('0x3e')]=_['intersection'](_0x528d92[_0x1fe4('0x36')],_0x528d92['query']);_0x327e6c[_0x1fe4('0x37')]=_[_0x1fe4('0x38')](_0x528d92[_0x1fe4('0x36')],qs[_0x1fe4('0x39')](_0x42c57d[_0x1fe4('0x34')]['fields']));_0x327e6c[_0x1fe4('0x37')]=_0x327e6c[_0x1fe4('0x37')][_0x1fe4('0x3a')]?_0x327e6c[_0x1fe4('0x37')]:_0x528d92['model'];if(_0x42c57d[_0x1fe4('0x34')][_0x1fe4('0x49')]){_0x327e6c[_0x1fe4('0x43')]=[{'all':!![]}];}_0x327e6c=_[_0x1fe4('0x29')]({},_0x327e6c,_0x42c57d['options']);return db[_0x1fe4('0x42')]['find'](_0x327e6c)['then'](handleEntityNotFound(_0x1e5610,null))[_0x1fe4('0x22')](respondWithResult(_0x1e5610,null))[_0x1fe4('0x46')](handleError(_0x1e5610,null));};exports['create']=function(_0x56616c,_0x438e33){return db[_0x1fe4('0x42')][_0x1fe4('0x4a')](_0x56616c[_0x1fe4('0x2a')],{})[_0x1fe4('0x22')](respondWithResult(_0x438e33,0xc9))[_0x1fe4('0x46')](handleError(_0x438e33,null));};exports[_0x1fe4('0x21')]=function(_0x388d96,_0x29b54b){if(_0x388d96[_0x1fe4('0x2a')]['id']){delete _0x388d96[_0x1fe4('0x2a')]['id'];}return db[_0x1fe4('0x42')][_0x1fe4('0x4b')]({'where':{'id':_0x388d96[_0x1fe4('0x48')]['id']}})[_0x1fe4('0x22')](handleEntityNotFound(_0x29b54b,null))['then'](saveUpdates(_0x388d96[_0x1fe4('0x2a')],null))[_0x1fe4('0x22')](respondWithResult(_0x29b54b,null))[_0x1fe4('0x46')](handleError(_0x29b54b,null));};exports[_0x1fe4('0x23')]=function(_0x4d622c,_0x74615){return db[_0x1fe4('0x42')][_0x1fe4('0x4b')]({'where':{'id':_0x4d622c[_0x1fe4('0x48')]['id']}})[_0x1fe4('0x22')](handleEntityNotFound(_0x74615,null))['then'](removeEntity(_0x74615,null))[_0x1fe4('0x46')](handleError(_0x74615,null));};exports['describe']=function(_0x419088,_0x25195b){return db[_0x1fe4('0x42')][_0x1fe4('0x4c')]()['then'](respondWithResult(_0x25195b,null))[_0x1fe4('0x46')](handleError(_0x25195b,null));};