Built motion from commit fe909640.|2.6.8
[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 _0xaebd=['fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','find','create','body','params','describe','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','destroy','error','name','send','index','map','WhatsappTransferReport','rawAttributes','fieldName','type','key','query','keys','intersection','model','attributes'];(function(_0x22377a,_0x3397cb){var _0x36f105=function(_0x2174cc){while(--_0x2174cc){_0x22377a['push'](_0x22377a['shift']());}};_0x36f105(++_0x3397cb);}(_0xaebd,0x105));var _0xdaeb=function(_0x4e4987,_0x5a7734){_0x4e4987=_0x4e4987-0x0;var _0x3a400c=_0xaebd[_0x4e4987];return _0x3a400c;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xdaeb('0x0'));var zipdir=require(_0xdaeb('0x1'));var jsonpatch=require(_0xdaeb('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xdaeb('0x3'));var Mustache=require(_0xdaeb('0x4'));var util=require(_0xdaeb('0x5'));var path=require('path');var sox=require(_0xdaeb('0x6'));var csv=require(_0xdaeb('0x7'));var ejs=require(_0xdaeb('0x8'));var fs=require('fs');var fs_extra=require(_0xdaeb('0x9'));var _=require('lodash');var squel=require(_0xdaeb('0xa'));var crypto=require(_0xdaeb('0xb'));var jsforce=require(_0xdaeb('0xc'));var deskjs=require(_0xdaeb('0xd'));var toCsv=require('to-csv');var querystring=require(_0xdaeb('0xe'));var Papa=require(_0xdaeb('0xf'));var Redis=require(_0xdaeb('0x10'));var authService=require(_0xdaeb('0x11'));var qs=require(_0xdaeb('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xdaeb('0x13'))(_0xdaeb('0x14'));var utils=require(_0xdaeb('0x15'));var config=require(_0xdaeb('0x16'));var licenseUtil=require(_0xdaeb('0x17'));var db=require(_0xdaeb('0x18'))['db'];function respondWithStatusCode(_0x34e27f,_0x244c46){_0x244c46=_0x244c46||0xcc;return function(_0x2ed202){if(_0x2ed202){return _0x34e27f['sendStatus'](_0x244c46);}return _0x34e27f['status'](_0x244c46)[_0xdaeb('0x19')]();};}function respondWithResult(_0x58e1ed,_0x24c984){_0x24c984=_0x24c984||0xc8;return function(_0x13f13e){if(_0x13f13e){return _0x58e1ed[_0xdaeb('0x1a')](_0x24c984)['json'](_0x13f13e);}};}function respondWithFilteredResult(_0x158f5e,_0x2d99cd){return function(_0x2280e2){if(_0x2280e2){var _0x59eae3=typeof _0x2d99cd[_0xdaeb('0x1b')]===_0xdaeb('0x1c')&&typeof _0x2d99cd[_0xdaeb('0x1d')]===_0xdaeb('0x1c');var _0x4a752d=_0x2280e2[_0xdaeb('0x1e')];var _0x11521c=_0x59eae3?0x0:_0x2d99cd[_0xdaeb('0x1b')];var _0x2f8bcb=_0x59eae3?_0x2280e2[_0xdaeb('0x1e')]:_0x2d99cd[_0xdaeb('0x1b')]+_0x2d99cd[_0xdaeb('0x1d')];var _0x530c54;if(_0x2f8bcb>=_0x4a752d){_0x2f8bcb=_0x4a752d;_0x530c54=0xc8;}else{_0x530c54=0xce;}_0x158f5e[_0xdaeb('0x1a')](_0x530c54);return _0x158f5e[_0xdaeb('0x1f')](_0xdaeb('0x20'),_0x11521c+'-'+_0x2f8bcb+'/'+_0x4a752d)[_0xdaeb('0x21')](_0x2280e2);}return null;};}function patchUpdates(_0x4fe49a){return function(_0x69a163){try{jsonpatch[_0xdaeb('0x22')](_0x69a163,_0x4fe49a,!![]);}catch(_0x165776){return BPromise[_0xdaeb('0x23')](_0x165776);}return _0x69a163[_0xdaeb('0x24')]();};}function saveUpdates(_0x216cfb,_0x230c4d){return function(_0x5909c4){if(_0x5909c4){return _0x5909c4[_0xdaeb('0x25')](_0x216cfb)[_0xdaeb('0x26')](function(_0x4700db){return _0x4700db;});}return null;};}function removeEntity(_0xf1cacd,_0x4507a2){return function(_0x326a4c){if(_0x326a4c){return _0x326a4c[_0xdaeb('0x27')]()[_0xdaeb('0x26')](function(){_0xf1cacd['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x14084e,_0x197d65){return function(_0x6c3291){if(!_0x6c3291){_0x14084e['sendStatus'](0x194);}return _0x6c3291;};}function handleError(_0xb9ca27,_0x6d8e4b){_0x6d8e4b=_0x6d8e4b||0x1f4;return function(_0x2d03eb){logger[_0xdaeb('0x28')](_0x2d03eb['stack']);if(_0x2d03eb[_0xdaeb('0x29')]){delete _0x2d03eb['name'];}_0xb9ca27['status'](_0x6d8e4b)[_0xdaeb('0x2a')](_0x2d03eb);};}exports[_0xdaeb('0x2b')]=function(_0xf424ca,_0x59a7a1){var _0x51b2fb={},_0x4c596c={},_0x4d3b39={'count':0x0,'rows':[]};var _0x1a9f97=_[_0xdaeb('0x2c')](db[_0xdaeb('0x2d')][_0xdaeb('0x2e')],function(_0x1726d1){return{'name':_0x1726d1[_0xdaeb('0x2f')],'type':_0x1726d1[_0xdaeb('0x30')][_0xdaeb('0x31')]};});_0x4c596c['model']=_['map'](_0x1a9f97,_0xdaeb('0x29'));_0x4c596c[_0xdaeb('0x32')]=_[_0xdaeb('0x33')](_0xf424ca['query']);_0x4c596c['filters']=_[_0xdaeb('0x34')](_0x4c596c[_0xdaeb('0x35')],_0x4c596c[_0xdaeb('0x32')]);_0x51b2fb[_0xdaeb('0x36')]=_[_0xdaeb('0x34')](_0x4c596c[_0xdaeb('0x35')],qs[_0xdaeb('0x37')](_0xf424ca[_0xdaeb('0x32')][_0xdaeb('0x37')]));_0x51b2fb[_0xdaeb('0x36')]=_0x51b2fb[_0xdaeb('0x36')][_0xdaeb('0x38')]?_0x51b2fb[_0xdaeb('0x36')]:_0x4c596c['model'];if(!_0xf424ca[_0xdaeb('0x32')][_0xdaeb('0x39')](_0xdaeb('0x3a'))){_0x51b2fb[_0xdaeb('0x1d')]=qs[_0xdaeb('0x1d')](_0xf424ca[_0xdaeb('0x32')][_0xdaeb('0x1d')]);_0x51b2fb[_0xdaeb('0x1b')]=qs[_0xdaeb('0x1b')](_0xf424ca[_0xdaeb('0x32')]['offset']);}_0x51b2fb[_0xdaeb('0x3b')]=qs['sort'](_0xf424ca[_0xdaeb('0x32')][_0xdaeb('0x3c')]);_0x51b2fb[_0xdaeb('0x3d')]=qs[_0xdaeb('0x3e')](_[_0xdaeb('0x3f')](_0xf424ca[_0xdaeb('0x32')],_0x4c596c[_0xdaeb('0x3e')]),_0x1a9f97);if(_0xf424ca[_0xdaeb('0x32')][_0xdaeb('0x40')]){_0x51b2fb[_0xdaeb('0x3d')]=_[_0xdaeb('0x41')](_0x51b2fb[_0xdaeb('0x3d')],{'$or':_[_0xdaeb('0x2c')](_0x1a9f97,function(_0x5beaeb){if(_0x5beaeb[_0xdaeb('0x30')]!==_0xdaeb('0x42')){var _0xde7e6a={};_0xde7e6a[_0x5beaeb[_0xdaeb('0x29')]]={'$like':'%'+_0xf424ca['query'][_0xdaeb('0x40')]+'%'};return _0xde7e6a;}})});}_0x51b2fb=_['merge']({},_0x51b2fb,_0xf424ca[_0xdaeb('0x43')]);var _0x42b497={'where':_0x51b2fb[_0xdaeb('0x3d')]};return db[_0xdaeb('0x2d')][_0xdaeb('0x1e')](_0x42b497)[_0xdaeb('0x26')](function(_0x38f900){_0x4d3b39['count']=_0x38f900;if(_0xf424ca['query'][_0xdaeb('0x44')]){_0x51b2fb[_0xdaeb('0x45')]=[{'all':!![]}];}return db['WhatsappTransferReport'][_0xdaeb('0x46')](_0x51b2fb);})[_0xdaeb('0x26')](function(_0x1dede2){_0x4d3b39[_0xdaeb('0x47')]=_0x1dede2;return _0x4d3b39;})[_0xdaeb('0x26')](respondWithFilteredResult(_0x59a7a1,_0x51b2fb))[_0xdaeb('0x48')](handleError(_0x59a7a1,null));};exports[_0xdaeb('0x49')]=function(_0x533e67,_0x259b72){var _0x384ad4={'raw':!![],'where':{'id':_0x533e67['params']['id']}},_0x146b9b={};_0x146b9b[_0xdaeb('0x35')]=_[_0xdaeb('0x33')](db[_0xdaeb('0x2d')][_0xdaeb('0x2e')]);_0x146b9b[_0xdaeb('0x32')]=_[_0xdaeb('0x33')](_0x533e67[_0xdaeb('0x32')]);_0x146b9b[_0xdaeb('0x3e')]=_[_0xdaeb('0x34')](_0x146b9b[_0xdaeb('0x35')],_0x146b9b[_0xdaeb('0x32')]);_0x384ad4[_0xdaeb('0x36')]=_['intersection'](_0x146b9b[_0xdaeb('0x35')],qs[_0xdaeb('0x37')](_0x533e67['query'][_0xdaeb('0x37')]));_0x384ad4[_0xdaeb('0x36')]=_0x384ad4[_0xdaeb('0x36')]['length']?_0x384ad4['attributes']:_0x146b9b['model'];if(_0x533e67[_0xdaeb('0x32')][_0xdaeb('0x44')]){_0x384ad4[_0xdaeb('0x45')]=[{'all':!![]}];}_0x384ad4=_['merge']({},_0x384ad4,_0x533e67[_0xdaeb('0x43')]);return db['WhatsappTransferReport'][_0xdaeb('0x4a')](_0x384ad4)['then'](handleEntityNotFound(_0x259b72,null))[_0xdaeb('0x26')](respondWithResult(_0x259b72,null))[_0xdaeb('0x48')](handleError(_0x259b72,null));};exports[_0xdaeb('0x4b')]=function(_0xcaf0e9,_0x631d60){return db['WhatsappTransferReport'][_0xdaeb('0x4b')](_0xcaf0e9[_0xdaeb('0x4c')],{})[_0xdaeb('0x26')](respondWithResult(_0x631d60,0xc9))[_0xdaeb('0x48')](handleError(_0x631d60,null));};exports[_0xdaeb('0x25')]=function(_0x1b396c,_0x1f3e02){if(_0x1b396c['body']['id']){delete _0x1b396c[_0xdaeb('0x4c')]['id'];}return db[_0xdaeb('0x2d')][_0xdaeb('0x4a')]({'where':{'id':_0x1b396c[_0xdaeb('0x4d')]['id']}})[_0xdaeb('0x26')](handleEntityNotFound(_0x1f3e02,null))[_0xdaeb('0x26')](saveUpdates(_0x1b396c[_0xdaeb('0x4c')],null))[_0xdaeb('0x26')](respondWithResult(_0x1f3e02,null))[_0xdaeb('0x48')](handleError(_0x1f3e02,null));};exports['destroy']=function(_0x1655e8,_0x3abf98){return db[_0xdaeb('0x2d')][_0xdaeb('0x4a')]({'where':{'id':_0x1655e8['params']['id']}})[_0xdaeb('0x26')](handleEntityNotFound(_0x3abf98,null))['then'](removeEntity(_0x3abf98,null))[_0xdaeb('0x48')](handleError(_0x3abf98,null));};exports[_0xdaeb('0x4e')]=function(_0x282685,_0x2475bf){return db[_0xdaeb('0x2d')][_0xdaeb('0x4e')]()[_0xdaeb('0x26')](respondWithResult(_0x2475bf,null))[_0xdaeb('0x48')](handleError(_0x2475bf,null));};