Initial commit for resumeformatter project

This commit is contained in:
Laxmi Khilnani
2025-10-14 19:51:35 +05:30
commit ee030b70bc
43 changed files with 1668 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import type { Person, NewPerson } from '../types';
// Get APP_NAME from environment or use default
const APP_NAME = import.meta.env.VITE_APP_NAME || 'ResumeFormatter';
const API_BASE_URL = `/${APP_NAME}/api`;
// Function to get all people
export const getPeople = async (): Promise<Person[]> => {
console.log('Fetching people from API...');
try {
const response = await fetch(`${API_BASE_URL}/people/`);
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
console.log('... Data loaded:', data);
return data;
} catch (error) {
console.error('Error fetching people:', error);
throw error;
}
};
// Function to add a new person
export const addPerson = async (newPerson: NewPerson): Promise<Person> => {
console.log('Adding person to API:', newPerson);
if (!newPerson.firstName || !newPerson.lastName || !newPerson.linkedinUrl) {
throw new Error('All fields are required.');
}
try {
const response = await fetch(`${API_BASE_URL}/people/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newPerson),
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
console.log('... Person added:', data);
return data;
} catch (error) {
console.error('Error adding person:', error);
throw error;
}
};