fa0a2132510a28a3e79c809183c2a0b05a2e759b
[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 _0x3f74=['querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','WhatsappTransferReport','fieldName','type','map','query','keys','filters','intersection','attributes','model','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','params','rawAttributes','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','fs-extra','squel','jsforce','desk.js','to-csv'];(function(_0x57fa33,_0x2b8222){var _0x12e724=function(_0x481a33){while(--_0x481a33){_0x57fa33['push'](_0x57fa33['shift']());}};_0x12e724(++_0x2b8222);}(_0x3f74,0x121));var _0x43f7=function(_0x5f4b1c,_0x552a66){_0x5f4b1c=_0x5f4b1c-0x0;var _0x3ee292=_0x3f74[_0x5f4b1c];return _0x3ee292;};'use strict';var emlformat=require(_0x43f7('0x0'));var rimraf=require(_0x43f7('0x1'));var zipdir=require(_0x43f7('0x2'));var jsonpatch=require(_0x43f7('0x3'));var rp=require(_0x43f7('0x4'));var moment=require(_0x43f7('0x5'));var BPromise=require(_0x43f7('0x6'));var Mustache=require(_0x43f7('0x7'));var util=require('util');var path=require(_0x43f7('0x8'));var sox=require(_0x43f7('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x43f7('0xa'));var _=require('lodash');var squel=require(_0x43f7('0xb'));var crypto=require('crypto');var jsforce=require(_0x43f7('0xc'));var deskjs=require(_0x43f7('0xd'));var toCsv=require(_0x43f7('0xe'));var querystring=require(_0x43f7('0xf'));var Papa=require(_0x43f7('0x10'));var Redis=require('ioredis');var authService=require(_0x43f7('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x43f7('0x12'));var hardwareService=require(_0x43f7('0x13'));var logger=require('../../config/logger')(_0x43f7('0x14'));var utils=require(_0x43f7('0x15'));var config=require(_0x43f7('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x43f7('0x17'))['db'];function respondWithStatusCode(_0x3402c1,_0x227050){_0x227050=_0x227050||0xcc;return function(_0x14abd8){if(_0x14abd8){return _0x3402c1[_0x43f7('0x18')](_0x227050);}return _0x3402c1[_0x43f7('0x19')](_0x227050)[_0x43f7('0x1a')]();};}function respondWithResult(_0x17d588,_0x2680c7){_0x2680c7=_0x2680c7||0xc8;return function(_0x1ba361){if(_0x1ba361){return _0x17d588[_0x43f7('0x19')](_0x2680c7)[_0x43f7('0x1b')](_0x1ba361);}};}function respondWithFilteredResult(_0x38a060,_0x201273){return function(_0x1775b5){if(_0x1775b5){var _0x2316fa=typeof _0x201273[_0x43f7('0x1c')]===_0x43f7('0x1d')&&typeof _0x201273['limit']===_0x43f7('0x1d');var _0x5a558e=_0x1775b5['count'];var _0x3d8571=_0x2316fa?0x0:_0x201273['offset'];var _0x44380f=_0x2316fa?_0x1775b5[_0x43f7('0x1e')]:_0x201273[_0x43f7('0x1c')]+_0x201273[_0x43f7('0x1f')];var _0x294dce;if(_0x44380f>=_0x5a558e){_0x44380f=_0x5a558e;_0x294dce=0xc8;}else{_0x294dce=0xce;}_0x38a060['status'](_0x294dce);return _0x38a060[_0x43f7('0x20')](_0x43f7('0x21'),_0x3d8571+'-'+_0x44380f+'/'+_0x5a558e)['json'](_0x1775b5);}return null;};}function patchUpdates(_0x320317){return function(_0x4c5727){try{jsonpatch[_0x43f7('0x22')](_0x4c5727,_0x320317,!![]);}catch(_0x246e06){return BPromise[_0x43f7('0x23')](_0x246e06);}return _0x4c5727[_0x43f7('0x24')]();};}function saveUpdates(_0x4185c0,_0x4528bc){return function(_0x1d15e9){if(_0x1d15e9){return _0x1d15e9[_0x43f7('0x25')](_0x4185c0)[_0x43f7('0x26')](function(_0x422bbd){return _0x422bbd;});}return null;};}function removeEntity(_0x3bdb19,_0x4e6e98){return function(_0x313965){if(_0x313965){return _0x313965[_0x43f7('0x27')]()[_0x43f7('0x26')](function(){_0x3bdb19[_0x43f7('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2d7b3a,_0x4cdc92){return function(_0x173cf9){if(!_0x173cf9){_0x2d7b3a[_0x43f7('0x18')](0x194);}return _0x173cf9;};}function handleError(_0x39f2a6,_0x235cbc){_0x235cbc=_0x235cbc||0x1f4;return function(_0x339775){logger[_0x43f7('0x28')](_0x339775[_0x43f7('0x29')]);if(_0x339775[_0x43f7('0x2a')]){delete _0x339775[_0x43f7('0x2a')];}_0x39f2a6[_0x43f7('0x19')](_0x235cbc)[_0x43f7('0x2b')](_0x339775);};}exports[_0x43f7('0x2c')]=function(_0x4819b1,_0xf1e837){var _0x1bdd3c={},_0x16f48c={},_0x4472cc={'count':0x0,'rows':[]};var _0x79fae=_['map'](db[_0x43f7('0x2d')]['rawAttributes'],function(_0x5385e8){return{'name':_0x5385e8[_0x43f7('0x2e')],'type':_0x5385e8[_0x43f7('0x2f')]['key']};});_0x16f48c['model']=_[_0x43f7('0x30')](_0x79fae,_0x43f7('0x2a'));_0x16f48c[_0x43f7('0x31')]=_[_0x43f7('0x32')](_0x4819b1[_0x43f7('0x31')]);_0x16f48c[_0x43f7('0x33')]=_[_0x43f7('0x34')](_0x16f48c['model'],_0x16f48c[_0x43f7('0x31')]);_0x1bdd3c[_0x43f7('0x35')]=_[_0x43f7('0x34')](_0x16f48c[_0x43f7('0x36')],qs[_0x43f7('0x37')](_0x4819b1[_0x43f7('0x31')]['fields']));_0x1bdd3c[_0x43f7('0x35')]=_0x1bdd3c[_0x43f7('0x35')][_0x43f7('0x38')]?_0x1bdd3c[_0x43f7('0x35')]:_0x16f48c[_0x43f7('0x36')];if(!_0x4819b1[_0x43f7('0x31')][_0x43f7('0x39')]('nolimit')){_0x1bdd3c[_0x43f7('0x1f')]=qs[_0x43f7('0x1f')](_0x4819b1['query']['limit']);_0x1bdd3c['offset']=qs[_0x43f7('0x1c')](_0x4819b1['query'][_0x43f7('0x1c')]);}_0x1bdd3c[_0x43f7('0x3a')]=qs[_0x43f7('0x3b')](_0x4819b1[_0x43f7('0x31')]['sort']);_0x1bdd3c[_0x43f7('0x3c')]=qs[_0x43f7('0x33')](_[_0x43f7('0x3d')](_0x4819b1[_0x43f7('0x31')],_0x16f48c[_0x43f7('0x33')]),_0x79fae);if(_0x4819b1[_0x43f7('0x31')][_0x43f7('0x3e')]){_0x1bdd3c[_0x43f7('0x3c')]=_[_0x43f7('0x3f')](_0x1bdd3c[_0x43f7('0x3c')],{'$or':_[_0x43f7('0x30')](_0x79fae,function(_0x23712d){if(_0x23712d[_0x43f7('0x2f')]!==_0x43f7('0x40')){var _0x822a8c={};_0x822a8c[_0x23712d[_0x43f7('0x2a')]]={'$like':'%'+_0x4819b1[_0x43f7('0x31')][_0x43f7('0x3e')]+'%'};return _0x822a8c;}})});}_0x1bdd3c=_['merge']({},_0x1bdd3c,_0x4819b1['options']);var _0x13f21b={'where':_0x1bdd3c[_0x43f7('0x3c')]};return db['WhatsappTransferReport'][_0x43f7('0x1e')](_0x13f21b)[_0x43f7('0x26')](function(_0x338538){_0x4472cc['count']=_0x338538;if(_0x4819b1[_0x43f7('0x31')][_0x43f7('0x41')]){_0x1bdd3c[_0x43f7('0x42')]=[{'all':!![]}];}return db[_0x43f7('0x2d')][_0x43f7('0x43')](_0x1bdd3c);})[_0x43f7('0x26')](function(_0x1096f3){_0x4472cc[_0x43f7('0x44')]=_0x1096f3;return _0x4472cc;})[_0x43f7('0x26')](respondWithFilteredResult(_0xf1e837,_0x1bdd3c))[_0x43f7('0x45')](handleError(_0xf1e837,null));};exports['show']=function(_0x207654,_0x3e459f){var _0x28c3dc={'raw':!![],'where':{'id':_0x207654[_0x43f7('0x46')]['id']}},_0x2eff54={};_0x2eff54[_0x43f7('0x36')]=_['keys'](db[_0x43f7('0x2d')][_0x43f7('0x47')]);_0x2eff54[_0x43f7('0x31')]=_[_0x43f7('0x32')](_0x207654[_0x43f7('0x31')]);_0x2eff54[_0x43f7('0x33')]=_[_0x43f7('0x34')](_0x2eff54[_0x43f7('0x36')],_0x2eff54[_0x43f7('0x31')]);_0x28c3dc[_0x43f7('0x35')]=_[_0x43f7('0x34')](_0x2eff54['model'],qs['fields'](_0x207654[_0x43f7('0x31')][_0x43f7('0x37')]));_0x28c3dc[_0x43f7('0x35')]=_0x28c3dc[_0x43f7('0x35')][_0x43f7('0x38')]?_0x28c3dc[_0x43f7('0x35')]:_0x2eff54[_0x43f7('0x36')];if(_0x207654['query'][_0x43f7('0x41')]){_0x28c3dc[_0x43f7('0x42')]=[{'all':!![]}];}_0x28c3dc=_['merge']({},_0x28c3dc,_0x207654['options']);return db[_0x43f7('0x2d')][_0x43f7('0x48')](_0x28c3dc)[_0x43f7('0x26')](handleEntityNotFound(_0x3e459f,null))[_0x43f7('0x26')](respondWithResult(_0x3e459f,null))[_0x43f7('0x45')](handleError(_0x3e459f,null));};exports[_0x43f7('0x49')]=function(_0xd9685d,_0x177135){return db['WhatsappTransferReport'][_0x43f7('0x49')](_0xd9685d[_0x43f7('0x4a')],{})[_0x43f7('0x26')](respondWithResult(_0x177135,0xc9))['catch'](handleError(_0x177135,null));};exports[_0x43f7('0x25')]=function(_0x22c83,_0x490607){if(_0x22c83[_0x43f7('0x4a')]['id']){delete _0x22c83['body']['id'];}return db[_0x43f7('0x2d')][_0x43f7('0x48')]({'where':{'id':_0x22c83['params']['id']}})[_0x43f7('0x26')](handleEntityNotFound(_0x490607,null))[_0x43f7('0x26')](saveUpdates(_0x22c83[_0x43f7('0x4a')],null))['then'](respondWithResult(_0x490607,null))[_0x43f7('0x45')](handleError(_0x490607,null));};exports[_0x43f7('0x27')]=function(_0x4df844,_0x5a394f){return db[_0x43f7('0x2d')]['find']({'where':{'id':_0x4df844[_0x43f7('0x46')]['id']}})[_0x43f7('0x26')](handleEntityNotFound(_0x5a394f,null))[_0x43f7('0x26')](removeEntity(_0x5a394f,null))[_0x43f7('0x45')](handleError(_0x5a394f,null));};exports[_0x43f7('0x4b')]=function(_0x7b735c,_0x19fffd){return db[_0x43f7('0x2d')][_0x43f7('0x4b')]()[_0x43f7('0x26')](respondWithResult(_0x19fffd,null))[_0x43f7('0x45')](handleError(_0x19fffd,null));};