🚀 Advanced Web Server Manager
Complete File Manager & Terminal - Standalone Version
By Sid Gifari | Gifari Industries
Current path:
/
/
home
/
duzhbywe
/
Job-Portal
/
Services
/
job
✏️
Editing: index.js
import Cookies from "js-cookie"; // Post job API export const post_job = async (formData) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/postAJob`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${Cookies.get('token')}` }, body: JSON.stringify(formData), }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in post job (service) => ', error); return { success: false, message: 'Error posting job.' }; // Default error response } } // Get job API export const get_job = async () => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/getAllJobs`, { method: 'GET', headers : { 'Authorization': `Bearer ${Cookies.get('token')}` } }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in getting job (service) => ', error); return { success: false, message: 'Error getting jobs.' }; // Default error response } } // Get specified job API export const get_specified_job = async (id) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/getSpecifiedJob?id=${id}`, { method: 'GET', headers : {'Authorization': `Bearer ${Cookies.get('token')}`} }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in getting specified job (service) => ', error); return { success: false, message: 'Error getting specified job.' }; // Default error response } } // Apply job API export const apply_job = async (formData) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/applyJob`, { method: 'POST', headers: { 'Authorization': `Bearer ${Cookies.get('token')}`, }, body: formData, // FormData automatically sets the correct Content-Type }); if (!res.ok) { // Handle HTTP errors const errorResponse = await res.json(); return { success: false, message: errorResponse.message || 'Failed to apply for job.' }; } const data = await res.json(); return data; } catch (error) { console.log('Error in apply_job (service) => ', error); return { success: false, message: 'Error applying for job.' }; // Default error response } }; // Get my all applied jobs API export const get_my_applied_job = async (id) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/getAppliedJobs?id=${id}`, { method: 'GET', headers : {'Authorization': `Bearer ${Cookies.get('token')}`} }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in getting my all applied jobs (service) => ', error); return { success: false, message: 'Error getting applied jobs.' }; // Default error response } } // Get my all posted jobs API export const get_my_posted_job = async (id) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/getPostedJobs?id=${id}`, { method: 'GET', headers : {'Authorization': `Bearer ${Cookies.get('token')}`} }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in getting my all posted jobs (service) => ', error); return { success: false, message: 'Error getting posted jobs.' }; // Default error response } } // Get my all applications of specified job API export const get_all_applications = async (id) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/getAllApplicationsOfSpecifiedJob?id=${id}`, { method: 'GET', headers : {'Authorization': `Bearer ${Cookies.get('token')}`} }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in getting all applications of specified job (service) => ', error); return { success: false, message: 'Error getting applications.' }; // Default error response } } // Change application status API export const change_application_status = async (formData) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/responseOfApplication`, { method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${Cookies.get('token')}` }, body: JSON.stringify(formData), }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in changing application status (service) => ', error); return { success: false, message: 'Error changing application status.' }; // Default error response } } // Get application details API export const get_application_details = async (id) => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/job/getApplicationDetail?id=${id}`, { method: 'GET', headers : {'Authorization': `Bearer ${Cookies.get('token')}`} }); const data = await res.json(); // Added 'await' here return data; } catch (error) { console.log('error in getting application details (service) => ', error); return { success: false, message: 'Error getting application details.' }; // Default error response } }
💾 Save Changes
❌ Cancel