Built motion from commit f7863d46.|2.5.41
[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 _0x756f=['keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','include','findAll','catch','params','includeAll','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','count','limit','set','json','apply','save','update','then','destroy','end','stack','name','send','ChatTransferReport','rawAttributes','fieldName','type','key','model','map','query'];(function(_0x1b2ff7,_0x12a034){var _0x31656a=function(_0x1165a5){while(--_0x1165a5){_0x1b2ff7['push'](_0x1b2ff7['shift']());}};_0x31656a(++_0x12a034);}(_0x756f,0x137));var _0xf756=function(_0x778a18,_0x26f54d){_0x778a18=_0x778a18-0x0;var _0x354822=_0x756f[_0x778a18];return _0x354822;};'use strict';var emlformat=require(_0xf756('0x0'));var rimraf=require(_0xf756('0x1'));var zipdir=require(_0xf756('0x2'));var jsonpatch=require(_0xf756('0x3'));var rp=require('request-promise');var moment=require(_0xf756('0x4'));var BPromise=require(_0xf756('0x5'));var Mustache=require(_0xf756('0x6'));var util=require(_0xf756('0x7'));var path=require(_0xf756('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf756('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf756('0xa'));var squel=require(_0xf756('0xb'));var crypto=require(_0xf756('0xc'));var jsforce=require(_0xf756('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xf756('0xe'));var Papa=require(_0xf756('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xf756('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf756('0x11'));var logger=require(_0xf756('0x12'))(_0xf756('0x13'));var utils=require(_0xf756('0x14'));var config=require(_0xf756('0x15'));var licenseUtil=require(_0xf756('0x16'));var db=require(_0xf756('0x17'))['db'];function respondWithStatusCode(_0x24e0b9,_0x43d40c){_0x43d40c=_0x43d40c||0xcc;return function(_0x3e2ce7){if(_0x3e2ce7){return _0x24e0b9[_0xf756('0x18')](_0x43d40c);}return _0x24e0b9[_0xf756('0x19')](_0x43d40c)['end']();};}function respondWithResult(_0x159436,_0x35f91d){_0x35f91d=_0x35f91d||0xc8;return function(_0x31e27e){if(_0x31e27e){return _0x159436['status'](_0x35f91d)['json'](_0x31e27e);}};}function respondWithFilteredResult(_0x560976,_0x532520){return function(_0x479e90){if(_0x479e90){var _0x4a340f=typeof _0x532520[_0xf756('0x1a')]==='undefined'&&typeof _0x532520['limit']===_0xf756('0x1b');var _0x2bcea4=_0x479e90[_0xf756('0x1c')];var _0x2b6430=_0x4a340f?0x0:_0x532520[_0xf756('0x1a')];var _0x348fdc=_0x4a340f?_0x479e90['count']:_0x532520[_0xf756('0x1a')]+_0x532520[_0xf756('0x1d')];var _0x3b32f8;if(_0x348fdc>=_0x2bcea4){_0x348fdc=_0x2bcea4;_0x3b32f8=0xc8;}else{_0x3b32f8=0xce;}_0x560976[_0xf756('0x19')](_0x3b32f8);return _0x560976[_0xf756('0x1e')]('Content-Range',_0x2b6430+'-'+_0x348fdc+'/'+_0x2bcea4)[_0xf756('0x1f')](_0x479e90);}return null;};}function patchUpdates(_0x1f481a){return function(_0x210f2e){try{jsonpatch[_0xf756('0x20')](_0x210f2e,_0x1f481a,!![]);}catch(_0x56c9d4){return BPromise['reject'](_0x56c9d4);}return _0x210f2e[_0xf756('0x21')]();};}function saveUpdates(_0x4399c7,_0x198613){return function(_0x1af286){if(_0x1af286){return _0x1af286[_0xf756('0x22')](_0x4399c7)[_0xf756('0x23')](function(_0x252112){return _0x252112;});}return null;};}function removeEntity(_0x36d62c,_0x4075b5){return function(_0x58117d){if(_0x58117d){return _0x58117d[_0xf756('0x24')]()[_0xf756('0x23')](function(){_0x36d62c[_0xf756('0x19')](0xcc)[_0xf756('0x25')]();});}};}function handleEntityNotFound(_0x22eb27,_0x126dc1){return function(_0x53cdcb){if(!_0x53cdcb){_0x22eb27[_0xf756('0x18')](0x194);}return _0x53cdcb;};}function handleError(_0x1df3ef,_0xb40b97){_0xb40b97=_0xb40b97||0x1f4;return function(_0x2fb858){logger['error'](_0x2fb858[_0xf756('0x26')]);if(_0x2fb858[_0xf756('0x27')]){delete _0x2fb858[_0xf756('0x27')];}_0x1df3ef[_0xf756('0x19')](_0xb40b97)[_0xf756('0x28')](_0x2fb858);};}exports['index']=function(_0x186a10,_0x2ad930){var _0x2da963={},_0x2d84f4={},_0x100e92={'count':0x0,'rows':[]};var _0x4fb308=_['map'](db[_0xf756('0x29')][_0xf756('0x2a')],function(_0x59266e){return{'name':_0x59266e[_0xf756('0x2b')],'type':_0x59266e[_0xf756('0x2c')][_0xf756('0x2d')]};});_0x2d84f4[_0xf756('0x2e')]=_[_0xf756('0x2f')](_0x4fb308,_0xf756('0x27'));_0x2d84f4[_0xf756('0x30')]=_[_0xf756('0x31')](_0x186a10[_0xf756('0x30')]);_0x2d84f4[_0xf756('0x32')]=_[_0xf756('0x33')](_0x2d84f4['model'],_0x2d84f4[_0xf756('0x30')]);_0x2da963['attributes']=_[_0xf756('0x33')](_0x2d84f4['model'],qs[_0xf756('0x34')](_0x186a10[_0xf756('0x30')]['fields']));_0x2da963[_0xf756('0x35')]=_0x2da963[_0xf756('0x35')][_0xf756('0x36')]?_0x2da963[_0xf756('0x35')]:_0x2d84f4[_0xf756('0x2e')];if(!_0x186a10[_0xf756('0x30')][_0xf756('0x37')](_0xf756('0x38'))){_0x2da963[_0xf756('0x1d')]=qs[_0xf756('0x1d')](_0x186a10[_0xf756('0x30')]['limit']);_0x2da963[_0xf756('0x1a')]=qs[_0xf756('0x1a')](_0x186a10[_0xf756('0x30')][_0xf756('0x1a')]);}_0x2da963['order']=qs[_0xf756('0x39')](_0x186a10[_0xf756('0x30')][_0xf756('0x39')]);_0x2da963[_0xf756('0x3a')]=qs[_0xf756('0x32')](_['pick'](_0x186a10[_0xf756('0x30')],_0x2d84f4[_0xf756('0x32')]),_0x4fb308);if(_0x186a10[_0xf756('0x30')][_0xf756('0x3b')]){_0x2da963[_0xf756('0x3a')]=_[_0xf756('0x3c')](_0x2da963[_0xf756('0x3a')],{'$or':_[_0xf756('0x2f')](_0x4fb308,function(_0x119178){if(_0x119178[_0xf756('0x2c')]!==_0xf756('0x3d')){var _0x2cf443={};_0x2cf443[_0x119178[_0xf756('0x27')]]={'$like':'%'+_0x186a10[_0xf756('0x30')][_0xf756('0x3b')]+'%'};return _0x2cf443;}})});}_0x2da963=_['merge']({},_0x2da963,_0x186a10[_0xf756('0x3e')]);var _0x35576c={'where':_0x2da963['where']};return db['ChatTransferReport'][_0xf756('0x1c')](_0x35576c)[_0xf756('0x23')](function(_0x39f2db){_0x100e92[_0xf756('0x1c')]=_0x39f2db;if(_0x186a10[_0xf756('0x30')]['includeAll']){_0x2da963[_0xf756('0x3f')]=[{'all':!![]}];}return db[_0xf756('0x29')][_0xf756('0x40')](_0x2da963);})[_0xf756('0x23')](function(_0x2e3754){_0x100e92['rows']=_0x2e3754;return _0x100e92;})['then'](respondWithFilteredResult(_0x2ad930,_0x2da963))[_0xf756('0x41')](handleError(_0x2ad930,null));};exports['show']=function(_0x1b1a93,_0x1e1efa){var _0x4f0d8a={'raw':!![],'where':{'id':_0x1b1a93[_0xf756('0x42')]['id']}},_0xa3804d={};_0xa3804d[_0xf756('0x2e')]=_[_0xf756('0x31')](db['ChatTransferReport'][_0xf756('0x2a')]);_0xa3804d[_0xf756('0x30')]=_[_0xf756('0x31')](_0x1b1a93['query']);_0xa3804d[_0xf756('0x32')]=_[_0xf756('0x33')](_0xa3804d['model'],_0xa3804d[_0xf756('0x30')]);_0x4f0d8a[_0xf756('0x35')]=_['intersection'](_0xa3804d[_0xf756('0x2e')],qs['fields'](_0x1b1a93['query'][_0xf756('0x34')]));_0x4f0d8a[_0xf756('0x35')]=_0x4f0d8a['attributes'][_0xf756('0x36')]?_0x4f0d8a[_0xf756('0x35')]:_0xa3804d['model'];if(_0x1b1a93['query'][_0xf756('0x43')]){_0x4f0d8a[_0xf756('0x3f')]=[{'all':!![]}];}_0x4f0d8a=_[_0xf756('0x3c')]({},_0x4f0d8a,_0x1b1a93[_0xf756('0x3e')]);return db[_0xf756('0x29')][_0xf756('0x44')](_0x4f0d8a)[_0xf756('0x23')](handleEntityNotFound(_0x1e1efa,null))['then'](respondWithResult(_0x1e1efa,null))['catch'](handleError(_0x1e1efa,null));};exports[_0xf756('0x45')]=function(_0xf70b8,_0x34365a){return db[_0xf756('0x29')][_0xf756('0x45')](_0xf70b8['body'],{})['then'](respondWithResult(_0x34365a,0xc9))[_0xf756('0x41')](handleError(_0x34365a,null));};exports['update']=function(_0x3b543a,_0x5a3ca2){if(_0x3b543a[_0xf756('0x46')]['id']){delete _0x3b543a[_0xf756('0x46')]['id'];}return db[_0xf756('0x29')]['find']({'where':{'id':_0x3b543a[_0xf756('0x42')]['id']}})[_0xf756('0x23')](handleEntityNotFound(_0x5a3ca2,null))[_0xf756('0x23')](saveUpdates(_0x3b543a['body'],null))[_0xf756('0x23')](respondWithResult(_0x5a3ca2,null))[_0xf756('0x41')](handleError(_0x5a3ca2,null));};exports['destroy']=function(_0x48d859,_0x56045b){return db[_0xf756('0x29')]['find']({'where':{'id':_0x48d859[_0xf756('0x42')]['id']}})[_0xf756('0x23')](handleEntityNotFound(_0x56045b,null))[_0xf756('0x23')](removeEntity(_0x56045b,null))[_0xf756('0x41')](handleError(_0x56045b,null));};exports[_0xf756('0x47')]=function(_0x2f5305,_0x1b4512){return db[_0xf756('0x29')][_0xf756('0x47')]()[_0xf756('0x23')](respondWithResult(_0x1b4512,null))[_0xf756('0x41')](handleError(_0x1b4512,null));};