2e3e0c4507d1c4d7168d3e585a873776f359c15a
[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 _0x2ff8=['order','sort','where','filters','pick','merge','type','filter','options','ChatTransferReport','rows','catch','show','fields','length','includeAll','include','create','body','find','params','describe','rimraf','zip-dir','request-promise','moment','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','limit','count','offset','reject','save','update','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','key','keys','query','intersection','model','attributes','hasOwnProperty','nolimit'];(function(_0x46e3ff,_0x50ca39){var _0x4bf847=function(_0x3fa9b9){while(--_0x3fa9b9){_0x46e3ff['push'](_0x46e3ff['shift']());}};_0x4bf847(++_0x50ca39);}(_0x2ff8,0xa4));var _0x82ff=function(_0xa6cc5c,_0x239c99){_0xa6cc5c=_0xa6cc5c-0x0;var _0x44803d=_0x2ff8[_0xa6cc5c];return _0x44803d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x82ff('0x0'));var zipdir=require(_0x82ff('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x82ff('0x2'));var moment=require(_0x82ff('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x82ff('0x4'));var sox=require(_0x82ff('0x5'));var csv=require(_0x82ff('0x6'));var ejs=require(_0x82ff('0x7'));var fs=require('fs');var fs_extra=require(_0x82ff('0x8'));var _=require(_0x82ff('0x9'));var squel=require(_0x82ff('0xa'));var crypto=require('crypto');var jsforce=require(_0x82ff('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x82ff('0x6'));var querystring=require(_0x82ff('0xc'));var Papa=require(_0x82ff('0xd'));var Redis=require(_0x82ff('0xe'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x82ff('0xf'));var hardwareService=require(_0x82ff('0x10'));var logger=require('../../config/logger')('api');var utils=require(_0x82ff('0x11'));var config=require(_0x82ff('0x12'));var licenseUtil=require(_0x82ff('0x13'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x228b0e,_0x2ced18){_0x2ced18=_0x2ced18||0xcc;return function(_0x1d15e9){if(_0x1d15e9){return _0x228b0e[_0x82ff('0x14')](_0x2ced18);}return _0x228b0e[_0x82ff('0x15')](_0x2ced18)[_0x82ff('0x16')]();};}function respondWithResult(_0x23c524,_0x5446bb){_0x5446bb=_0x5446bb||0xc8;return function(_0xc3411a){if(_0xc3411a){return _0x23c524[_0x82ff('0x15')](_0x5446bb)[_0x82ff('0x17')](_0xc3411a);}};}function respondWithFilteredResult(_0x1fb8df,_0x253d48){return function(_0xc6b0db){if(_0xc6b0db){var _0x4a1e57=typeof _0x253d48['offset']===_0x82ff('0x18')&&typeof _0x253d48[_0x82ff('0x19')]===_0x82ff('0x18');var _0x9bb9c=_0xc6b0db[_0x82ff('0x1a')];var _0x42eb82=_0x4a1e57?0x0:_0x253d48[_0x82ff('0x1b')];var _0x3c19f5=_0x4a1e57?_0xc6b0db['count']:_0x253d48[_0x82ff('0x1b')]+_0x253d48[_0x82ff('0x19')];var _0x36d2e1;if(_0x3c19f5>=_0x9bb9c){_0x3c19f5=_0x9bb9c;_0x36d2e1=0xc8;}else{_0x36d2e1=0xce;}_0x1fb8df['status'](_0x36d2e1);return _0x1fb8df['set']('Content-Range',_0x42eb82+'-'+_0x3c19f5+'/'+_0x9bb9c)[_0x82ff('0x17')](_0xc6b0db);}return null;};}function patchUpdates(_0x10fb2a){return function(_0x5e52f6){try{jsonpatch['apply'](_0x5e52f6,_0x10fb2a,!![]);}catch(_0x3d0550){return BPromise[_0x82ff('0x1c')](_0x3d0550);}return _0x5e52f6[_0x82ff('0x1d')]();};}function saveUpdates(_0x2af402,_0xc3e3a8){return function(_0x3c3388){if(_0x3c3388){return _0x3c3388[_0x82ff('0x1e')](_0x2af402)[_0x82ff('0x1f')](function(_0x54c9eb){return _0x54c9eb;});}return null;};}function removeEntity(_0x1fa70c,_0x332991){return function(_0x26fb94){if(_0x26fb94){return _0x26fb94[_0x82ff('0x20')]()[_0x82ff('0x1f')](function(){_0x1fa70c['status'](0xcc)[_0x82ff('0x16')]();});}};}function handleEntityNotFound(_0x556610,_0x8487f0){return function(_0x48cfb9){if(!_0x48cfb9){_0x556610[_0x82ff('0x14')](0x194);}return _0x48cfb9;};}function handleError(_0x450490,_0x5d7241){_0x5d7241=_0x5d7241||0x1f4;return function(_0x76cb1f){logger[_0x82ff('0x21')](_0x76cb1f[_0x82ff('0x22')]);if(_0x76cb1f[_0x82ff('0x23')]){delete _0x76cb1f[_0x82ff('0x23')];}_0x450490[_0x82ff('0x15')](_0x5d7241)[_0x82ff('0x24')](_0x76cb1f);};}exports[_0x82ff('0x25')]=function(_0x9bb8ed,_0x2f459f){var _0x4c38cb={},_0x291ed2={},_0x5c3875={'count':0x0,'rows':[]};var _0x3b28a7=_[_0x82ff('0x26')](db['ChatTransferReport'][_0x82ff('0x27')],function(_0x269abe){return{'name':_0x269abe[_0x82ff('0x28')],'type':_0x269abe['type'][_0x82ff('0x29')]};});_0x291ed2['model']=_['map'](_0x3b28a7,_0x82ff('0x23'));_0x291ed2['query']=_[_0x82ff('0x2a')](_0x9bb8ed[_0x82ff('0x2b')]);_0x291ed2['filters']=_[_0x82ff('0x2c')](_0x291ed2[_0x82ff('0x2d')],_0x291ed2['query']);_0x4c38cb[_0x82ff('0x2e')]=_[_0x82ff('0x2c')](_0x291ed2[_0x82ff('0x2d')],qs['fields'](_0x9bb8ed[_0x82ff('0x2b')]['fields']));_0x4c38cb[_0x82ff('0x2e')]=_0x4c38cb[_0x82ff('0x2e')]['length']?_0x4c38cb[_0x82ff('0x2e')]:_0x291ed2[_0x82ff('0x2d')];if(!_0x9bb8ed[_0x82ff('0x2b')][_0x82ff('0x2f')](_0x82ff('0x30'))){_0x4c38cb[_0x82ff('0x19')]=qs[_0x82ff('0x19')](_0x9bb8ed[_0x82ff('0x2b')][_0x82ff('0x19')]);_0x4c38cb[_0x82ff('0x1b')]=qs[_0x82ff('0x1b')](_0x9bb8ed[_0x82ff('0x2b')]['offset']);}_0x4c38cb[_0x82ff('0x31')]=qs[_0x82ff('0x32')](_0x9bb8ed[_0x82ff('0x2b')][_0x82ff('0x32')]);_0x4c38cb[_0x82ff('0x33')]=qs[_0x82ff('0x34')](_[_0x82ff('0x35')](_0x9bb8ed['query'],_0x291ed2[_0x82ff('0x34')]),_0x3b28a7);if(_0x9bb8ed[_0x82ff('0x2b')]['filter']){_0x4c38cb[_0x82ff('0x33')]=_[_0x82ff('0x36')](_0x4c38cb[_0x82ff('0x33')],{'$or':_['map'](_0x3b28a7,function(_0xe721d9){if(_0xe721d9[_0x82ff('0x37')]!=='VIRTUAL'){var _0x3cf9d1={};_0x3cf9d1[_0xe721d9[_0x82ff('0x23')]]={'$like':'%'+_0x9bb8ed[_0x82ff('0x2b')][_0x82ff('0x38')]+'%'};return _0x3cf9d1;}})});}_0x4c38cb=_[_0x82ff('0x36')]({},_0x4c38cb,_0x9bb8ed[_0x82ff('0x39')]);var _0x52b9b9={'where':_0x4c38cb[_0x82ff('0x33')]};return db[_0x82ff('0x3a')][_0x82ff('0x1a')](_0x52b9b9)[_0x82ff('0x1f')](function(_0x3f5082){_0x5c3875[_0x82ff('0x1a')]=_0x3f5082;if(_0x9bb8ed[_0x82ff('0x2b')]['includeAll']){_0x4c38cb['include']=[{'all':!![]}];}return db[_0x82ff('0x3a')]['findAll'](_0x4c38cb);})[_0x82ff('0x1f')](function(_0xfd799f){_0x5c3875[_0x82ff('0x3b')]=_0xfd799f;return _0x5c3875;})[_0x82ff('0x1f')](respondWithFilteredResult(_0x2f459f,_0x4c38cb))[_0x82ff('0x3c')](handleError(_0x2f459f,null));};exports[_0x82ff('0x3d')]=function(_0x409792,_0x199eeb){var _0x5d8cfa={'raw':!![],'where':{'id':_0x409792['params']['id']}},_0x397c5a={};_0x397c5a[_0x82ff('0x2d')]=_[_0x82ff('0x2a')](db[_0x82ff('0x3a')][_0x82ff('0x27')]);_0x397c5a[_0x82ff('0x2b')]=_[_0x82ff('0x2a')](_0x409792['query']);_0x397c5a[_0x82ff('0x34')]=_['intersection'](_0x397c5a[_0x82ff('0x2d')],_0x397c5a['query']);_0x5d8cfa[_0x82ff('0x2e')]=_[_0x82ff('0x2c')](_0x397c5a['model'],qs[_0x82ff('0x3e')](_0x409792[_0x82ff('0x2b')]['fields']));_0x5d8cfa[_0x82ff('0x2e')]=_0x5d8cfa[_0x82ff('0x2e')][_0x82ff('0x3f')]?_0x5d8cfa[_0x82ff('0x2e')]:_0x397c5a[_0x82ff('0x2d')];if(_0x409792[_0x82ff('0x2b')][_0x82ff('0x40')]){_0x5d8cfa[_0x82ff('0x41')]=[{'all':!![]}];}_0x5d8cfa=_[_0x82ff('0x36')]({},_0x5d8cfa,_0x409792[_0x82ff('0x39')]);return db[_0x82ff('0x3a')]['find'](_0x5d8cfa)['then'](handleEntityNotFound(_0x199eeb,null))[_0x82ff('0x1f')](respondWithResult(_0x199eeb,null))[_0x82ff('0x3c')](handleError(_0x199eeb,null));};exports[_0x82ff('0x42')]=function(_0x56a47f,_0x260d95){return db[_0x82ff('0x3a')]['create'](_0x56a47f['body'],{})[_0x82ff('0x1f')](respondWithResult(_0x260d95,0xc9))[_0x82ff('0x3c')](handleError(_0x260d95,null));};exports[_0x82ff('0x1e')]=function(_0xe4f8ed,_0x5c6292){if(_0xe4f8ed[_0x82ff('0x43')]['id']){delete _0xe4f8ed[_0x82ff('0x43')]['id'];}return db[_0x82ff('0x3a')][_0x82ff('0x44')]({'where':{'id':_0xe4f8ed[_0x82ff('0x45')]['id']}})[_0x82ff('0x1f')](handleEntityNotFound(_0x5c6292,null))[_0x82ff('0x1f')](saveUpdates(_0xe4f8ed[_0x82ff('0x43')],null))['then'](respondWithResult(_0x5c6292,null))[_0x82ff('0x3c')](handleError(_0x5c6292,null));};exports[_0x82ff('0x20')]=function(_0x4acb08,_0x455863){return db['ChatTransferReport'][_0x82ff('0x44')]({'where':{'id':_0x4acb08['params']['id']}})[_0x82ff('0x1f')](handleEntityNotFound(_0x455863,null))[_0x82ff('0x1f')](removeEntity(_0x455863,null))[_0x82ff('0x3c')](handleError(_0x455863,null));};exports['describe']=function(_0x240280,_0x411975){return db[_0x82ff('0x3a')][_0x82ff('0x46')]()[_0x82ff('0x1f')](respondWithResult(_0x411975,null))[_0x82ff('0x3c')](handleError(_0x411975,null));};