ac626e92d6146c73855e1ef91a5e8ac1122b14b1
[motion2.git] / server / api / whatsappTransferReport / whatsappTransferReport.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 _0x21f8=['keys','include','create','update','body','find','destroy','describe','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','end','status','json','undefined','count','offset','limit','set','reject','then','error','stack','name','send','index','map','WhatsappTransferReport','rawAttributes','fieldName','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','options','includeAll','findAll','rows','catch','params'];(function(_0x4363d0,_0x52508e){var _0x14d9bb=function(_0x143030){while(--_0x143030){_0x4363d0['push'](_0x4363d0['shift']());}};_0x14d9bb(++_0x52508e);}(_0x21f8,0x170));var _0x821f=function(_0x29d623,_0x1a5c9c){_0x29d623=_0x29d623-0x0;var _0x242e59=_0x21f8[_0x29d623];return _0x242e59;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x821f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x821f('0x1'));var rp=require(_0x821f('0x2'));var moment=require(_0x821f('0x3'));var BPromise=require(_0x821f('0x4'));var Mustache=require(_0x821f('0x5'));var util=require(_0x821f('0x6'));var path=require(_0x821f('0x7'));var sox=require(_0x821f('0x8'));var csv=require(_0x821f('0x9'));var ejs=require(_0x821f('0xa'));var fs=require('fs');var fs_extra=require(_0x821f('0xb'));var _=require('lodash');var squel=require(_0x821f('0xc'));var crypto=require(_0x821f('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x821f('0x9'));var querystring=require('querystring');var Papa=require(_0x821f('0xe'));var Redis=require(_0x821f('0xf'));var authService=require(_0x821f('0x10'));var qs=require(_0x821f('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x821f('0x12'));var logger=require(_0x821f('0x13'))(_0x821f('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x821f('0x15'));var db=require(_0x821f('0x16'))['db'];function respondWithStatusCode(_0x81aad9,_0x4f0f83){_0x4f0f83=_0x4f0f83||0xcc;return function(_0x2b9e7f){if(_0x2b9e7f){return _0x81aad9[_0x821f('0x17')](_0x4f0f83);}return _0x81aad9['status'](_0x4f0f83)[_0x821f('0x18')]();};}function respondWithResult(_0x366481,_0x571664){_0x571664=_0x571664||0xc8;return function(_0x336f37){if(_0x336f37){return _0x366481[_0x821f('0x19')](_0x571664)[_0x821f('0x1a')](_0x336f37);}};}function respondWithFilteredResult(_0x5254ca,_0x7677b8){return function(_0x914d84){if(_0x914d84){var _0x3a69d7=typeof _0x7677b8['offset']===_0x821f('0x1b')&&typeof _0x7677b8['limit']===_0x821f('0x1b');var _0x46ccfc=_0x914d84[_0x821f('0x1c')];var _0x4d0402=_0x3a69d7?0x0:_0x7677b8[_0x821f('0x1d')];var _0xb65631=_0x3a69d7?_0x914d84[_0x821f('0x1c')]:_0x7677b8[_0x821f('0x1d')]+_0x7677b8[_0x821f('0x1e')];var _0x246f8f;if(_0xb65631>=_0x46ccfc){_0xb65631=_0x46ccfc;_0x246f8f=0xc8;}else{_0x246f8f=0xce;}_0x5254ca['status'](_0x246f8f);return _0x5254ca[_0x821f('0x1f')]('Content-Range',_0x4d0402+'-'+_0xb65631+'/'+_0x46ccfc)[_0x821f('0x1a')](_0x914d84);}return null;};}function patchUpdates(_0x4e8f85){return function(_0x1f8488){try{jsonpatch['apply'](_0x1f8488,_0x4e8f85,!![]);}catch(_0x193b51){return BPromise[_0x821f('0x20')](_0x193b51);}return _0x1f8488['save']();};}function saveUpdates(_0x1e5ff3,_0x14a6c9){return function(_0x4882e5){if(_0x4882e5){return _0x4882e5['update'](_0x1e5ff3)[_0x821f('0x21')](function(_0x1b3ff4){return _0x1b3ff4;});}return null;};}function removeEntity(_0x18f62b,_0x3b9e5f){return function(_0x3afd21){if(_0x3afd21){return _0x3afd21['destroy']()[_0x821f('0x21')](function(){_0x18f62b[_0x821f('0x19')](0xcc)[_0x821f('0x18')]();});}};}function handleEntityNotFound(_0x3287e1,_0x29fe80){return function(_0x53667a){if(!_0x53667a){_0x3287e1[_0x821f('0x17')](0x194);}return _0x53667a;};}function handleError(_0x5a3524,_0x5d0146){_0x5d0146=_0x5d0146||0x1f4;return function(_0x23fedb){logger[_0x821f('0x22')](_0x23fedb[_0x821f('0x23')]);if(_0x23fedb['name']){delete _0x23fedb[_0x821f('0x24')];}_0x5a3524[_0x821f('0x19')](_0x5d0146)[_0x821f('0x25')](_0x23fedb);};}exports[_0x821f('0x26')]=function(_0x2a4433,_0x403d42){var _0x240447={},_0x31cfdd={},_0x4fa68c={'count':0x0,'rows':[]};var _0x1c3454=_[_0x821f('0x27')](db[_0x821f('0x28')][_0x821f('0x29')],function(_0x29ed92){return{'name':_0x29ed92[_0x821f('0x2a')],'type':_0x29ed92[_0x821f('0x2b')]['key']};});_0x31cfdd[_0x821f('0x2c')]=_[_0x821f('0x27')](_0x1c3454,_0x821f('0x24'));_0x31cfdd[_0x821f('0x2d')]=_['keys'](_0x2a4433[_0x821f('0x2d')]);_0x31cfdd[_0x821f('0x2e')]=_[_0x821f('0x2f')](_0x31cfdd['model'],_0x31cfdd[_0x821f('0x2d')]);_0x240447[_0x821f('0x30')]=_['intersection'](_0x31cfdd[_0x821f('0x2c')],qs[_0x821f('0x31')](_0x2a4433[_0x821f('0x2d')][_0x821f('0x31')]));_0x240447[_0x821f('0x30')]=_0x240447['attributes'][_0x821f('0x32')]?_0x240447['attributes']:_0x31cfdd[_0x821f('0x2c')];if(!_0x2a4433[_0x821f('0x2d')][_0x821f('0x33')]('nolimit')){_0x240447[_0x821f('0x1e')]=qs[_0x821f('0x1e')](_0x2a4433['query'][_0x821f('0x1e')]);_0x240447[_0x821f('0x1d')]=qs[_0x821f('0x1d')](_0x2a4433[_0x821f('0x2d')]['offset']);}_0x240447[_0x821f('0x34')]=qs[_0x821f('0x35')](_0x2a4433[_0x821f('0x2d')][_0x821f('0x35')]);_0x240447[_0x821f('0x36')]=qs['filters'](_[_0x821f('0x37')](_0x2a4433[_0x821f('0x2d')],_0x31cfdd[_0x821f('0x2e')]),_0x1c3454);if(_0x2a4433[_0x821f('0x2d')][_0x821f('0x38')]){_0x240447[_0x821f('0x36')]=_[_0x821f('0x39')](_0x240447[_0x821f('0x36')],{'$or':_[_0x821f('0x27')](_0x1c3454,function(_0x598130){if(_0x598130[_0x821f('0x2b')]!=='VIRTUAL'){var _0x4f92a0={};_0x4f92a0[_0x598130[_0x821f('0x24')]]={'$like':'%'+_0x2a4433['query']['filter']+'%'};return _0x4f92a0;}})});}_0x240447=_[_0x821f('0x39')]({},_0x240447,_0x2a4433[_0x821f('0x3a')]);var _0x4cc2e7={'where':_0x240447['where']};return db[_0x821f('0x28')]['count'](_0x4cc2e7)[_0x821f('0x21')](function(_0x47d920){_0x4fa68c[_0x821f('0x1c')]=_0x47d920;if(_0x2a4433['query'][_0x821f('0x3b')]){_0x240447['include']=[{'all':!![]}];}return db[_0x821f('0x28')][_0x821f('0x3c')](_0x240447);})[_0x821f('0x21')](function(_0x3717e3){_0x4fa68c[_0x821f('0x3d')]=_0x3717e3;return _0x4fa68c;})[_0x821f('0x21')](respondWithFilteredResult(_0x403d42,_0x240447))[_0x821f('0x3e')](handleError(_0x403d42,null));};exports['show']=function(_0x27d74c,_0x529d17){var _0x1f9aa5={'raw':!![],'where':{'id':_0x27d74c[_0x821f('0x3f')]['id']}},_0x139485={};_0x139485[_0x821f('0x2c')]=_[_0x821f('0x40')](db['WhatsappTransferReport'][_0x821f('0x29')]);_0x139485[_0x821f('0x2d')]=_[_0x821f('0x40')](_0x27d74c['query']);_0x139485['filters']=_[_0x821f('0x2f')](_0x139485[_0x821f('0x2c')],_0x139485[_0x821f('0x2d')]);_0x1f9aa5[_0x821f('0x30')]=_[_0x821f('0x2f')](_0x139485[_0x821f('0x2c')],qs[_0x821f('0x31')](_0x27d74c[_0x821f('0x2d')][_0x821f('0x31')]));_0x1f9aa5[_0x821f('0x30')]=_0x1f9aa5[_0x821f('0x30')]['length']?_0x1f9aa5[_0x821f('0x30')]:_0x139485[_0x821f('0x2c')];if(_0x27d74c['query'][_0x821f('0x3b')]){_0x1f9aa5[_0x821f('0x41')]=[{'all':!![]}];}_0x1f9aa5=_[_0x821f('0x39')]({},_0x1f9aa5,_0x27d74c[_0x821f('0x3a')]);return db[_0x821f('0x28')]['find'](_0x1f9aa5)[_0x821f('0x21')](handleEntityNotFound(_0x529d17,null))['then'](respondWithResult(_0x529d17,null))['catch'](handleError(_0x529d17,null));};exports['create']=function(_0x545d4f,_0x561cec){return db[_0x821f('0x28')][_0x821f('0x42')](_0x545d4f['body'],{})[_0x821f('0x21')](respondWithResult(_0x561cec,0xc9))['catch'](handleError(_0x561cec,null));};exports[_0x821f('0x43')]=function(_0x77b87c,_0x53734c){if(_0x77b87c[_0x821f('0x44')]['id']){delete _0x77b87c[_0x821f('0x44')]['id'];}return db[_0x821f('0x28')][_0x821f('0x45')]({'where':{'id':_0x77b87c[_0x821f('0x3f')]['id']}})[_0x821f('0x21')](handleEntityNotFound(_0x53734c,null))['then'](saveUpdates(_0x77b87c[_0x821f('0x44')],null))[_0x821f('0x21')](respondWithResult(_0x53734c,null))[_0x821f('0x3e')](handleError(_0x53734c,null));};exports[_0x821f('0x46')]=function(_0x234f0a,_0x4c9d3){return db[_0x821f('0x28')][_0x821f('0x45')]({'where':{'id':_0x234f0a[_0x821f('0x3f')]['id']}})[_0x821f('0x21')](handleEntityNotFound(_0x4c9d3,null))[_0x821f('0x21')](removeEntity(_0x4c9d3,null))[_0x821f('0x3e')](handleError(_0x4c9d3,null));};exports[_0x821f('0x47')]=function(_0x44cd7f,_0x260347){return db[_0x821f('0x28')][_0x821f('0x47')]()[_0x821f('0x21')](respondWithResult(_0x260347,null))[_0x821f('0x3e')](handleError(_0x260347,null));};