7a3147ed6e8651e02069c87d914e84ee83b712fe
[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 _0xc73f=['fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','status','json','limit','undefined','count','offset','set','Content-Range','apply','reject','save','then','destroy','end','sendStatus','error','stack','name','index','map','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','filter','merge','VIRTUAL','WhatsappTransferReport','includeAll','include','rows','catch','show','params','rawAttributes','options','find','create','body','describe','eml-format','rimraf'];(function(_0x4df0bb,_0x32f084){var _0x1277a6=function(_0x3b2345){while(--_0x3b2345){_0x4df0bb['push'](_0x4df0bb['shift']());}};_0x1277a6(++_0x32f084);}(_0xc73f,0xe2));var _0xfc73=function(_0x305ea1,_0x1a075b){_0x305ea1=_0x305ea1-0x0;var _0x2c6d52=_0xc73f[_0x305ea1];return _0x2c6d52;};'use strict';var emlformat=require(_0xfc73('0x0'));var rimraf=require(_0xfc73('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfc73('0x2'));var rp=require(_0xfc73('0x3'));var moment=require(_0xfc73('0x4'));var BPromise=require(_0xfc73('0x5'));var Mustache=require(_0xfc73('0x6'));var util=require(_0xfc73('0x7'));var path=require('path');var sox=require(_0xfc73('0x8'));var csv=require('to-csv');var ejs=require(_0xfc73('0x9'));var fs=require('fs');var fs_extra=require(_0xfc73('0xa'));var _=require(_0xfc73('0xb'));var squel=require(_0xfc73('0xc'));var crypto=require(_0xfc73('0xd'));var jsforce=require(_0xfc73('0xe'));var deskjs=require(_0xfc73('0xf'));var toCsv=require('to-csv');var querystring=require(_0xfc73('0x10'));var Papa=require(_0xfc73('0x11'));var Redis=require(_0xfc73('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xfc73('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xfc73('0x14'));var logger=require(_0xfc73('0x15'))('api');var utils=require('../../config/utils');var config=require(_0xfc73('0x16'));var licenseUtil=require(_0xfc73('0x17'));var db=require(_0xfc73('0x18'))['db'];function respondWithStatusCode(_0x283f6e,_0x2c8f88){_0x2c8f88=_0x2c8f88||0xcc;return function(_0xcc2da0){if(_0xcc2da0){return _0x283f6e['sendStatus'](_0x2c8f88);}return _0x283f6e[_0xfc73('0x19')](_0x2c8f88)['end']();};}function respondWithResult(_0x744a17,_0x77a9b9){_0x77a9b9=_0x77a9b9||0xc8;return function(_0x1d284f){if(_0x1d284f){return _0x744a17[_0xfc73('0x19')](_0x77a9b9)[_0xfc73('0x1a')](_0x1d284f);}};}function respondWithFilteredResult(_0x25f694,_0x54d480){return function(_0x103bf2){if(_0x103bf2){var _0x4a28c3=typeof _0x54d480['offset']==='undefined'&&typeof _0x54d480[_0xfc73('0x1b')]===_0xfc73('0x1c');var _0x26cdc1=_0x103bf2[_0xfc73('0x1d')];var _0x34ca68=_0x4a28c3?0x0:_0x54d480[_0xfc73('0x1e')];var _0x10e8eb=_0x4a28c3?_0x103bf2[_0xfc73('0x1d')]:_0x54d480['offset']+_0x54d480['limit'];var _0xf2387f;if(_0x10e8eb>=_0x26cdc1){_0x10e8eb=_0x26cdc1;_0xf2387f=0xc8;}else{_0xf2387f=0xce;}_0x25f694[_0xfc73('0x19')](_0xf2387f);return _0x25f694[_0xfc73('0x1f')](_0xfc73('0x20'),_0x34ca68+'-'+_0x10e8eb+'/'+_0x26cdc1)[_0xfc73('0x1a')](_0x103bf2);}return null;};}function patchUpdates(_0x4a403c){return function(_0x1d94e8){try{jsonpatch[_0xfc73('0x21')](_0x1d94e8,_0x4a403c,!![]);}catch(_0x323b20){return BPromise[_0xfc73('0x22')](_0x323b20);}return _0x1d94e8[_0xfc73('0x23')]();};}function saveUpdates(_0x13bfab,_0x315da4){return function(_0x1446e5){if(_0x1446e5){return _0x1446e5['update'](_0x13bfab)[_0xfc73('0x24')](function(_0x288556){return _0x288556;});}return null;};}function removeEntity(_0x275703,_0x38193d){return function(_0xd6d5eb){if(_0xd6d5eb){return _0xd6d5eb[_0xfc73('0x25')]()[_0xfc73('0x24')](function(){_0x275703[_0xfc73('0x19')](0xcc)[_0xfc73('0x26')]();});}};}function handleEntityNotFound(_0x59ed74,_0x18477a){return function(_0x46df52){if(!_0x46df52){_0x59ed74[_0xfc73('0x27')](0x194);}return _0x46df52;};}function handleError(_0x579a79,_0x2429b9){_0x2429b9=_0x2429b9||0x1f4;return function(_0x2afb30){logger[_0xfc73('0x28')](_0x2afb30[_0xfc73('0x29')]);if(_0x2afb30[_0xfc73('0x2a')]){delete _0x2afb30['name'];}_0x579a79[_0xfc73('0x19')](_0x2429b9)['send'](_0x2afb30);};}exports[_0xfc73('0x2b')]=function(_0x2a3432,_0x16ec88){var _0x2613c3={},_0x2f3ed5={},_0x2f069e={'count':0x0,'rows':[]};var _0x248685=_[_0xfc73('0x2c')](db['WhatsappTransferReport']['rawAttributes'],function(_0x4831df){return{'name':_0x4831df[_0xfc73('0x2d')],'type':_0x4831df[_0xfc73('0x2e')][_0xfc73('0x2f')]};});_0x2f3ed5[_0xfc73('0x30')]=_[_0xfc73('0x2c')](_0x248685,_0xfc73('0x2a'));_0x2f3ed5[_0xfc73('0x31')]=_[_0xfc73('0x32')](_0x2a3432['query']);_0x2f3ed5[_0xfc73('0x33')]=_[_0xfc73('0x34')](_0x2f3ed5['model'],_0x2f3ed5[_0xfc73('0x31')]);_0x2613c3[_0xfc73('0x35')]=_[_0xfc73('0x34')](_0x2f3ed5[_0xfc73('0x30')],qs[_0xfc73('0x36')](_0x2a3432[_0xfc73('0x31')][_0xfc73('0x36')]));_0x2613c3['attributes']=_0x2613c3['attributes'][_0xfc73('0x37')]?_0x2613c3[_0xfc73('0x35')]:_0x2f3ed5[_0xfc73('0x30')];if(!_0x2a3432[_0xfc73('0x31')][_0xfc73('0x38')]('nolimit')){_0x2613c3[_0xfc73('0x1b')]=qs['limit'](_0x2a3432[_0xfc73('0x31')][_0xfc73('0x1b')]);_0x2613c3[_0xfc73('0x1e')]=qs[_0xfc73('0x1e')](_0x2a3432[_0xfc73('0x31')][_0xfc73('0x1e')]);}_0x2613c3[_0xfc73('0x39')]=qs[_0xfc73('0x3a')](_0x2a3432['query']['sort']);_0x2613c3[_0xfc73('0x3b')]=qs[_0xfc73('0x33')](_['pick'](_0x2a3432[_0xfc73('0x31')],_0x2f3ed5[_0xfc73('0x33')]),_0x248685);if(_0x2a3432['query'][_0xfc73('0x3c')]){_0x2613c3[_0xfc73('0x3b')]=_[_0xfc73('0x3d')](_0x2613c3[_0xfc73('0x3b')],{'$or':_[_0xfc73('0x2c')](_0x248685,function(_0x20da04){if(_0x20da04[_0xfc73('0x2e')]!==_0xfc73('0x3e')){var _0x270e9c={};_0x270e9c[_0x20da04[_0xfc73('0x2a')]]={'$like':'%'+_0x2a3432[_0xfc73('0x31')][_0xfc73('0x3c')]+'%'};return _0x270e9c;}})});}_0x2613c3=_[_0xfc73('0x3d')]({},_0x2613c3,_0x2a3432['options']);var _0x33b0f4={'where':_0x2613c3[_0xfc73('0x3b')]};return db[_0xfc73('0x3f')][_0xfc73('0x1d')](_0x33b0f4)[_0xfc73('0x24')](function(_0x3efacd){_0x2f069e[_0xfc73('0x1d')]=_0x3efacd;if(_0x2a3432['query'][_0xfc73('0x40')]){_0x2613c3[_0xfc73('0x41')]=[{'all':!![]}];}return db[_0xfc73('0x3f')]['findAll'](_0x2613c3);})[_0xfc73('0x24')](function(_0x2d3342){_0x2f069e[_0xfc73('0x42')]=_0x2d3342;return _0x2f069e;})['then'](respondWithFilteredResult(_0x16ec88,_0x2613c3))[_0xfc73('0x43')](handleError(_0x16ec88,null));};exports[_0xfc73('0x44')]=function(_0x519211,_0x4ec1f9){var _0x147436={'raw':!![],'where':{'id':_0x519211[_0xfc73('0x45')]['id']}},_0x49768e={};_0x49768e[_0xfc73('0x30')]=_[_0xfc73('0x32')](db[_0xfc73('0x3f')][_0xfc73('0x46')]);_0x49768e['query']=_[_0xfc73('0x32')](_0x519211[_0xfc73('0x31')]);_0x49768e[_0xfc73('0x33')]=_[_0xfc73('0x34')](_0x49768e[_0xfc73('0x30')],_0x49768e['query']);_0x147436['attributes']=_[_0xfc73('0x34')](_0x49768e[_0xfc73('0x30')],qs[_0xfc73('0x36')](_0x519211[_0xfc73('0x31')][_0xfc73('0x36')]));_0x147436[_0xfc73('0x35')]=_0x147436[_0xfc73('0x35')][_0xfc73('0x37')]?_0x147436['attributes']:_0x49768e[_0xfc73('0x30')];if(_0x519211[_0xfc73('0x31')]['includeAll']){_0x147436[_0xfc73('0x41')]=[{'all':!![]}];}_0x147436=_['merge']({},_0x147436,_0x519211[_0xfc73('0x47')]);return db[_0xfc73('0x3f')][_0xfc73('0x48')](_0x147436)['then'](handleEntityNotFound(_0x4ec1f9,null))[_0xfc73('0x24')](respondWithResult(_0x4ec1f9,null))[_0xfc73('0x43')](handleError(_0x4ec1f9,null));};exports[_0xfc73('0x49')]=function(_0x586ce5,_0x374a9d){return db['WhatsappTransferReport'][_0xfc73('0x49')](_0x586ce5[_0xfc73('0x4a')],{})[_0xfc73('0x24')](respondWithResult(_0x374a9d,0xc9))[_0xfc73('0x43')](handleError(_0x374a9d,null));};exports['update']=function(_0x34fe15,_0x3b3884){if(_0x34fe15[_0xfc73('0x4a')]['id']){delete _0x34fe15[_0xfc73('0x4a')]['id'];}return db['WhatsappTransferReport'][_0xfc73('0x48')]({'where':{'id':_0x34fe15[_0xfc73('0x45')]['id']}})[_0xfc73('0x24')](handleEntityNotFound(_0x3b3884,null))['then'](saveUpdates(_0x34fe15['body'],null))[_0xfc73('0x24')](respondWithResult(_0x3b3884,null))['catch'](handleError(_0x3b3884,null));};exports[_0xfc73('0x25')]=function(_0x44998a,_0x23f863){return db[_0xfc73('0x3f')][_0xfc73('0x48')]({'where':{'id':_0x44998a[_0xfc73('0x45')]['id']}})['then'](handleEntityNotFound(_0x23f863,null))[_0xfc73('0x24')](removeEntity(_0x23f863,null))[_0xfc73('0x43')](handleError(_0x23f863,null));};exports[_0xfc73('0x4b')]=function(_0x57ce9a,_0x6bf408){return db[_0xfc73('0x3f')]['describe']()[_0xfc73('0x24')](respondWithResult(_0x6bf408,null))[_0xfc73('0x43')](handleError(_0x6bf408,null));};