Built motion from commit 87cd5f02.|2.5.48
[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 _0xf4ce=['then','error','name','index','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','findAll','rows','catch','WhatsappApplication','rawAttributes','includeAll','include','find','create','body','params','destroy','eml-format','fast-json-patch','request-promise','moment','bluebird','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','status','end','json','offset','undefined','limit','count','Content-Range','apply','save','update'];(function(_0x13b02f,_0x462a53){var _0x12e9a6=function(_0x187d57){while(--_0x187d57){_0x13b02f['push'](_0x13b02f['shift']());}};_0x12e9a6(++_0x462a53);}(_0xf4ce,0xf2));var _0xef4c=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0xf4ce[_0x2dafbe];return _0x58a45a;};'use strict';var emlformat=require(_0xef4c('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xef4c('0x1'));var rp=require(_0xef4c('0x2'));var moment=require(_0xef4c('0x3'));var BPromise=require(_0xef4c('0x4'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xef4c('0x5'));var fs=require('fs');var fs_extra=require(_0xef4c('0x6'));var _=require(_0xef4c('0x7'));var squel=require(_0xef4c('0x8'));var crypto=require(_0xef4c('0x9'));var jsforce=require(_0xef4c('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xef4c('0xb'));var querystring=require(_0xef4c('0xc'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xef4c('0xd'));var as=require(_0xef4c('0xe'));var hardwareService=require(_0xef4c('0xf'));var logger=require(_0xef4c('0x10'))('api');var utils=require(_0xef4c('0x11'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xef4c('0x12'))['db'];function respondWithStatusCode(_0x3bda49,_0x2bfe28){_0x2bfe28=_0x2bfe28||0xcc;return function(_0x6a1290){if(_0x6a1290){return _0x3bda49['sendStatus'](_0x2bfe28);}return _0x3bda49[_0xef4c('0x13')](_0x2bfe28)[_0xef4c('0x14')]();};}function respondWithResult(_0x12d7a6,_0x417f67){_0x417f67=_0x417f67||0xc8;return function(_0x2a2631){if(_0x2a2631){return _0x12d7a6[_0xef4c('0x13')](_0x417f67)[_0xef4c('0x15')](_0x2a2631);}};}function respondWithFilteredResult(_0x1c7633,_0x5dc6a3){return function(_0x55a7aa){if(_0x55a7aa){var _0x3637ce=typeof _0x5dc6a3[_0xef4c('0x16')]===_0xef4c('0x17')&&typeof _0x5dc6a3[_0xef4c('0x18')]===_0xef4c('0x17');var _0x371f2a=_0x55a7aa[_0xef4c('0x19')];var _0x446847=_0x3637ce?0x0:_0x5dc6a3[_0xef4c('0x16')];var _0x2bcc97=_0x3637ce?_0x55a7aa[_0xef4c('0x19')]:_0x5dc6a3[_0xef4c('0x16')]+_0x5dc6a3[_0xef4c('0x18')];var _0x560486;if(_0x2bcc97>=_0x371f2a){_0x2bcc97=_0x371f2a;_0x560486=0xc8;}else{_0x560486=0xce;}_0x1c7633[_0xef4c('0x13')](_0x560486);return _0x1c7633['set'](_0xef4c('0x1a'),_0x446847+'-'+_0x2bcc97+'/'+_0x371f2a)[_0xef4c('0x15')](_0x55a7aa);}return null;};}function patchUpdates(_0x46f556){return function(_0xd4e0a){try{jsonpatch[_0xef4c('0x1b')](_0xd4e0a,_0x46f556,!![]);}catch(_0x3bf901){return BPromise['reject'](_0x3bf901);}return _0xd4e0a[_0xef4c('0x1c')]();};}function saveUpdates(_0x460860,_0x500bd3){return function(_0x251e29){if(_0x251e29){return _0x251e29[_0xef4c('0x1d')](_0x460860)[_0xef4c('0x1e')](function(_0x4f4a3a){return _0x4f4a3a;});}return null;};}function removeEntity(_0x1f98a1,_0x17c816){return function(_0x2aca1e){if(_0x2aca1e){return _0x2aca1e['destroy']()[_0xef4c('0x1e')](function(){_0x1f98a1[_0xef4c('0x13')](0xcc)[_0xef4c('0x14')]();});}};}function handleEntityNotFound(_0xfd0013,_0x3f4015){return function(_0x26f523){if(!_0x26f523){_0xfd0013['sendStatus'](0x194);}return _0x26f523;};}function handleError(_0x7e3dd8,_0x286ad3){_0x286ad3=_0x286ad3||0x1f4;return function(_0x35f404){logger[_0xef4c('0x1f')](_0x35f404['stack']);if(_0x35f404[_0xef4c('0x20')]){delete _0x35f404['name'];}_0x7e3dd8[_0xef4c('0x13')](_0x286ad3)['send'](_0x35f404);};}exports[_0xef4c('0x21')]=function(_0x15dfba,_0x39fb17){var _0x13eb57={},_0x8fe191={},_0xb10f30={'count':0x0,'rows':[]};var _0x539486=_['map'](db['WhatsappApplication']['rawAttributes'],function(_0x1d587a){return{'name':_0x1d587a[_0xef4c('0x22')],'type':_0x1d587a[_0xef4c('0x23')][_0xef4c('0x24')]};});_0x8fe191[_0xef4c('0x25')]=_[_0xef4c('0x26')](_0x539486,_0xef4c('0x20'));_0x8fe191[_0xef4c('0x27')]=_[_0xef4c('0x28')](_0x15dfba[_0xef4c('0x27')]);_0x8fe191[_0xef4c('0x29')]=_[_0xef4c('0x2a')](_0x8fe191['model'],_0x8fe191['query']);_0x13eb57[_0xef4c('0x2b')]=_[_0xef4c('0x2a')](_0x8fe191['model'],qs[_0xef4c('0x2c')](_0x15dfba[_0xef4c('0x27')]['fields']));_0x13eb57[_0xef4c('0x2b')]=_0x13eb57[_0xef4c('0x2b')][_0xef4c('0x2d')]?_0x13eb57[_0xef4c('0x2b')]:_0x8fe191['model'];if(!_0x15dfba[_0xef4c('0x27')][_0xef4c('0x2e')](_0xef4c('0x2f'))){_0x13eb57[_0xef4c('0x18')]=qs[_0xef4c('0x18')](_0x15dfba[_0xef4c('0x27')][_0xef4c('0x18')]);_0x13eb57['offset']=qs[_0xef4c('0x16')](_0x15dfba[_0xef4c('0x27')][_0xef4c('0x16')]);}_0x13eb57[_0xef4c('0x30')]=qs[_0xef4c('0x31')](_0x15dfba['query']['sort']);_0x13eb57[_0xef4c('0x32')]=qs[_0xef4c('0x29')](_[_0xef4c('0x33')](_0x15dfba[_0xef4c('0x27')],_0x8fe191[_0xef4c('0x29')]),_0x539486);if(_0x15dfba[_0xef4c('0x27')][_0xef4c('0x34')]){_0x13eb57[_0xef4c('0x32')]=_[_0xef4c('0x35')](_0x13eb57['where'],{'$or':_['map'](_0x539486,function(_0x7f3c9b){if(_0x7f3c9b[_0xef4c('0x23')]!==_0xef4c('0x36')){var _0x14d621={};_0x14d621[_0x7f3c9b[_0xef4c('0x20')]]={'$like':'%'+_0x15dfba[_0xef4c('0x27')][_0xef4c('0x34')]+'%'};return _0x14d621;}})});}_0x13eb57=_[_0xef4c('0x35')]({},_0x13eb57,_0x15dfba[_0xef4c('0x37')]);var _0x19524a={'where':_0x13eb57['where']};return db['WhatsappApplication']['count'](_0x19524a)[_0xef4c('0x1e')](function(_0x519a17){_0xb10f30['count']=_0x519a17;if(_0x15dfba['query']['includeAll']){_0x13eb57['include']=[{'all':!![]}];}return db['WhatsappApplication'][_0xef4c('0x38')](_0x13eb57);})[_0xef4c('0x1e')](function(_0x46edf0){_0xb10f30[_0xef4c('0x39')]=_0x46edf0;return _0xb10f30;})[_0xef4c('0x1e')](respondWithFilteredResult(_0x39fb17,_0x13eb57))[_0xef4c('0x3a')](handleError(_0x39fb17,null));};exports['show']=function(_0x2afdec,_0x35d30e){var _0x1ec099={'raw':!![],'where':{'id':_0x2afdec['params']['id']}},_0x1f7a13={};_0x1f7a13['model']=_[_0xef4c('0x28')](db[_0xef4c('0x3b')][_0xef4c('0x3c')]);_0x1f7a13[_0xef4c('0x27')]=_[_0xef4c('0x28')](_0x2afdec[_0xef4c('0x27')]);_0x1f7a13[_0xef4c('0x29')]=_[_0xef4c('0x2a')](_0x1f7a13['model'],_0x1f7a13['query']);_0x1ec099[_0xef4c('0x2b')]=_['intersection'](_0x1f7a13[_0xef4c('0x25')],qs[_0xef4c('0x2c')](_0x2afdec[_0xef4c('0x27')][_0xef4c('0x2c')]));_0x1ec099[_0xef4c('0x2b')]=_0x1ec099[_0xef4c('0x2b')][_0xef4c('0x2d')]?_0x1ec099[_0xef4c('0x2b')]:_0x1f7a13[_0xef4c('0x25')];if(_0x2afdec[_0xef4c('0x27')][_0xef4c('0x3d')]){_0x1ec099[_0xef4c('0x3e')]=[{'all':!![]}];}_0x1ec099=_['merge']({},_0x1ec099,_0x2afdec[_0xef4c('0x37')]);return db[_0xef4c('0x3b')][_0xef4c('0x3f')](_0x1ec099)[_0xef4c('0x1e')](handleEntityNotFound(_0x35d30e,null))[_0xef4c('0x1e')](respondWithResult(_0x35d30e,null))[_0xef4c('0x3a')](handleError(_0x35d30e,null));};exports['create']=function(_0x2710fc,_0x20a30b){return db[_0xef4c('0x3b')][_0xef4c('0x40')](_0x2710fc['body'],{})[_0xef4c('0x1e')](respondWithResult(_0x20a30b,0xc9))['catch'](handleError(_0x20a30b,null));};exports[_0xef4c('0x1d')]=function(_0x2eb3ad,_0x5e89de){if(_0x2eb3ad[_0xef4c('0x41')]['id']){delete _0x2eb3ad[_0xef4c('0x41')]['id'];}return db['WhatsappApplication'][_0xef4c('0x3f')]({'where':{'id':_0x2eb3ad[_0xef4c('0x42')]['id']}})[_0xef4c('0x1e')](handleEntityNotFound(_0x5e89de,null))['then'](saveUpdates(_0x2eb3ad[_0xef4c('0x41')],null))[_0xef4c('0x1e')](respondWithResult(_0x5e89de,null))[_0xef4c('0x3a')](handleError(_0x5e89de,null));};exports[_0xef4c('0x43')]=function(_0x2d5e1a,_0x27056c){return db[_0xef4c('0x3b')]['find']({'where':{'id':_0x2d5e1a[_0xef4c('0x42')]['id']}})[_0xef4c('0x1e')](handleEntityNotFound(_0x27056c,null))[_0xef4c('0x1e')](removeEntity(_0x27056c,null))[_0xef4c('0x3a')](handleError(_0x27056c,null));};