e498d9529a5ced02cefcb938178e69ecdadf8d7e
[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 _0xc309=['name','send','index','map','ChatTransferReport','fieldName','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','limit','offset','order','sort','where','pick','type','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','lodash','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','count','reject','save','update','then','destroy','end','stack'];(function(_0x3a26b7,_0x46d681){var _0x13f87a=function(_0xd0c69d){while(--_0xd0c69d){_0x3a26b7['push'](_0x3a26b7['shift']());}};_0x13f87a(++_0x46d681);}(_0xc309,0xf8));var _0x9c30=function(_0x18059e,_0x4f3986){_0x18059e=_0x18059e-0x0;var _0x4d2759=_0xc309[_0x18059e];return _0x4d2759;};'use strict';var emlformat=require(_0x9c30('0x0'));var rimraf=require(_0x9c30('0x1'));var zipdir=require(_0x9c30('0x2'));var jsonpatch=require(_0x9c30('0x3'));var rp=require(_0x9c30('0x4'));var moment=require(_0x9c30('0x5'));var BPromise=require(_0x9c30('0x6'));var Mustache=require('mustache');var util=require(_0x9c30('0x7'));var path=require(_0x9c30('0x8'));var sox=require(_0x9c30('0x9'));var csv=require('to-csv');var ejs=require(_0x9c30('0xa'));var fs=require('fs');var fs_extra=require(_0x9c30('0xb'));var _=require(_0x9c30('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x9c30('0xd'));var toCsv=require('to-csv');var querystring=require(_0x9c30('0xe'));var Papa=require(_0x9c30('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x9c30('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9c30('0x11'));var logger=require(_0x9c30('0x12'))(_0x9c30('0x13'));var utils=require(_0x9c30('0x14'));var config=require(_0x9c30('0x15'));var licenseUtil=require(_0x9c30('0x16'));var db=require(_0x9c30('0x17'))['db'];function respondWithStatusCode(_0x2eb043,_0x1d18d3){_0x1d18d3=_0x1d18d3||0xcc;return function(_0x5483dd){if(_0x5483dd){return _0x2eb043[_0x9c30('0x18')](_0x1d18d3);}return _0x2eb043['status'](_0x1d18d3)['end']();};}function respondWithResult(_0x2dcdae,_0x21f0a6){_0x21f0a6=_0x21f0a6||0xc8;return function(_0x40afa1){if(_0x40afa1){return _0x2dcdae[_0x9c30('0x19')](_0x21f0a6)[_0x9c30('0x1a')](_0x40afa1);}};}function respondWithFilteredResult(_0x36ee6e,_0x5849c9){return function(_0x3bacfc){if(_0x3bacfc){var _0x145167=typeof _0x5849c9['offset']==='undefined'&&typeof _0x5849c9['limit']===_0x9c30('0x1b');var _0x34f46e=_0x3bacfc[_0x9c30('0x1c')];var _0x241da1=_0x145167?0x0:_0x5849c9['offset'];var _0x574b44=_0x145167?_0x3bacfc[_0x9c30('0x1c')]:_0x5849c9['offset']+_0x5849c9['limit'];var _0x1f2f9a;if(_0x574b44>=_0x34f46e){_0x574b44=_0x34f46e;_0x1f2f9a=0xc8;}else{_0x1f2f9a=0xce;}_0x36ee6e[_0x9c30('0x19')](_0x1f2f9a);return _0x36ee6e['set']('Content-Range',_0x241da1+'-'+_0x574b44+'/'+_0x34f46e)[_0x9c30('0x1a')](_0x3bacfc);}return null;};}function patchUpdates(_0x130762){return function(_0x1a4d32){try{jsonpatch['apply'](_0x1a4d32,_0x130762,!![]);}catch(_0x1b0d8b){return BPromise[_0x9c30('0x1d')](_0x1b0d8b);}return _0x1a4d32[_0x9c30('0x1e')]();};}function saveUpdates(_0x897be2,_0x68664){return function(_0x55f1ac){if(_0x55f1ac){return _0x55f1ac[_0x9c30('0x1f')](_0x897be2)[_0x9c30('0x20')](function(_0x276c56){return _0x276c56;});}return null;};}function removeEntity(_0x2a01f3,_0x5ea073){return function(_0x57063c){if(_0x57063c){return _0x57063c[_0x9c30('0x21')]()[_0x9c30('0x20')](function(){_0x2a01f3[_0x9c30('0x19')](0xcc)[_0x9c30('0x22')]();});}};}function handleEntityNotFound(_0xf5e51d,_0x3cf792){return function(_0x1f28c2){if(!_0x1f28c2){_0xf5e51d[_0x9c30('0x18')](0x194);}return _0x1f28c2;};}function handleError(_0x252325,_0x54d53e){_0x54d53e=_0x54d53e||0x1f4;return function(_0x3a56ae){logger['error'](_0x3a56ae[_0x9c30('0x23')]);if(_0x3a56ae[_0x9c30('0x24')]){delete _0x3a56ae[_0x9c30('0x24')];}_0x252325[_0x9c30('0x19')](_0x54d53e)[_0x9c30('0x25')](_0x3a56ae);};}exports[_0x9c30('0x26')]=function(_0x5afdf6,_0x4c0081){var _0x51d268={},_0xcfa735={},_0x849a47={'count':0x0,'rows':[]};var _0x404b70=_[_0x9c30('0x27')](db[_0x9c30('0x28')]['rawAttributes'],function(_0x24a922){return{'name':_0x24a922[_0x9c30('0x29')],'type':_0x24a922['type']['key']};});_0xcfa735[_0x9c30('0x2a')]=_[_0x9c30('0x27')](_0x404b70,_0x9c30('0x24'));_0xcfa735['query']=_[_0x9c30('0x2b')](_0x5afdf6[_0x9c30('0x2c')]);_0xcfa735[_0x9c30('0x2d')]=_[_0x9c30('0x2e')](_0xcfa735[_0x9c30('0x2a')],_0xcfa735[_0x9c30('0x2c')]);_0x51d268[_0x9c30('0x2f')]=_['intersection'](_0xcfa735[_0x9c30('0x2a')],qs[_0x9c30('0x30')](_0x5afdf6['query']['fields']));_0x51d268[_0x9c30('0x2f')]=_0x51d268[_0x9c30('0x2f')]['length']?_0x51d268[_0x9c30('0x2f')]:_0xcfa735[_0x9c30('0x2a')];if(!_0x5afdf6[_0x9c30('0x2c')][_0x9c30('0x31')]('nolimit')){_0x51d268[_0x9c30('0x32')]=qs['limit'](_0x5afdf6['query'][_0x9c30('0x32')]);_0x51d268[_0x9c30('0x33')]=qs[_0x9c30('0x33')](_0x5afdf6[_0x9c30('0x2c')][_0x9c30('0x33')]);}_0x51d268[_0x9c30('0x34')]=qs[_0x9c30('0x35')](_0x5afdf6[_0x9c30('0x2c')][_0x9c30('0x35')]);_0x51d268[_0x9c30('0x36')]=qs[_0x9c30('0x2d')](_[_0x9c30('0x37')](_0x5afdf6[_0x9c30('0x2c')],_0xcfa735[_0x9c30('0x2d')]),_0x404b70);if(_0x5afdf6[_0x9c30('0x2c')]['filter']){_0x51d268[_0x9c30('0x36')]=_['merge'](_0x51d268[_0x9c30('0x36')],{'$or':_['map'](_0x404b70,function(_0x3517dd){if(_0x3517dd[_0x9c30('0x38')]!==_0x9c30('0x39')){var _0xba04fa={};_0xba04fa[_0x3517dd[_0x9c30('0x24')]]={'$like':'%'+_0x5afdf6[_0x9c30('0x2c')]['filter']+'%'};return _0xba04fa;}})});}_0x51d268=_[_0x9c30('0x3a')]({},_0x51d268,_0x5afdf6[_0x9c30('0x3b')]);var _0x19fcc1={'where':_0x51d268[_0x9c30('0x36')]};return db[_0x9c30('0x28')][_0x9c30('0x1c')](_0x19fcc1)[_0x9c30('0x20')](function(_0x1a67b7){_0x849a47[_0x9c30('0x1c')]=_0x1a67b7;if(_0x5afdf6[_0x9c30('0x2c')][_0x9c30('0x3c')]){_0x51d268[_0x9c30('0x3d')]=[{'all':!![]}];}return db['ChatTransferReport'][_0x9c30('0x3e')](_0x51d268);})[_0x9c30('0x20')](function(_0x46ace6){_0x849a47[_0x9c30('0x3f')]=_0x46ace6;return _0x849a47;})[_0x9c30('0x20')](respondWithFilteredResult(_0x4c0081,_0x51d268))[_0x9c30('0x40')](handleError(_0x4c0081,null));};exports[_0x9c30('0x41')]=function(_0x48f937,_0x6a52c1){var _0x16bb5f={'raw':!![],'where':{'id':_0x48f937[_0x9c30('0x42')]['id']}},_0x5f5297={};_0x5f5297[_0x9c30('0x2a')]=_[_0x9c30('0x2b')](db[_0x9c30('0x28')]['rawAttributes']);_0x5f5297['query']=_[_0x9c30('0x2b')](_0x48f937[_0x9c30('0x2c')]);_0x5f5297[_0x9c30('0x2d')]=_[_0x9c30('0x2e')](_0x5f5297['model'],_0x5f5297[_0x9c30('0x2c')]);_0x16bb5f[_0x9c30('0x2f')]=_[_0x9c30('0x2e')](_0x5f5297[_0x9c30('0x2a')],qs[_0x9c30('0x30')](_0x48f937['query'][_0x9c30('0x30')]));_0x16bb5f['attributes']=_0x16bb5f[_0x9c30('0x2f')]['length']?_0x16bb5f[_0x9c30('0x2f')]:_0x5f5297[_0x9c30('0x2a')];if(_0x48f937[_0x9c30('0x2c')][_0x9c30('0x3c')]){_0x16bb5f[_0x9c30('0x3d')]=[{'all':!![]}];}_0x16bb5f=_[_0x9c30('0x3a')]({},_0x16bb5f,_0x48f937['options']);return db[_0x9c30('0x28')][_0x9c30('0x43')](_0x16bb5f)[_0x9c30('0x20')](handleEntityNotFound(_0x6a52c1,null))[_0x9c30('0x20')](respondWithResult(_0x6a52c1,null))['catch'](handleError(_0x6a52c1,null));};exports[_0x9c30('0x44')]=function(_0x2617de,_0x387d70){return db[_0x9c30('0x28')][_0x9c30('0x44')](_0x2617de['body'],{})['then'](respondWithResult(_0x387d70,0xc9))[_0x9c30('0x40')](handleError(_0x387d70,null));};exports[_0x9c30('0x1f')]=function(_0x315103,_0x577503){if(_0x315103[_0x9c30('0x45')]['id']){delete _0x315103[_0x9c30('0x45')]['id'];}return db[_0x9c30('0x28')][_0x9c30('0x43')]({'where':{'id':_0x315103[_0x9c30('0x42')]['id']}})[_0x9c30('0x20')](handleEntityNotFound(_0x577503,null))[_0x9c30('0x20')](saveUpdates(_0x315103[_0x9c30('0x45')],null))['then'](respondWithResult(_0x577503,null))[_0x9c30('0x40')](handleError(_0x577503,null));};exports['destroy']=function(_0xf3ddad,_0x5c2305){return db[_0x9c30('0x28')][_0x9c30('0x43')]({'where':{'id':_0xf3ddad[_0x9c30('0x42')]['id']}})[_0x9c30('0x20')](handleEntityNotFound(_0x5c2305,null))[_0x9c30('0x20')](removeEntity(_0x5c2305,null))['catch'](handleError(_0x5c2305,null));};exports[_0x9c30('0x46')]=function(_0x393b81,_0x32f67c){return db['ChatTransferReport']['describe']()[_0x9c30('0x20')](respondWithResult(_0x32f67c,null))[_0x9c30('0x40')](handleError(_0x32f67c,null));};