Built motion from commit (unavailable).|2.5.18
[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 _0x912f=['fast-json-patch','request-promise','moment','bluebird','sox','to-csv','lodash','squel','crypto','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../mysqldb','status','end','json','offset','Content-Range','reject','save','then','error','name','send','index','map','WhatsappTransferReport','rawAttributes','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','limit','order','sort','where','filters','pick','VIRTUAL','merge','options','count','findAll','rows','show','params','includeAll','include','find','catch','create','body','update','destroy','describe','html-pdf','eml-format','rimraf'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x912f,0x1d9));var _0xf912=function(_0x1798c3,_0x19e909){_0x1798c3=_0x1798c3-0x0;var _0x13e392=_0x912f[_0x1798c3];return _0x13e392;};'use strict';var pdf=require(_0xf912('0x0'));var emlformat=require(_0xf912('0x1'));var rimraf=require(_0xf912('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf912('0x3'));var rp=require(_0xf912('0x4'));var moment=require(_0xf912('0x5'));var BPromise=require(_0xf912('0x6'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xf912('0x7'));var csv=require(_0xf912('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xf912('0x9'));var squel=require(_0xf912('0xa'));var crypto=require(_0xf912('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf912('0x8'));var querystring=require(_0xf912('0xc'));var Papa=require(_0xf912('0xd'));var Redis=require(_0xf912('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xf912('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf912('0x10'));var logger=require(_0xf912('0x11'))(_0xf912('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xf912('0x13'))['db'];function respondWithStatusCode(_0x2a1053,_0x241b89){_0x241b89=_0x241b89||0xcc;return function(_0x289114){if(_0x289114){return _0x2a1053['sendStatus'](_0x241b89);}return _0x2a1053[_0xf912('0x14')](_0x241b89)[_0xf912('0x15')]();};}function respondWithResult(_0x4e7c3,_0x4d8fc0){_0x4d8fc0=_0x4d8fc0||0xc8;return function(_0x4bfd8c){if(_0x4bfd8c){return _0x4e7c3[_0xf912('0x14')](_0x4d8fc0)[_0xf912('0x16')](_0x4bfd8c);}};}function respondWithFilteredResult(_0x37a387,_0x68881){return function(_0x313483){if(_0x313483){var _0x199a62=_0x313483['count'],_0x3ab965=_0x68881[_0xf912('0x17')],_0x248f15=_0x68881[_0xf912('0x17')]+_0x68881['limit'],_0x158826;if(_0x248f15>=_0x199a62){_0x248f15=_0x199a62;_0x158826=0xc8;}else{_0x158826=0xce;}_0x37a387[_0xf912('0x14')](_0x158826);return _0x37a387['set'](_0xf912('0x18'),_0x3ab965+'-'+_0x248f15+'/'+_0x199a62)['json'](_0x313483);}return null;};}function patchUpdates(_0x20f27e){return function(_0x152fbf){try{jsonpatch['apply'](_0x152fbf,_0x20f27e,!![]);}catch(_0x4e8696){return BPromise[_0xf912('0x19')](_0x4e8696);}return _0x152fbf[_0xf912('0x1a')]();};}function saveUpdates(_0x2a01e6,_0x3f537f){return function(_0xc6423e){if(_0xc6423e){return _0xc6423e['update'](_0x2a01e6)[_0xf912('0x1b')](function(_0x35215d){return _0x35215d;});}return null;};}function removeEntity(_0x3a7b14,_0x257bca){return function(_0x5d87fa){if(_0x5d87fa){return _0x5d87fa['destroy']()['then'](function(){_0x3a7b14[_0xf912('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0x18fd4c,_0x4fd19f){return function(_0x310e0d){if(!_0x310e0d){_0x18fd4c['sendStatus'](0x194);}return _0x310e0d;};}function handleError(_0xd55095,_0x3070fb){_0x3070fb=_0x3070fb||0x1f4;return function(_0x3d0faf){logger[_0xf912('0x1c')](_0x3d0faf['stack']);if(_0x3d0faf['name']){delete _0x3d0faf[_0xf912('0x1d')];}_0xd55095[_0xf912('0x14')](_0x3070fb)[_0xf912('0x1e')](_0x3d0faf);};}exports[_0xf912('0x1f')]=function(_0x722d29,_0x46a6d4){var _0x4a5004={},_0x49a454={},_0xf12a68={'count':0x0,'rows':[]};var _0x485e2d=_[_0xf912('0x20')](db[_0xf912('0x21')][_0xf912('0x22')],function(_0x34ff42){return{'name':_0x34ff42['fieldName'],'type':_0x34ff42[_0xf912('0x23')][_0xf912('0x24')]};});_0x49a454[_0xf912('0x25')]=_[_0xf912('0x20')](_0x485e2d,_0xf912('0x1d'));_0x49a454[_0xf912('0x26')]=_[_0xf912('0x27')](_0x722d29['query']);_0x49a454['filters']=_[_0xf912('0x28')](_0x49a454[_0xf912('0x25')],_0x49a454['query']);_0x4a5004['attributes']=_[_0xf912('0x28')](_0x49a454['model'],qs[_0xf912('0x29')](_0x722d29[_0xf912('0x26')][_0xf912('0x29')]));_0x4a5004[_0xf912('0x2a')]=_0x4a5004['attributes'][_0xf912('0x2b')]?_0x4a5004['attributes']:_0x49a454[_0xf912('0x25')];if(!_0x722d29[_0xf912('0x26')][_0xf912('0x2c')]('nolimit')){_0x4a5004[_0xf912('0x2d')]=qs[_0xf912('0x2d')](_0x722d29[_0xf912('0x26')]['limit']);_0x4a5004['offset']=qs['offset'](_0x722d29[_0xf912('0x26')][_0xf912('0x17')]);}_0x4a5004[_0xf912('0x2e')]=qs[_0xf912('0x2f')](_0x722d29[_0xf912('0x26')][_0xf912('0x2f')]);_0x4a5004[_0xf912('0x30')]=qs[_0xf912('0x31')](_[_0xf912('0x32')](_0x722d29[_0xf912('0x26')],_0x49a454['filters']),_0x485e2d);if(_0x722d29[_0xf912('0x26')]['filter']){_0x4a5004['where']=_['merge'](_0x4a5004[_0xf912('0x30')],{'$or':_[_0xf912('0x20')](_0x485e2d,function(_0x21595f){if(_0x21595f[_0xf912('0x23')]!==_0xf912('0x33')){var _0x182c1f={};_0x182c1f[_0x21595f[_0xf912('0x1d')]]={'$like':'%'+_0x722d29[_0xf912('0x26')]['filter']+'%'};return _0x182c1f;}})});}_0x4a5004=_[_0xf912('0x34')]({},_0x4a5004,_0x722d29[_0xf912('0x35')]);var _0x6f37e1={'where':_0x4a5004['where']};return db[_0xf912('0x21')][_0xf912('0x36')](_0x6f37e1)[_0xf912('0x1b')](function(_0x2b570e){_0xf12a68[_0xf912('0x36')]=_0x2b570e;if(_0x722d29[_0xf912('0x26')]['includeAll']){_0x4a5004['include']=[{'all':!![]}];}return db['WhatsappTransferReport'][_0xf912('0x37')](_0x4a5004);})[_0xf912('0x1b')](function(_0x4b32a6){_0xf12a68[_0xf912('0x38')]=_0x4b32a6;return _0xf12a68;})[_0xf912('0x1b')](respondWithFilteredResult(_0x46a6d4,_0x4a5004))['catch'](handleError(_0x46a6d4,null));};exports[_0xf912('0x39')]=function(_0x4b50eb,_0x3fbc07){var _0x4e7260={'raw':!![],'where':{'id':_0x4b50eb[_0xf912('0x3a')]['id']}},_0x2140e7={};_0x2140e7['model']=_[_0xf912('0x27')](db['WhatsappTransferReport']['rawAttributes']);_0x2140e7[_0xf912('0x26')]=_[_0xf912('0x27')](_0x4b50eb[_0xf912('0x26')]);_0x2140e7['filters']=_[_0xf912('0x28')](_0x2140e7[_0xf912('0x25')],_0x2140e7[_0xf912('0x26')]);_0x4e7260['attributes']=_[_0xf912('0x28')](_0x2140e7['model'],qs[_0xf912('0x29')](_0x4b50eb[_0xf912('0x26')][_0xf912('0x29')]));_0x4e7260[_0xf912('0x2a')]=_0x4e7260[_0xf912('0x2a')][_0xf912('0x2b')]?_0x4e7260[_0xf912('0x2a')]:_0x2140e7[_0xf912('0x25')];if(_0x4b50eb[_0xf912('0x26')][_0xf912('0x3b')]){_0x4e7260[_0xf912('0x3c')]=[{'all':!![]}];}_0x4e7260=_[_0xf912('0x34')]({},_0x4e7260,_0x4b50eb[_0xf912('0x35')]);return db[_0xf912('0x21')][_0xf912('0x3d')](_0x4e7260)[_0xf912('0x1b')](handleEntityNotFound(_0x3fbc07,null))[_0xf912('0x1b')](respondWithResult(_0x3fbc07,null))[_0xf912('0x3e')](handleError(_0x3fbc07,null));};exports[_0xf912('0x3f')]=function(_0x395ec2,_0x39ed24){return db['WhatsappTransferReport'][_0xf912('0x3f')](_0x395ec2[_0xf912('0x40')],{})[_0xf912('0x1b')](respondWithResult(_0x39ed24,0xc9))[_0xf912('0x3e')](handleError(_0x39ed24,null));};exports[_0xf912('0x41')]=function(_0x5c8e91,_0x160a1e){if(_0x5c8e91[_0xf912('0x40')]['id']){delete _0x5c8e91[_0xf912('0x40')]['id'];}return db[_0xf912('0x21')][_0xf912('0x3d')]({'where':{'id':_0x5c8e91['params']['id']}})[_0xf912('0x1b')](handleEntityNotFound(_0x160a1e,null))[_0xf912('0x1b')](saveUpdates(_0x5c8e91[_0xf912('0x40')],null))[_0xf912('0x1b')](respondWithResult(_0x160a1e,null))[_0xf912('0x3e')](handleError(_0x160a1e,null));};exports[_0xf912('0x42')]=function(_0x363e7d,_0x52dabd){return db[_0xf912('0x21')]['find']({'where':{'id':_0x363e7d[_0xf912('0x3a')]['id']}})['then'](handleEntityNotFound(_0x52dabd,null))[_0xf912('0x1b')](removeEntity(_0x52dabd,null))[_0xf912('0x3e')](handleError(_0x52dabd,null));};exports[_0xf912('0x43')]=function(_0x51866f,_0x1aa6d0){return db[_0xf912('0x21')][_0xf912('0x43')]()[_0xf912('0x1b')](respondWithResult(_0x1aa6d0,null))[_0xf912('0x3e')](handleError(_0x1aa6d0,null));};