added employeeService in a application

This commit is contained in:
Suraj Birewar 2024-08-05 22:03:32 +05:30
parent ccf3547404
commit c2c5ef0ff0
8 changed files with 116 additions and 13 deletions

17
db.json
View File

@ -106,6 +106,23 @@
"lastname": "shelke", "lastname": "shelke",
"email": "customer2@example.com", "email": "customer2@example.com",
"phone": "0987654321" "phone": "0987654321"
},
{
"id": "7779",
"firstname": "Suraj",
"lastname": "Birewar",
"age": "22",
"gender": "male",
"email": "surajbirewar001@gmail.com",
"mobile": "07559393995",
"address": {
"address_line_1": "Bavdhan, Pune",
"address_line_2": "LOCAL :,Bavdhan",
"nearby_landmark": "sbi",
"pincode": "411021",
"city_id": "1"
},
"image": null
} }
], ],
"cities": [ "cities": [

View File

@ -4,6 +4,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronLeft } from '@fortawesome/free-solid-svg-icons'; import { faChevronLeft } from '@fortawesome/free-solid-svg-icons';
import Sidebar from '../sidebar/Sidebar'; import Sidebar from '../sidebar/Sidebar';
import axiosInstance from '../../api/axiosConfig'; import axiosInstance from '../../api/axiosConfig';
import { createEmployee } from "../../services_1/employeeService";
const CLASSES = { const CLASSES = {
container: 'flex flex-row', container: 'flex flex-row',

View File

@ -4,7 +4,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronLeft } from '@fortawesome/free-solid-svg-icons'; import { faChevronLeft } from '@fortawesome/free-solid-svg-icons';
import Sidebar from '../sidebar/Sidebar'; import Sidebar from '../sidebar/Sidebar';
import axiosInstance from '../../api/axiosConfig'; import axiosInstance from '../../api/axiosConfig';
import { addCustomer } from "../../services_1/customersService"; import { createCustomer } from "../../services_1/customersService";
const CLASSES = { const CLASSES = {
container: 'flex flex-row', container: 'flex flex-row',
mainContent: 'w-full flex flex-col min-h-screen text-black', mainContent: 'w-full flex flex-col min-h-screen text-black',
@ -124,7 +124,7 @@ const AddCustomer = () => {
} }
try { try {
const data = await customerService.createCustomer(customerData); const data = await createCustomer(customerData);
console.log('Customer added successfully:', data); console.log('Customer added successfully:', data);
navigate('/customers'); navigate('/customers');
} catch (error) { } catch (error) {

View File

@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
import Sidebar from '../sidebar/Sidebar'; import Sidebar from '../sidebar/Sidebar';
import axiosInstance from '../../api/axiosConfig'; import axiosInstance from '../../api/axiosConfig';
import '../../styles/CustomerList.css'; import '../../styles/CustomerList.css';
import { getCustomers, addCustomer } from '@/services_1/customersService'; import {getAllCustomers} from '../../services_1/customersService'
@ -17,7 +17,7 @@ const CustomerList = () => {
const getCustomers = async () => { const getCustomers = async () => {
try { try {
const data = await customerService.getAllCustomers() const data = await getAllCustomers()
setCustomers(data); setCustomers(data);
} catch (error) { } catch (error) {
throw error; throw error;

View File

@ -42,6 +42,8 @@ const Customize = () => {
material, material,
}; };
navigate('/setmeasurements');
fetch('/api/saveCustomization', { fetch('/api/saveCustomization', {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -50,7 +50,7 @@ const EmployeeSidebar = () => {
<Link to="/order" className={classNames.iconLink}> <Link to="/order" className={classNames.iconLink}>
<img src={OrdersIcon} alt="Orders" className={classNames.icon} /> <img src={OrdersIcon} alt="Orders" className={classNames.icon} />
</Link> </Link>
<Link to="/setmeasurements" className={classNames.iconLink}> <Link to="/profile" className={classNames.iconLink}>
<img src={ProfileIcon} alt="Profile" className={classNames.icon} /> <img src={ProfileIcon} alt="Profile" className={classNames.icon} />
</Link> </Link>
</div> </div>

View File

@ -10,14 +10,6 @@ export const getAllCustomers = async () => {
} }
}; };
export const getCustomers = async () => {
// Implementation
};
export const addCustomer = async (customer) => {
// Implementation
};
// Create a new customer // Create a new customer
export const createCustomer = async (customerPayload) => { export const createCustomer = async (customerPayload) => {
try { try {

View File

@ -0,0 +1,91 @@
import axiosInstance from "../api/axiosConfig";
// Get all employees
export const getAllEmployees = async () => {
try {
const response = await axiosInstance.get("/employees");
return response.data;
} catch (error) {
throw error; // The error is handled globally by the axiosInstance
}
};
// Create a new employee
export const createEmployee = async (employeePayload) => {
try {
const response = await axiosInstance.post("/employees", employeePayload);
return response.data;
} catch (error) {
throw error; // The error is handled globally by the axiosInstance
}
};
// Get an employee by ID
export const getEmployeeById = async (id) => {
try {
const response = await axiosInstance.get(`/employees/${id}`);
return response.data;
} catch (error) {
throw error; // The error is handled globally by the axiosInstance
}
};
// Update an employee's details
export const updateEmployee = async (id, employeePayload) => {
try {
const response = await axiosInstance.patch(
`/employees/${id}`,
employeePayload
);
return response.data;
} catch (error) {
throw error; // The error is handled globally by the axiosInstance
}
};
// Delete an employee
export const deleteEmployee = async (id) => {
try {
await axiosInstance.delete(`/employees/${id}`);
return; // No content to return on successful delete
} catch (error) {
throw error; // The error is handled globally by the axiosInstance
}
};
// Example function to use the employee service
export const exampleEmployeeUsage = async () => {
try {
// Example: Get all employees
const employees = await getAllEmployees();
console.log("Employees:", employees);
// Example: Create a new employee
const newEmployee = {
name: "John Doe",
email: "john.doe@example.com",
position: "Software Engineer",
};
const createdEmployee = await createEmployee(newEmployee);
console.log("Created Employee:", createdEmployee);
// Example: Get an employee by ID
const employeeId = "123";
const employee = await getEmployeeById(employeeId);
console.log("Employee by ID:", employee);
// Example: Update an employee
const updatedEmployeePayload = { position: "Senior Software Engineer" };
const updatedEmployee = await updateEmployee(
employeeId,
updatedEmployeePayload
);
console.log("Updated Employee:", updatedEmployee);
// Example: Delete an employee
await deleteEmployee(employeeId);
console.log("Employee deleted successfully");
} catch (error) {
console.error("Error occurred while using employees service:", error);
}
};