Feature parity with admins and users (also a minor backend change)

This commit is contained in:
augmentedpotato
2026-04-07 23:23:05 -06:00
parent ffef9243dd
commit 83477904be
3 changed files with 8 additions and 18 deletions

View File

@@ -50,7 +50,7 @@ public class AppointmentController {
.orElse(null); .orElse(null);
Long effectiveCustomerId = customerId; Long effectiveCustomerId = customerId;
if (role != null && role.equals("CUSTOMER")) { if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) {
User user = AuthenticationHelper.getAuthenticatedUser(userRepository); User user = AuthenticationHelper.getAuthenticatedUser(userRepository);
effectiveCustomerId = user.getId(); effectiveCustomerId = user.getId();
} }
@@ -88,7 +88,7 @@ public class AppointmentController {
.map(authority -> authority.getAuthority().replace("ROLE_", "")) .map(authority -> authority.getAuthority().replace("ROLE_", ""))
.orElse(null); .orElse(null);
if (role != null && role.equals("CUSTOMER")) { if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) {
User user = AuthenticationHelper.getAuthenticatedUser(userRepository); User user = AuthenticationHelper.getAuthenticatedUser(userRepository);
if (!request.getCustomerId().equals(user.getId())) { if (!request.getCustomerId().equals(user.getId())) {
throw new org.springframework.security.access.AccessDeniedException("You can only create appointments for yourself"); throw new org.springframework.security.access.AccessDeniedException("You can only create appointments for yourself");

View File

@@ -224,7 +224,7 @@ function AppointmentsPage() {
const [appointments, setAppointments] = useState([]); const [appointments, setAppointments] = useState([]);
const [loadingAppointments, setLoadingAppointments] = useState(false); const [loadingAppointments, setLoadingAppointments] = useState(false);
const canBookAppointments = user?.role === "CUSTOMER"; const canBookAppointments = user?.role === "CUSTOMER" || user?.role === "ADMIN";
useEffect(() => { useEffect(() => {
if (!authLoading && !user) { if (!authLoading && !user) {
@@ -410,12 +410,6 @@ function AppointmentsPage() {
return; return;
} }
if (!user?.customerId) {
setError("Customer account not found. Please contact support.");
return;
}
if (selectedPetIds.length === 0) { if (selectedPetIds.length === 0) {
setError(isAdoptionService ? "Please select a pet to adopt." : "Please select at least one pet."); setError(isAdoptionService ? "Please select a pet to adopt." : "Please select at least one pet.");
@@ -426,7 +420,7 @@ function AppointmentsPage() {
try { try {
const body = { const body = {
customerId: user.customerId, customerId: user.customerId || user.id,
storeId: Number(storeId), storeId: Number(storeId),
serviceId: Number(serviceId), serviceId: Number(serviceId),
employeeId: employeeId ? Number(employeeId) : undefined, employeeId: employeeId ? Number(employeeId) : undefined,
@@ -435,12 +429,8 @@ function AppointmentsPage() {
appointmentStatus: "Booked", appointmentStatus: "Booked",
}; };
if (isCustomerPetService) { if (selectedPetIds.length > 0) {
body.customerPetIds = selectedPetIds; body.petId = selectedPetIds[0];
}
else {
body.petIds = selectedPetIds;
} }
const res = await fetch(`${API_BASE}/api/v1/appointments`, { const res = await fetch(`${API_BASE}/api/v1/appointments`, {

View File

@@ -108,7 +108,7 @@ export default function ProfilePage() {
}, [clearPetImageObjectUrls]); }, [clearPetImageObjectUrls]);
useEffect(() => { useEffect(() => {
if (user?.role === "CUSTOMER") { if (user?.role === "CUSTOMER" || user?.role === "ADMIN") {
loadPets(); loadPets();
} }
}, [user, loadPets]); }, [user, loadPets]);
@@ -419,7 +419,7 @@ export default function ProfilePage() {
</button> </button>
</div> </div>
{user.role === "CUSTOMER" && ( {(user.role === "CUSTOMER" || user.role === "ADMIN") && (
<div className="profile-pets-section"> <div className="profile-pets-section">
<div className="profile-pets-header"> <div className="profile-pets-header">
<h2 className="profile-pets-title">My Pets</h2> <h2 className="profile-pets-title">My Pets</h2>