dc6342a10d9abb99d68c85ef59a2c9cd50fb01bd
[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 _0xa7ee=['../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','reject','save','update','destroy','then','error','stack','name','send','map','WhatsappApplication','fieldName','key','model','keys','query','filters','intersection','fields','attributes','nolimit','order','sort','where','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','length','find','create','body','params','eml-format','zip-dir','fast-json-patch','request-promise','moment','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','ioredis'];(function(_0xdb2727,_0xce46aa){var _0x36d766=function(_0x62a5a7){while(--_0x62a5a7){_0xdb2727['push'](_0xdb2727['shift']());}};_0x36d766(++_0xce46aa);}(_0xa7ee,0x159));var _0xea7e=function(_0x531a19,_0x43e019){_0x531a19=_0x531a19-0x0;var _0x4845d2=_0xa7ee[_0x531a19];return _0x4845d2;};'use strict';var emlformat=require(_0xea7e('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xea7e('0x1'));var jsonpatch=require(_0xea7e('0x2'));var rp=require(_0xea7e('0x3'));var moment=require(_0xea7e('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xea7e('0x5'));var path=require('path');var sox=require(_0xea7e('0x6'));var csv=require(_0xea7e('0x7'));var ejs=require(_0xea7e('0x8'));var fs=require('fs');var fs_extra=require(_0xea7e('0x9'));var _=require('lodash');var squel=require(_0xea7e('0xa'));var crypto=require(_0xea7e('0xb'));var jsforce=require(_0xea7e('0xc'));var deskjs=require(_0xea7e('0xd'));var toCsv=require(_0xea7e('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xea7e('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xea7e('0xf'));var as=require(_0xea7e('0x10'));var hardwareService=require(_0xea7e('0x11'));var logger=require(_0xea7e('0x12'))('api');var utils=require(_0xea7e('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0xea7e('0x14'));var db=require(_0xea7e('0x15'))['db'];function respondWithStatusCode(_0x138555,_0x1d2702){_0x1d2702=_0x1d2702||0xcc;return function(_0x97ec09){if(_0x97ec09){return _0x138555[_0xea7e('0x16')](_0x1d2702);}return _0x138555[_0xea7e('0x17')](_0x1d2702)[_0xea7e('0x18')]();};}function respondWithResult(_0x4c5137,_0x25317c){_0x25317c=_0x25317c||0xc8;return function(_0x3ef916){if(_0x3ef916){return _0x4c5137[_0xea7e('0x17')](_0x25317c)[_0xea7e('0x19')](_0x3ef916);}};}function respondWithFilteredResult(_0x57d27e,_0x18f7f0){return function(_0x4d3796){if(_0x4d3796){var _0x5c7466=typeof _0x18f7f0[_0xea7e('0x1a')]===_0xea7e('0x1b')&&typeof _0x18f7f0[_0xea7e('0x1c')]==='undefined';var _0x5c3b15=_0x4d3796[_0xea7e('0x1d')];var _0x5becf4=_0x5c7466?0x0:_0x18f7f0[_0xea7e('0x1a')];var _0x125aec=_0x5c7466?_0x4d3796['count']:_0x18f7f0['offset']+_0x18f7f0[_0xea7e('0x1c')];var _0x59e8d8;if(_0x125aec>=_0x5c3b15){_0x125aec=_0x5c3b15;_0x59e8d8=0xc8;}else{_0x59e8d8=0xce;}_0x57d27e['status'](_0x59e8d8);return _0x57d27e[_0xea7e('0x1e')]('Content-Range',_0x5becf4+'-'+_0x125aec+'/'+_0x5c3b15)[_0xea7e('0x19')](_0x4d3796);}return null;};}function patchUpdates(_0x1def2a){return function(_0x5c8d42){try{jsonpatch[_0xea7e('0x1f')](_0x5c8d42,_0x1def2a,!![]);}catch(_0x52dfb0){return BPromise[_0xea7e('0x20')](_0x52dfb0);}return _0x5c8d42[_0xea7e('0x21')]();};}function saveUpdates(_0xf779ad,_0xd441f8){return function(_0x372b9d){if(_0x372b9d){return _0x372b9d[_0xea7e('0x22')](_0xf779ad)['then'](function(_0xd41599){return _0xd41599;});}return null;};}function removeEntity(_0x1ddcc7,_0x4e8b96){return function(_0xb8149f){if(_0xb8149f){return _0xb8149f[_0xea7e('0x23')]()[_0xea7e('0x24')](function(){_0x1ddcc7['status'](0xcc)[_0xea7e('0x18')]();});}};}function handleEntityNotFound(_0x400125,_0x41b995){return function(_0x49ce51){if(!_0x49ce51){_0x400125[_0xea7e('0x16')](0x194);}return _0x49ce51;};}function handleError(_0x2a6623,_0x41d40c){_0x41d40c=_0x41d40c||0x1f4;return function(_0x7a75a6){logger[_0xea7e('0x25')](_0x7a75a6[_0xea7e('0x26')]);if(_0x7a75a6[_0xea7e('0x27')]){delete _0x7a75a6[_0xea7e('0x27')];}_0x2a6623[_0xea7e('0x17')](_0x41d40c)[_0xea7e('0x28')](_0x7a75a6);};}exports['index']=function(_0x1744f3,_0xd856de){var _0x4d3c38={},_0x2a1753={},_0x3a9465={'count':0x0,'rows':[]};var _0x1951c0=_[_0xea7e('0x29')](db[_0xea7e('0x2a')]['rawAttributes'],function(_0x38d8a7){return{'name':_0x38d8a7[_0xea7e('0x2b')],'type':_0x38d8a7['type'][_0xea7e('0x2c')]};});_0x2a1753[_0xea7e('0x2d')]=_['map'](_0x1951c0,_0xea7e('0x27'));_0x2a1753['query']=_[_0xea7e('0x2e')](_0x1744f3[_0xea7e('0x2f')]);_0x2a1753[_0xea7e('0x30')]=_[_0xea7e('0x31')](_0x2a1753[_0xea7e('0x2d')],_0x2a1753[_0xea7e('0x2f')]);_0x4d3c38['attributes']=_[_0xea7e('0x31')](_0x2a1753[_0xea7e('0x2d')],qs[_0xea7e('0x32')](_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x32')]));_0x4d3c38[_0xea7e('0x33')]=_0x4d3c38['attributes']['length']?_0x4d3c38[_0xea7e('0x33')]:_0x2a1753[_0xea7e('0x2d')];if(!_0x1744f3[_0xea7e('0x2f')]['hasOwnProperty'](_0xea7e('0x34'))){_0x4d3c38[_0xea7e('0x1c')]=qs[_0xea7e('0x1c')](_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x1c')]);_0x4d3c38[_0xea7e('0x1a')]=qs[_0xea7e('0x1a')](_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x1a')]);}_0x4d3c38[_0xea7e('0x35')]=qs[_0xea7e('0x36')](_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x36')]);_0x4d3c38[_0xea7e('0x37')]=qs[_0xea7e('0x30')](_['pick'](_0x1744f3[_0xea7e('0x2f')],_0x2a1753[_0xea7e('0x30')]),_0x1951c0);if(_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x38')]){_0x4d3c38['where']=_[_0xea7e('0x39')](_0x4d3c38['where'],{'$or':_[_0xea7e('0x29')](_0x1951c0,function(_0x51ceb2){if(_0x51ceb2[_0xea7e('0x3a')]!==_0xea7e('0x3b')){var _0x468606={};_0x468606[_0x51ceb2[_0xea7e('0x27')]]={'$like':'%'+_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x38')]+'%'};return _0x468606;}})});}_0x4d3c38=_['merge']({},_0x4d3c38,_0x1744f3[_0xea7e('0x3c')]);var _0x369cad={'where':_0x4d3c38['where']};return db[_0xea7e('0x2a')]['count'](_0x369cad)[_0xea7e('0x24')](function(_0x233824){_0x3a9465['count']=_0x233824;if(_0x1744f3[_0xea7e('0x2f')][_0xea7e('0x3d')]){_0x4d3c38[_0xea7e('0x3e')]=[{'all':!![]}];}return db[_0xea7e('0x2a')][_0xea7e('0x3f')](_0x4d3c38);})[_0xea7e('0x24')](function(_0x2db099){_0x3a9465[_0xea7e('0x40')]=_0x2db099;return _0x3a9465;})[_0xea7e('0x24')](respondWithFilteredResult(_0xd856de,_0x4d3c38))[_0xea7e('0x41')](handleError(_0xd856de,null));};exports[_0xea7e('0x42')]=function(_0x40093a,_0x44a501){var _0x18fd0f={'raw':!![],'where':{'id':_0x40093a['params']['id']}},_0x507d92={};_0x507d92['model']=_['keys'](db['WhatsappApplication']['rawAttributes']);_0x507d92[_0xea7e('0x2f')]=_['keys'](_0x40093a[_0xea7e('0x2f')]);_0x507d92[_0xea7e('0x30')]=_['intersection'](_0x507d92['model'],_0x507d92[_0xea7e('0x2f')]);_0x18fd0f[_0xea7e('0x33')]=_[_0xea7e('0x31')](_0x507d92[_0xea7e('0x2d')],qs['fields'](_0x40093a['query'][_0xea7e('0x32')]));_0x18fd0f['attributes']=_0x18fd0f[_0xea7e('0x33')][_0xea7e('0x43')]?_0x18fd0f['attributes']:_0x507d92[_0xea7e('0x2d')];if(_0x40093a[_0xea7e('0x2f')]['includeAll']){_0x18fd0f[_0xea7e('0x3e')]=[{'all':!![]}];}_0x18fd0f=_[_0xea7e('0x39')]({},_0x18fd0f,_0x40093a['options']);return db['WhatsappApplication'][_0xea7e('0x44')](_0x18fd0f)[_0xea7e('0x24')](handleEntityNotFound(_0x44a501,null))['then'](respondWithResult(_0x44a501,null))[_0xea7e('0x41')](handleError(_0x44a501,null));};exports[_0xea7e('0x45')]=function(_0x4dd73b,_0x45901a){return db[_0xea7e('0x2a')][_0xea7e('0x45')](_0x4dd73b[_0xea7e('0x46')],{})[_0xea7e('0x24')](respondWithResult(_0x45901a,0xc9))[_0xea7e('0x41')](handleError(_0x45901a,null));};exports[_0xea7e('0x22')]=function(_0x593d13,_0x351a61){if(_0x593d13[_0xea7e('0x46')]['id']){delete _0x593d13[_0xea7e('0x46')]['id'];}return db[_0xea7e('0x2a')][_0xea7e('0x44')]({'where':{'id':_0x593d13[_0xea7e('0x47')]['id']}})['then'](handleEntityNotFound(_0x351a61,null))[_0xea7e('0x24')](saveUpdates(_0x593d13[_0xea7e('0x46')],null))[_0xea7e('0x24')](respondWithResult(_0x351a61,null))[_0xea7e('0x41')](handleError(_0x351a61,null));};exports[_0xea7e('0x23')]=function(_0x365b39,_0x5318b4){return db[_0xea7e('0x2a')][_0xea7e('0x44')]({'where':{'id':_0x365b39[_0xea7e('0x47')]['id']}})['then'](handleEntityNotFound(_0x5318b4,null))[_0xea7e('0x24')](removeEntity(_0x5318b4,null))[_0xea7e('0x41')](handleError(_0x5318b4,null));};