b46e4317a4746c9fd39d926066d3fe06ae97831e
[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 _0x82f4=['sendStatus','status','count','offset','limit','Content-Range','json','apply','reject','update','then','destroy','end','error','stack','name','index','map','ChatTransferReport','rawAttributes','fieldName','type','key','query','filters','intersection','model','fields','length','attributes','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','includeAll','include','findAll','rows','catch','show','params','keys','create','body','find','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0x82f4,0xce));var _0x482f=function(_0x3e1415,_0x2ad5ee){_0x3e1415=_0x3e1415-0x0;var _0x2e1ec7=_0x82f4[_0x3e1415];return _0x2e1ec7;};'use strict';var pdf=require(_0x482f('0x0'));var emlformat=require(_0x482f('0x1'));var rimraf=require(_0x482f('0x2'));var zipdir=require(_0x482f('0x3'));var jsonpatch=require(_0x482f('0x4'));var rp=require(_0x482f('0x5'));var moment=require(_0x482f('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x482f('0x7'));var util=require('util');var path=require(_0x482f('0x8'));var sox=require(_0x482f('0x9'));var csv=require(_0x482f('0xa'));var ejs=require(_0x482f('0xb'));var fs=require('fs');var _=require(_0x482f('0xc'));var squel=require(_0x482f('0xd'));var crypto=require(_0x482f('0xe'));var jsforce=require(_0x482f('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x482f('0xa'));var querystring=require(_0x482f('0x10'));var Papa=require(_0x482f('0x11'));var Redis=require(_0x482f('0x12'));var authService=require(_0x482f('0x13'));var qs=require(_0x482f('0x14'));var as=require(_0x482f('0x15'));var hardwareService=require(_0x482f('0x16'));var logger=require(_0x482f('0x17'))(_0x482f('0x18'));var utils=require('../../config/utils');var config=require(_0x482f('0x19'));var licenseUtil=require(_0x482f('0x1a'));var db=require(_0x482f('0x1b'))['db'];function respondWithStatusCode(_0x4ab62f,_0x576633){_0x576633=_0x576633||0xcc;return function(_0x3886f2){if(_0x3886f2){return _0x4ab62f[_0x482f('0x1c')](_0x576633);}return _0x4ab62f[_0x482f('0x1d')](_0x576633)['end']();};}function respondWithResult(_0x1a0e46,_0x128f24){_0x128f24=_0x128f24||0xc8;return function(_0x315d92){if(_0x315d92){return _0x1a0e46[_0x482f('0x1d')](_0x128f24)['json'](_0x315d92);}};}function respondWithFilteredResult(_0x312f44,_0x4818e0){return function(_0x3cd6d1){if(_0x3cd6d1){var _0x8a84fe=_0x3cd6d1[_0x482f('0x1e')],_0x1c58e1=_0x4818e0[_0x482f('0x1f')],_0x3a78ee=_0x4818e0[_0x482f('0x1f')]+_0x4818e0[_0x482f('0x20')],_0x32d4b2;if(_0x3a78ee>=_0x8a84fe){_0x3a78ee=_0x8a84fe;_0x32d4b2=0xc8;}else{_0x32d4b2=0xce;}_0x312f44['status'](_0x32d4b2);return _0x312f44['set'](_0x482f('0x21'),_0x1c58e1+'-'+_0x3a78ee+'/'+_0x8a84fe)[_0x482f('0x22')](_0x3cd6d1);}return null;};}function patchUpdates(_0x13c3f9){return function(_0x5ece8d){try{jsonpatch[_0x482f('0x23')](_0x5ece8d,_0x13c3f9,!![]);}catch(_0x1c08aa){return BPromise[_0x482f('0x24')](_0x1c08aa);}return _0x5ece8d['save']();};}function saveUpdates(_0x187bb4,_0x55d625){return function(_0x472027){if(_0x472027){return _0x472027[_0x482f('0x25')](_0x187bb4)[_0x482f('0x26')](function(_0x13b407){return _0x13b407;});}return null;};}function removeEntity(_0x41ec40,_0xc9525f){return function(_0x5965cb){if(_0x5965cb){return _0x5965cb[_0x482f('0x27')]()[_0x482f('0x26')](function(){_0x41ec40[_0x482f('0x1d')](0xcc)[_0x482f('0x28')]();});}};}function handleEntityNotFound(_0x5ba940,_0x36b31a){return function(_0x2b70ad){if(!_0x2b70ad){_0x5ba940[_0x482f('0x1c')](0x194);}return _0x2b70ad;};}function handleError(_0x11b7da,_0x547302){_0x547302=_0x547302||0x1f4;return function(_0x4d7138){logger[_0x482f('0x29')](_0x4d7138[_0x482f('0x2a')]);if(_0x4d7138[_0x482f('0x2b')]){delete _0x4d7138[_0x482f('0x2b')];}_0x11b7da[_0x482f('0x1d')](_0x547302)['send'](_0x4d7138);};}exports[_0x482f('0x2c')]=function(_0x2be8fe,_0x64283c){var _0x34df93={},_0x3e8a35={},_0xf3124={'count':0x0,'rows':[]};var _0x495625=_[_0x482f('0x2d')](db[_0x482f('0x2e')][_0x482f('0x2f')],function(_0x1d63ba){return{'name':_0x1d63ba[_0x482f('0x30')],'type':_0x1d63ba[_0x482f('0x31')][_0x482f('0x32')]};});_0x3e8a35['model']=_[_0x482f('0x2d')](_0x495625,_0x482f('0x2b'));_0x3e8a35['query']=_['keys'](_0x2be8fe[_0x482f('0x33')]);_0x3e8a35[_0x482f('0x34')]=_[_0x482f('0x35')](_0x3e8a35[_0x482f('0x36')],_0x3e8a35['query']);_0x34df93['attributes']=_[_0x482f('0x35')](_0x3e8a35[_0x482f('0x36')],qs[_0x482f('0x37')](_0x2be8fe[_0x482f('0x33')][_0x482f('0x37')]));_0x34df93['attributes']=_0x34df93['attributes'][_0x482f('0x38')]?_0x34df93[_0x482f('0x39')]:_0x3e8a35[_0x482f('0x36')];if(!_0x2be8fe[_0x482f('0x33')][_0x482f('0x3a')](_0x482f('0x3b'))){_0x34df93[_0x482f('0x20')]=qs[_0x482f('0x20')](_0x2be8fe[_0x482f('0x33')][_0x482f('0x20')]);_0x34df93[_0x482f('0x1f')]=qs[_0x482f('0x1f')](_0x2be8fe[_0x482f('0x33')][_0x482f('0x1f')]);}_0x34df93[_0x482f('0x3c')]=qs[_0x482f('0x3d')](_0x2be8fe['query'][_0x482f('0x3d')]);_0x34df93[_0x482f('0x3e')]=qs[_0x482f('0x34')](_['pick'](_0x2be8fe[_0x482f('0x33')],_0x3e8a35[_0x482f('0x34')]),_0x495625);if(_0x2be8fe[_0x482f('0x33')][_0x482f('0x3f')]){_0x34df93[_0x482f('0x3e')]=_[_0x482f('0x40')](_0x34df93[_0x482f('0x3e')],{'$or':_['map'](_0x495625,function(_0x81a47b){if(_0x81a47b[_0x482f('0x31')]!=='VIRTUAL'){var _0x2bb0e0={};_0x2bb0e0[_0x81a47b[_0x482f('0x2b')]]={'$like':'%'+_0x2be8fe['query'][_0x482f('0x3f')]+'%'};return _0x2bb0e0;}})});}_0x34df93=_['merge']({},_0x34df93,_0x2be8fe[_0x482f('0x41')]);var _0x3a7b28={'where':_0x34df93['where']};return db[_0x482f('0x2e')][_0x482f('0x1e')](_0x3a7b28)[_0x482f('0x26')](function(_0x1e05f6){_0xf3124['count']=_0x1e05f6;if(_0x2be8fe[_0x482f('0x33')][_0x482f('0x42')]){_0x34df93[_0x482f('0x43')]=[{'all':!![]}];}return db[_0x482f('0x2e')][_0x482f('0x44')](_0x34df93);})[_0x482f('0x26')](function(_0x3a9e98){_0xf3124[_0x482f('0x45')]=_0x3a9e98;return _0xf3124;})[_0x482f('0x26')](respondWithFilteredResult(_0x64283c,_0x34df93))[_0x482f('0x46')](handleError(_0x64283c,null));};exports[_0x482f('0x47')]=function(_0x4525ff,_0x57527b){var _0x29f600={'raw':!![],'where':{'id':_0x4525ff[_0x482f('0x48')]['id']}},_0x1a36f5={};_0x1a36f5[_0x482f('0x36')]=_[_0x482f('0x49')](db[_0x482f('0x2e')]['rawAttributes']);_0x1a36f5[_0x482f('0x33')]=_[_0x482f('0x49')](_0x4525ff[_0x482f('0x33')]);_0x1a36f5[_0x482f('0x34')]=_['intersection'](_0x1a36f5[_0x482f('0x36')],_0x1a36f5[_0x482f('0x33')]);_0x29f600[_0x482f('0x39')]=_['intersection'](_0x1a36f5['model'],qs[_0x482f('0x37')](_0x4525ff[_0x482f('0x33')][_0x482f('0x37')]));_0x29f600[_0x482f('0x39')]=_0x29f600[_0x482f('0x39')]['length']?_0x29f600[_0x482f('0x39')]:_0x1a36f5[_0x482f('0x36')];if(_0x4525ff[_0x482f('0x33')][_0x482f('0x42')]){_0x29f600[_0x482f('0x43')]=[{'all':!![]}];}_0x29f600=_[_0x482f('0x40')]({},_0x29f600,_0x4525ff[_0x482f('0x41')]);return db[_0x482f('0x2e')]['find'](_0x29f600)['then'](handleEntityNotFound(_0x57527b,null))[_0x482f('0x26')](respondWithResult(_0x57527b,null))['catch'](handleError(_0x57527b,null));};exports[_0x482f('0x4a')]=function(_0x5295f3,_0x4f1b76){return db[_0x482f('0x2e')][_0x482f('0x4a')](_0x5295f3[_0x482f('0x4b')],{})[_0x482f('0x26')](respondWithResult(_0x4f1b76,0xc9))[_0x482f('0x46')](handleError(_0x4f1b76,null));};exports['update']=function(_0x131433,_0x28599a){if(_0x131433[_0x482f('0x4b')]['id']){delete _0x131433[_0x482f('0x4b')]['id'];}return db[_0x482f('0x2e')][_0x482f('0x4c')]({'where':{'id':_0x131433[_0x482f('0x48')]['id']}})[_0x482f('0x26')](handleEntityNotFound(_0x28599a,null))['then'](saveUpdates(_0x131433[_0x482f('0x4b')],null))[_0x482f('0x26')](respondWithResult(_0x28599a,null))[_0x482f('0x46')](handleError(_0x28599a,null));};exports[_0x482f('0x27')]=function(_0x3fa8e0,_0x471d49){return db['ChatTransferReport'][_0x482f('0x4c')]({'where':{'id':_0x3fa8e0[_0x482f('0x48')]['id']}})[_0x482f('0x26')](handleEntityNotFound(_0x471d49,null))['then'](removeEntity(_0x471d49,null))['catch'](handleError(_0x471d49,null));};exports[_0x482f('0x4d')]=function(_0x571e66,_0x2c7f07){return db[_0x482f('0x2e')][_0x482f('0x4d')]()[_0x482f('0x26')](respondWithResult(_0x2c7f07,null))['catch'](handleError(_0x2c7f07,null));};