| import { Request, Response } from 'express'; |
| import axios from 'axios'; |
|
|
| const SACHET_BASE_URL = 'https://sachet.ndma.gov.in/cap_public_website'; |
|
|
| |
| |
| |
| export const fetchEarthquakeAlerts = async (req: Request, res: Response): Promise<Response> => { |
| try { |
| const response = await axios.get(`${SACHET_BASE_URL}/FetchEarthquakeAlerts`, { |
| timeout: 10000, |
| headers: { |
| 'Accept': 'application/json', |
| 'User-Agent': 'Prashikshak-Backend/1.0' |
| } |
| }); |
|
|
| return res.status(200).json({ |
| success: true, |
| data: response.data |
| }); |
| } catch (error: any) { |
| console.error('Error fetching earthquake alerts:', error.message); |
| return res.status(error.response?.status || 500).json({ |
| success: false, |
| message: 'Failed to fetch earthquake alerts', |
| error: error.message |
| }); |
| } |
| }; |
|
|
| |
| |
| |
| export const fetchNowcastAlerts = async (req: Request, res: Response): Promise<Response> => { |
| try { |
| const response = await axios.get(`${SACHET_BASE_URL}/FetchIMDNowcastAlerts`, { |
| timeout: 10000, |
| headers: { |
| 'Accept': 'application/json', |
| 'User-Agent': 'Prashikshak-Backend/1.0' |
| } |
| }); |
|
|
| return res.status(200).json({ |
| success: true, |
| data: response.data |
| }); |
| } catch (error: any) { |
| console.error('Error fetching nowcast alerts:', error.message); |
| return res.status(error.response?.status || 500).json({ |
| success: false, |
| message: 'Failed to fetch nowcast alerts', |
| error: error.message |
| }); |
| } |
| }; |
|
|
| |
| |
| |
| export const fetchAllAlertDetails = async (req: Request, res: Response): Promise<Response> => { |
| try { |
| const response = await axios.get(`${SACHET_BASE_URL}/FetchAllAlertDetails`, { |
| timeout: 10000, |
| headers: { |
| 'Accept': 'application/json', |
| 'User-Agent': 'Prashikshak-Backend/1.0' |
| } |
| }); |
|
|
| return res.status(200).json({ |
| success: true, |
| data: response.data |
| }); |
| } catch (error: any) { |
| console.error('Error fetching all alert details:', error.message); |
| return res.status(error.response?.status || 500).json({ |
| success: false, |
| message: 'Failed to fetch all alert details', |
| error: error.message |
| }); |
| } |
| }; |
|
|
| |
| |
| |
| export const fetchStatewiseFilter = async (req: Request, res: Response): Promise<Response> => { |
| try { |
| const response = await axios.get(`${SACHET_BASE_URL}/../locales/en/statewiseFilter.json`, { |
| timeout: 10000, |
| headers: { |
| 'Accept': 'application/json', |
| 'User-Agent': 'Prashikshak-Backend/1.0' |
| } |
| }); |
|
|
| return res.status(200).json({ |
| success: true, |
| data: response.data |
| }); |
| } catch (error: any) { |
| console.error('Error fetching statewise filter:', error.message); |
| return res.status(error.response?.status || 500).json({ |
| success: false, |
| message: 'Failed to fetch statewise filter', |
| error: error.message |
| }); |
| } |
| }; |
|
|
| |
| |
| |
| export const fetchAllAlerts = async (req: Request, res: Response): Promise<Response> => { |
| try { |
| const [earthquakeRes, nowcastRes, generalRes] = await Promise.all([ |
| axios.get(`${SACHET_BASE_URL}/FetchEarthquakeAlerts`, { |
| timeout: 10000, |
| headers: { 'Accept': 'application/json', 'User-Agent': 'Prashikshak-Backend/1.0' } |
| }), |
| axios.get(`${SACHET_BASE_URL}/FetchIMDNowcastAlerts`, { |
| timeout: 10000, |
| headers: { 'Accept': 'application/json', 'User-Agent': 'Prashikshak-Backend/1.0' } |
| }), |
| axios.get(`${SACHET_BASE_URL}/FetchAllAlertDetails`, { |
| timeout: 10000, |
| headers: { 'Accept': 'application/json', 'User-Agent': 'Prashikshak-Backend/1.0' } |
| }) |
| ]); |
|
|
| return res.status(200).json({ |
| success: true, |
| data: { |
| earthquakes: earthquakeRes.data, |
| nowcast: nowcastRes.data, |
| general: generalRes.data |
| } |
| }); |
| } catch (error: any) { |
| console.error('Error fetching all alerts:', error.message); |
| return res.status(error.response?.status || 500).json({ |
| success: false, |
| message: 'Failed to fetch all alerts', |
| error: error.message |
| }); |
| } |
| }; |
|
|