Built motion from commit d69f4380.|2.6.29
[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 _0x44f6=['rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','status','end','json','limit','undefined','count','set','apply','reject','save','update','then','sendStatus','error','name','send','index','ChatTransferReport','rawAttributes','fieldName','type','model','map','query','keys','filters','fields','attributes','hasOwnProperty','offset','order','sort','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','catch','show','params','intersection','length','find','create','body','destroy','describe','eml-format'];(function(_0x421924,_0x15d560){var _0x10b657=function(_0x355529){while(--_0x355529){_0x421924['push'](_0x421924['shift']());}};_0x10b657(++_0x15d560);}(_0x44f6,0x171));var _0x644f=function(_0x4b73a2,_0x40b5fe){_0x4b73a2=_0x4b73a2-0x0;var _0x383c66=_0x44f6[_0x4b73a2];return _0x383c66;};'use strict';var emlformat=require(_0x644f('0x0'));var rimraf=require(_0x644f('0x1'));var zipdir=require(_0x644f('0x2'));var jsonpatch=require(_0x644f('0x3'));var rp=require(_0x644f('0x4'));var moment=require(_0x644f('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x644f('0x6'));var util=require(_0x644f('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x644f('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x644f('0x9'));var _=require(_0x644f('0xa'));var squel=require(_0x644f('0xb'));var crypto=require('crypto');var jsforce=require(_0x644f('0xc'));var deskjs=require(_0x644f('0xd'));var toCsv=require(_0x644f('0x8'));var querystring=require(_0x644f('0xe'));var Papa=require('papaparse');var Redis=require(_0x644f('0xf'));var authService=require(_0x644f('0x10'));var qs=require(_0x644f('0x11'));var as=require(_0x644f('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x644f('0x13'))(_0x644f('0x14'));var utils=require(_0x644f('0x15'));var config=require(_0x644f('0x16'));var licenseUtil=require(_0x644f('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xf97c15,_0x57702c){_0x57702c=_0x57702c||0xcc;return function(_0x1eaf01){if(_0x1eaf01){return _0xf97c15['sendStatus'](_0x57702c);}return _0xf97c15[_0x644f('0x18')](_0x57702c)[_0x644f('0x19')]();};}function respondWithResult(_0x1e52a,_0x592f83){_0x592f83=_0x592f83||0xc8;return function(_0x300124){if(_0x300124){return _0x1e52a['status'](_0x592f83)[_0x644f('0x1a')](_0x300124);}};}function respondWithFilteredResult(_0xe8155c,_0x38c640){return function(_0x4333f4){if(_0x4333f4){var _0x889153=typeof _0x38c640['offset']==='undefined'&&typeof _0x38c640[_0x644f('0x1b')]===_0x644f('0x1c');var _0x1fe32e=_0x4333f4[_0x644f('0x1d')];var _0x59d9b0=_0x889153?0x0:_0x38c640['offset'];var _0x5540a5=_0x889153?_0x4333f4[_0x644f('0x1d')]:_0x38c640['offset']+_0x38c640[_0x644f('0x1b')];var _0x58c2a7;if(_0x5540a5>=_0x1fe32e){_0x5540a5=_0x1fe32e;_0x58c2a7=0xc8;}else{_0x58c2a7=0xce;}_0xe8155c[_0x644f('0x18')](_0x58c2a7);return _0xe8155c[_0x644f('0x1e')]('Content-Range',_0x59d9b0+'-'+_0x5540a5+'/'+_0x1fe32e)[_0x644f('0x1a')](_0x4333f4);}return null;};}function patchUpdates(_0x40e6bf){return function(_0xc783ae){try{jsonpatch[_0x644f('0x1f')](_0xc783ae,_0x40e6bf,!![]);}catch(_0x3497a3){return BPromise[_0x644f('0x20')](_0x3497a3);}return _0xc783ae[_0x644f('0x21')]();};}function saveUpdates(_0x240cdc,_0x3db17c){return function(_0x95d68b){if(_0x95d68b){return _0x95d68b[_0x644f('0x22')](_0x240cdc)['then'](function(_0x3ccb6c){return _0x3ccb6c;});}return null;};}function removeEntity(_0x2d1aa1,_0x4b9fe3){return function(_0x21d97a){if(_0x21d97a){return _0x21d97a['destroy']()[_0x644f('0x23')](function(){_0x2d1aa1['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x166706,_0x4d8a94){return function(_0x578c09){if(!_0x578c09){_0x166706[_0x644f('0x24')](0x194);}return _0x578c09;};}function handleError(_0xd601,_0x22add3){_0x22add3=_0x22add3||0x1f4;return function(_0x12f7d3){logger[_0x644f('0x25')](_0x12f7d3['stack']);if(_0x12f7d3[_0x644f('0x26')]){delete _0x12f7d3['name'];}_0xd601[_0x644f('0x18')](_0x22add3)[_0x644f('0x27')](_0x12f7d3);};}exports[_0x644f('0x28')]=function(_0x22e45a,_0x349292){var _0x44a3ac={},_0x21d33f={},_0x266679={'count':0x0,'rows':[]};var _0x414d9a=_['map'](db[_0x644f('0x29')][_0x644f('0x2a')],function(_0x3d8d3f){return{'name':_0x3d8d3f[_0x644f('0x2b')],'type':_0x3d8d3f[_0x644f('0x2c')]['key']};});_0x21d33f[_0x644f('0x2d')]=_[_0x644f('0x2e')](_0x414d9a,'name');_0x21d33f[_0x644f('0x2f')]=_[_0x644f('0x30')](_0x22e45a[_0x644f('0x2f')]);_0x21d33f[_0x644f('0x31')]=_['intersection'](_0x21d33f[_0x644f('0x2d')],_0x21d33f[_0x644f('0x2f')]);_0x44a3ac['attributes']=_['intersection'](_0x21d33f[_0x644f('0x2d')],qs[_0x644f('0x32')](_0x22e45a[_0x644f('0x2f')][_0x644f('0x32')]));_0x44a3ac[_0x644f('0x33')]=_0x44a3ac[_0x644f('0x33')]['length']?_0x44a3ac[_0x644f('0x33')]:_0x21d33f[_0x644f('0x2d')];if(!_0x22e45a['query'][_0x644f('0x34')]('nolimit')){_0x44a3ac[_0x644f('0x1b')]=qs[_0x644f('0x1b')](_0x22e45a[_0x644f('0x2f')][_0x644f('0x1b')]);_0x44a3ac[_0x644f('0x35')]=qs['offset'](_0x22e45a[_0x644f('0x2f')]['offset']);}_0x44a3ac[_0x644f('0x36')]=qs[_0x644f('0x37')](_0x22e45a[_0x644f('0x2f')][_0x644f('0x37')]);_0x44a3ac[_0x644f('0x38')]=qs[_0x644f('0x31')](_['pick'](_0x22e45a[_0x644f('0x2f')],_0x21d33f[_0x644f('0x31')]),_0x414d9a);if(_0x22e45a[_0x644f('0x2f')]['filter']){_0x44a3ac[_0x644f('0x38')]=_[_0x644f('0x39')](_0x44a3ac[_0x644f('0x38')],{'$or':_[_0x644f('0x2e')](_0x414d9a,function(_0x588ab9){if(_0x588ab9[_0x644f('0x2c')]!==_0x644f('0x3a')){var _0x341b37={};_0x341b37[_0x588ab9[_0x644f('0x26')]]={'$like':'%'+_0x22e45a[_0x644f('0x2f')][_0x644f('0x3b')]+'%'};return _0x341b37;}})});}_0x44a3ac=_['merge']({},_0x44a3ac,_0x22e45a[_0x644f('0x3c')]);var _0x4937de={'where':_0x44a3ac[_0x644f('0x38')]};return db['ChatTransferReport']['count'](_0x4937de)[_0x644f('0x23')](function(_0x12c09d){_0x266679[_0x644f('0x1d')]=_0x12c09d;if(_0x22e45a['query'][_0x644f('0x3d')]){_0x44a3ac[_0x644f('0x3e')]=[{'all':!![]}];}return db[_0x644f('0x29')][_0x644f('0x3f')](_0x44a3ac);})[_0x644f('0x23')](function(_0x490de7){_0x266679['rows']=_0x490de7;return _0x266679;})['then'](respondWithFilteredResult(_0x349292,_0x44a3ac))[_0x644f('0x40')](handleError(_0x349292,null));};exports[_0x644f('0x41')]=function(_0x4914f8,_0x3b0951){var _0x544320={'raw':!![],'where':{'id':_0x4914f8[_0x644f('0x42')]['id']}},_0x26a871={};_0x26a871[_0x644f('0x2d')]=_[_0x644f('0x30')](db[_0x644f('0x29')]['rawAttributes']);_0x26a871['query']=_['keys'](_0x4914f8[_0x644f('0x2f')]);_0x26a871[_0x644f('0x31')]=_[_0x644f('0x43')](_0x26a871[_0x644f('0x2d')],_0x26a871['query']);_0x544320[_0x644f('0x33')]=_[_0x644f('0x43')](_0x26a871[_0x644f('0x2d')],qs['fields'](_0x4914f8[_0x644f('0x2f')][_0x644f('0x32')]));_0x544320['attributes']=_0x544320[_0x644f('0x33')][_0x644f('0x44')]?_0x544320[_0x644f('0x33')]:_0x26a871[_0x644f('0x2d')];if(_0x4914f8[_0x644f('0x2f')][_0x644f('0x3d')]){_0x544320[_0x644f('0x3e')]=[{'all':!![]}];}_0x544320=_[_0x644f('0x39')]({},_0x544320,_0x4914f8[_0x644f('0x3c')]);return db[_0x644f('0x29')][_0x644f('0x45')](_0x544320)[_0x644f('0x23')](handleEntityNotFound(_0x3b0951,null))['then'](respondWithResult(_0x3b0951,null))[_0x644f('0x40')](handleError(_0x3b0951,null));};exports[_0x644f('0x46')]=function(_0x5de413,_0x1c045c){return db[_0x644f('0x29')][_0x644f('0x46')](_0x5de413[_0x644f('0x47')],{})[_0x644f('0x23')](respondWithResult(_0x1c045c,0xc9))[_0x644f('0x40')](handleError(_0x1c045c,null));};exports[_0x644f('0x22')]=function(_0x1b6f50,_0x2c677e){if(_0x1b6f50[_0x644f('0x47')]['id']){delete _0x1b6f50[_0x644f('0x47')]['id'];}return db[_0x644f('0x29')][_0x644f('0x45')]({'where':{'id':_0x1b6f50[_0x644f('0x42')]['id']}})['then'](handleEntityNotFound(_0x2c677e,null))[_0x644f('0x23')](saveUpdates(_0x1b6f50[_0x644f('0x47')],null))[_0x644f('0x23')](respondWithResult(_0x2c677e,null))[_0x644f('0x40')](handleError(_0x2c677e,null));};exports[_0x644f('0x48')]=function(_0x3cf45c,_0x2c381a){return db['ChatTransferReport'][_0x644f('0x45')]({'where':{'id':_0x3cf45c[_0x644f('0x42')]['id']}})['then'](handleEntityNotFound(_0x2c381a,null))[_0x644f('0x23')](removeEntity(_0x2c381a,null))[_0x644f('0x40')](handleError(_0x2c381a,null));};exports[_0x644f('0x49')]=function(_0x594c37,_0x5327b4){return db[_0x644f('0x29')][_0x644f('0x49')]()[_0x644f('0x23')](respondWithResult(_0x5327b4,null))['catch'](handleError(_0x5327b4,null));};