44});
45} catch (error) {
46console.error("Error fetching policy acceptance:", error);
47return c.json({ error: "Failed to fetch policy acceptance status" }, 500);
48}
49});
33return c.json({ children });
34} catch (error) {
35console.error("Error fetching children:", error);
36return c.json({ error: "Failed to fetch children" }, 500);
37}
38});
46return c.json({ children });
47} catch (error) {
48console.error("Error fetching children:", error);
49return c.json({ error: "Failed to fetch children" }, 500);
50}
51});
74return c.json({ child });
75} catch (error) {
76console.error("Error fetching child:", error);
77return c.json({ error: "Failed to fetch child" }, 500);
78}
79});
1/**
2* Cron job to fetch emails from dealflow application
3* Runs every 60 minutes
4*/
5export default async function() {
6try {
7const response = await fetch("https://dealflow-pearl.vercel.app/fetch-emails", {
8method: "GET",
9});
1011if (!response.ok) {
12throw new Error(`Failed to fetch emails: ${response.status} ${response.statusText}`);
13}
1415const result = await response.text();
16console.log("Successfully fetched emails:", result);
17return { success: true, message: "Emails fetched successfully" };
18} catch (error) {
19console.error("Error fetching emails:", error);
20return { success: false, error: error.message };
21}
17// State
18let username = localStorage.getItem('username') || '';
19let lastChatFetch = 0;
20let chatPollingInterval;
213334// Load initial data
35fetchJobs();
36fetchChatMessages();
3738// Set up event listeners
80}
8182// Fetch jobs from the API
83async function fetchJobs() {
84try {
85jobsContainer.innerHTML = '<p class="text-center py-4"><span class="loading-spinner mr-2"></span>Loading jobs...</p>';
86
87const response = await fetch('/api/jobs');
88const data = await response.json();
89
90if (!data.success) {
91throw new Error(data.error || 'Failed to fetch jobs');
92}
93
94displayJobs(data.data);
95} catch (error) {
96console.error('Error fetching jobs:', error);
97jobsContainer.innerHTML = `
98<div class="text-center py-8 text-red-600">
99<p>Failed to load job listings</p>
100<button class="mt-2 px-4 py-2 bg-blue-600 text-white rounded" onclick="fetchJobs()">
101Try Again
102</button>
149jobModal.classList.remove('hidden');
150
151const response = await fetch(`/api/jobs/${jobId}`);
152const data = await response.json();
153
154if (!data.success) {
155throw new Error(data.error || 'Failed to fetch job details');
156}
157
183`;
184} catch (error) {
185console.error('Error fetching job details:', error);
186modalContent.innerHTML = `
187<div class="text-center py-4 text-red-600">
210submitBtn.disabled = true;
211
212const response = await fetch('/api/jobs', {
213method: 'POST',
214headers: {
229
230// Refresh job listings
231fetchJobs();
232
233// Post a chat message about the new job
238};
239
240await fetch('/api/chat', {
241method: 'POST',
242headers: {
246});
247
248fetchChatMessages();
249}
250} catch (error) {
260// Start polling for chat messages
261function startChatPolling() {
262// Initial fetch
263fetchChatMessages();
264
265// Set up polling interval (every 5 seconds)
266chatPollingInterval = setInterval(fetchChatMessages, 5000);
267}
268269// Fetch chat messages
270async function fetchChatMessages() {
271try {
272const response = await fetch('/api/chat');
273const data = await response.json();
274
275if (!data.success) {
276throw new Error(data.error || 'Failed to fetch chat messages');
277}
278
279displayChatMessages(data.data);
280lastChatFetch = Date.now();
281} catch (error) {
282console.error('Error fetching chat messages:', error);
283if (chatMessages.children.length === 0 || chatMessages.innerHTML.includes('Loading')) {
284chatMessages.innerHTML = `
285<div class="text-center py-4 text-red-600">
286<p>Failed to load chat messages</p>
287<button class="mt-2 px-4 py-2 bg-blue-600 text-white rounded" onclick="fetchChatMessages()">
288Try Again
289</button>
345
346try {
347const response = await fetch('/api/chat', {
348method: 'POST',
349headers: {
365chatInput.value = '';
366
367// Fetch latest messages
368fetchChatMessages();
369} catch (error) {
370console.error('Error sending message:', error);
17return c.json({ success: true, data: messages.reverse() });
18} catch (error) {
19console.error("Error fetching chat messages:", error);
20return c.json({ success: false, error: "Failed to fetch chat messages" }, 500);
21}
22});
15return c.json({ success: true, data: jobPostings });
16} catch (error) {
17console.error("Error fetching jobs:", error);
18return c.json({ success: false, error: "Failed to fetch job postings" }, 500);
19}
20});
35return c.json({ success: true, data: job });
36} catch (error) {
37console.error("Error fetching job:", error);
38return c.json({ success: false, error: "Failed to fetch job posting" }, 500);
39}
40});
22const [loading, setLoading] = useState(false);
2324// Fetch tutorials with current filter
25const fetchTutorials = async () => {
26setLoading(true);
27try {
28const response = await fetch("/api/tutorials/filter", {
29method: "POST",
30headers: { "Content-Type": "application/json" },
37}
38} catch (error) {
39console.error("Error fetching tutorials:", error);
40} finally {
41setLoading(false);
45// Apply filter changes
46useEffect(() => {
47fetchTutorials();
48}, [filter]);
4951const handleAddTutorial = async (tutorial: any) => {
52try {
53const response = await fetch("/api/tutorials", {
54method: "POST",
55headers: { "Content-Type": "application/json" },
59if (response.ok) {
60setIsAddingTutorial(false);
61fetchTutorials();
62}
63} catch (error) {
69const handleUpdateProgress = async (tutorialId: number, status: 'not_started' | 'in_progress' | 'completed', teamMemberId?: number, notes?: string, progress?: number) => {
70try {
71await fetch(`/api/tutorials/${tutorialId}/progress`, {
72method: "POST",
73headers: { "Content-Type": "application/json" },
75});
76
77fetchTutorials();
78} catch (error) {
79console.error("Error updating progress:", error);
86
87try {
88const response = await fetch("/api/team-members", {
89method: "POST",
90headers: { "Content-Type": "application/json" },
Weather-Mapindex.html7 matches
199
200// Use Nominatim API to search for the location
201const response = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}&limit=1`);
202
203if (!response.ok) {
226map.setView([lat, lon], 10);
227
228// Trigger weather data fetch for this location
229map.fireEvent('click', { latlng: L.latLng(lat, lon) });
230
339}
340
341// Handle map clicks to fetch and display weather data
342let currentMarker = null;
343
352document.getElementById('weather-container').classList.add('hidden');
353
354// Fetch weather data from our API
355const response = await fetch(`/api/weather/${lat}/${lon}`);
356if (!response.ok) {
357throw new Error('Failed to fetch weather data');
358}
359
469} catch (error) {
470console.error('Error:', error);
471document.getElementById('weather-placeholder').innerHTML = 'Error fetching weather data. Please try again.';
472document.getElementById('weather-container').classList.add('hidden');
473document.getElementById('weather-placeholder').classList.remove('hidden');