fd005372b2de4967527a9fd50d15ae02ed87def8
[motion2.git] / server / api / whatsappApplication / whatsappApplication.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 _0xc1d3=['rows','catch','show','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','json','undefined','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','end','sendStatus','error','stack','name','send','index','map','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','type','VIRTUAL','options','WhatsappApplication','includeAll','include','findAll'];(function(_0x43665e,_0x1cdd0d){var _0x3598a4=function(_0x1d96cb){while(--_0x1d96cb){_0x43665e['push'](_0x43665e['shift']());}};_0x3598a4(++_0x1cdd0d);}(_0xc1d3,0x147));var _0x3c1d=function(_0x1a7d59,_0x3dbe18){_0x1a7d59=_0x1a7d59-0x0;var _0x3ea517=_0xc1d3[_0x1a7d59];return _0x3ea517;};'use strict';var emlformat=require(_0x3c1d('0x0'));var rimraf=require(_0x3c1d('0x1'));var zipdir=require(_0x3c1d('0x2'));var jsonpatch=require(_0x3c1d('0x3'));var rp=require(_0x3c1d('0x4'));var moment=require(_0x3c1d('0x5'));var BPromise=require(_0x3c1d('0x6'));var Mustache=require('mustache');var util=require('util');var path=require(_0x3c1d('0x7'));var sox=require(_0x3c1d('0x8'));var csv=require(_0x3c1d('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3c1d('0xa'));var _=require(_0x3c1d('0xb'));var squel=require(_0x3c1d('0xc'));var crypto=require(_0x3c1d('0xd'));var jsforce=require(_0x3c1d('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x3c1d('0x9'));var querystring=require(_0x3c1d('0xf'));var Papa=require(_0x3c1d('0x10'));var Redis=require(_0x3c1d('0x11'));var authService=require(_0x3c1d('0x12'));var qs=require(_0x3c1d('0x13'));var as=require(_0x3c1d('0x14'));var hardwareService=require(_0x3c1d('0x15'));var logger=require('../../config/logger')(_0x3c1d('0x16'));var utils=require(_0x3c1d('0x17'));var config=require(_0x3c1d('0x18'));var licenseUtil=require(_0x3c1d('0x19'));var db=require(_0x3c1d('0x1a'))['db'];function respondWithStatusCode(_0x5a2402,_0xf3cd6d){_0xf3cd6d=_0xf3cd6d||0xcc;return function(_0x209b55){if(_0x209b55){return _0x5a2402['sendStatus'](_0xf3cd6d);}return _0x5a2402[_0x3c1d('0x1b')](_0xf3cd6d)['end']();};}function respondWithResult(_0x4ed530,_0x4b941d){_0x4b941d=_0x4b941d||0xc8;return function(_0x2875a9){if(_0x2875a9){return _0x4ed530[_0x3c1d('0x1b')](_0x4b941d)[_0x3c1d('0x1c')](_0x2875a9);}};}function respondWithFilteredResult(_0x434dbc,_0x2ed7af){return function(_0x2c0b83){if(_0x2c0b83){var _0x4e6157=typeof _0x2ed7af['offset']===_0x3c1d('0x1d')&&typeof _0x2ed7af['limit']===_0x3c1d('0x1d');var _0x295467=_0x2c0b83['count'];var _0x4a7e42=_0x4e6157?0x0:_0x2ed7af['offset'];var _0x33637d=_0x4e6157?_0x2c0b83[_0x3c1d('0x1e')]:_0x2ed7af[_0x3c1d('0x1f')]+_0x2ed7af[_0x3c1d('0x20')];var _0x9dce85;if(_0x33637d>=_0x295467){_0x33637d=_0x295467;_0x9dce85=0xc8;}else{_0x9dce85=0xce;}_0x434dbc['status'](_0x9dce85);return _0x434dbc['set'](_0x3c1d('0x21'),_0x4a7e42+'-'+_0x33637d+'/'+_0x295467)[_0x3c1d('0x1c')](_0x2c0b83);}return null;};}function patchUpdates(_0x3c7455){return function(_0x233dff){try{jsonpatch[_0x3c1d('0x22')](_0x233dff,_0x3c7455,!![]);}catch(_0x5b2720){return BPromise[_0x3c1d('0x23')](_0x5b2720);}return _0x233dff[_0x3c1d('0x24')]();};}function saveUpdates(_0xa5fd81,_0x5211d7){return function(_0x129497){if(_0x129497){return _0x129497[_0x3c1d('0x25')](_0xa5fd81)[_0x3c1d('0x26')](function(_0x210e9c){return _0x210e9c;});}return null;};}function removeEntity(_0x2e1af4,_0x1a853d){return function(_0x41a683){if(_0x41a683){return _0x41a683[_0x3c1d('0x27')]()[_0x3c1d('0x26')](function(){_0x2e1af4['status'](0xcc)[_0x3c1d('0x28')]();});}};}function handleEntityNotFound(_0x2a8854,_0x2078d5){return function(_0x4f7cd8){if(!_0x4f7cd8){_0x2a8854[_0x3c1d('0x29')](0x194);}return _0x4f7cd8;};}function handleError(_0x3bde45,_0x4e1f79){_0x4e1f79=_0x4e1f79||0x1f4;return function(_0x392bb1){logger[_0x3c1d('0x2a')](_0x392bb1[_0x3c1d('0x2b')]);if(_0x392bb1['name']){delete _0x392bb1[_0x3c1d('0x2c')];}_0x3bde45['status'](_0x4e1f79)[_0x3c1d('0x2d')](_0x392bb1);};}exports[_0x3c1d('0x2e')]=function(_0x59db0a,_0x4ff12a){var _0x356f61={},_0x2f7af9={},_0x93a3b1={'count':0x0,'rows':[]};var _0x52ab2b=_[_0x3c1d('0x2f')](db['WhatsappApplication'][_0x3c1d('0x30')],function(_0x438b09){return{'name':_0x438b09[_0x3c1d('0x31')],'type':_0x438b09['type'][_0x3c1d('0x32')]};});_0x2f7af9[_0x3c1d('0x33')]=_[_0x3c1d('0x2f')](_0x52ab2b,_0x3c1d('0x2c'));_0x2f7af9[_0x3c1d('0x34')]=_[_0x3c1d('0x35')](_0x59db0a[_0x3c1d('0x34')]);_0x2f7af9[_0x3c1d('0x36')]=_[_0x3c1d('0x37')](_0x2f7af9['model'],_0x2f7af9['query']);_0x356f61[_0x3c1d('0x38')]=_['intersection'](_0x2f7af9[_0x3c1d('0x33')],qs[_0x3c1d('0x39')](_0x59db0a[_0x3c1d('0x34')][_0x3c1d('0x39')]));_0x356f61[_0x3c1d('0x38')]=_0x356f61['attributes'][_0x3c1d('0x3a')]?_0x356f61[_0x3c1d('0x38')]:_0x2f7af9['model'];if(!_0x59db0a['query'][_0x3c1d('0x3b')](_0x3c1d('0x3c'))){_0x356f61[_0x3c1d('0x20')]=qs[_0x3c1d('0x20')](_0x59db0a[_0x3c1d('0x34')]['limit']);_0x356f61[_0x3c1d('0x1f')]=qs[_0x3c1d('0x1f')](_0x59db0a['query']['offset']);}_0x356f61['order']=qs[_0x3c1d('0x3d')](_0x59db0a[_0x3c1d('0x34')][_0x3c1d('0x3d')]);_0x356f61[_0x3c1d('0x3e')]=qs['filters'](_[_0x3c1d('0x3f')](_0x59db0a['query'],_0x2f7af9[_0x3c1d('0x36')]),_0x52ab2b);if(_0x59db0a[_0x3c1d('0x34')][_0x3c1d('0x40')]){_0x356f61[_0x3c1d('0x3e')]=_[_0x3c1d('0x41')](_0x356f61['where'],{'$or':_[_0x3c1d('0x2f')](_0x52ab2b,function(_0x28c575){if(_0x28c575[_0x3c1d('0x42')]!==_0x3c1d('0x43')){var _0x59c8fb={};_0x59c8fb[_0x28c575[_0x3c1d('0x2c')]]={'$like':'%'+_0x59db0a['query']['filter']+'%'};return _0x59c8fb;}})});}_0x356f61=_[_0x3c1d('0x41')]({},_0x356f61,_0x59db0a[_0x3c1d('0x44')]);var _0x58c490={'where':_0x356f61['where']};return db[_0x3c1d('0x45')][_0x3c1d('0x1e')](_0x58c490)['then'](function(_0x4f07d6){_0x93a3b1[_0x3c1d('0x1e')]=_0x4f07d6;if(_0x59db0a[_0x3c1d('0x34')][_0x3c1d('0x46')]){_0x356f61[_0x3c1d('0x47')]=[{'all':!![]}];}return db[_0x3c1d('0x45')][_0x3c1d('0x48')](_0x356f61);})[_0x3c1d('0x26')](function(_0x11bca2){_0x93a3b1[_0x3c1d('0x49')]=_0x11bca2;return _0x93a3b1;})[_0x3c1d('0x26')](respondWithFilteredResult(_0x4ff12a,_0x356f61))[_0x3c1d('0x4a')](handleError(_0x4ff12a,null));};exports[_0x3c1d('0x4b')]=function(_0x4b0f40,_0x21dbef){var _0x5ca02c={'raw':!![],'where':{'id':_0x4b0f40['params']['id']}},_0x415a61={};_0x415a61[_0x3c1d('0x33')]=_['keys'](db[_0x3c1d('0x45')][_0x3c1d('0x30')]);_0x415a61[_0x3c1d('0x34')]=_[_0x3c1d('0x35')](_0x4b0f40['query']);_0x415a61[_0x3c1d('0x36')]=_['intersection'](_0x415a61[_0x3c1d('0x33')],_0x415a61[_0x3c1d('0x34')]);_0x5ca02c[_0x3c1d('0x38')]=_[_0x3c1d('0x37')](_0x415a61['model'],qs[_0x3c1d('0x39')](_0x4b0f40[_0x3c1d('0x34')][_0x3c1d('0x39')]));_0x5ca02c[_0x3c1d('0x38')]=_0x5ca02c[_0x3c1d('0x38')]['length']?_0x5ca02c[_0x3c1d('0x38')]:_0x415a61[_0x3c1d('0x33')];if(_0x4b0f40[_0x3c1d('0x34')]['includeAll']){_0x5ca02c['include']=[{'all':!![]}];}_0x5ca02c=_[_0x3c1d('0x41')]({},_0x5ca02c,_0x4b0f40[_0x3c1d('0x44')]);return db[_0x3c1d('0x45')][_0x3c1d('0x4c')](_0x5ca02c)[_0x3c1d('0x26')](handleEntityNotFound(_0x21dbef,null))[_0x3c1d('0x26')](respondWithResult(_0x21dbef,null))['catch'](handleError(_0x21dbef,null));};exports[_0x3c1d('0x4d')]=function(_0x4c533e,_0x34ad3a){return db[_0x3c1d('0x45')][_0x3c1d('0x4d')](_0x4c533e[_0x3c1d('0x4e')],{})[_0x3c1d('0x26')](respondWithResult(_0x34ad3a,0xc9))[_0x3c1d('0x4a')](handleError(_0x34ad3a,null));};exports[_0x3c1d('0x25')]=function(_0x4f0b44,_0x576552){if(_0x4f0b44['body']['id']){delete _0x4f0b44[_0x3c1d('0x4e')]['id'];}return db[_0x3c1d('0x45')][_0x3c1d('0x4c')]({'where':{'id':_0x4f0b44[_0x3c1d('0x4f')]['id']}})[_0x3c1d('0x26')](handleEntityNotFound(_0x576552,null))[_0x3c1d('0x26')](saveUpdates(_0x4f0b44['body'],null))[_0x3c1d('0x26')](respondWithResult(_0x576552,null))[_0x3c1d('0x4a')](handleError(_0x576552,null));};exports['destroy']=function(_0x4bc4ac,_0x4302f3){return db[_0x3c1d('0x45')][_0x3c1d('0x4c')]({'where':{'id':_0x4bc4ac[_0x3c1d('0x4f')]['id']}})[_0x3c1d('0x26')](handleEntityNotFound(_0x4302f3,null))[_0x3c1d('0x26')](removeEntity(_0x4302f3,null))[_0x3c1d('0x4a')](handleError(_0x4302f3,null));};