Feature parity with admins and users (also a minor backend change)
This commit is contained in:
@@ -50,7 +50,7 @@ public class AppointmentController {
|
||||
.orElse(null);
|
||||
|
||||
Long effectiveCustomerId = customerId;
|
||||
if (role != null && role.equals("CUSTOMER")) {
|
||||
if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) {
|
||||
User user = AuthenticationHelper.getAuthenticatedUser(userRepository);
|
||||
effectiveCustomerId = user.getId();
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class AppointmentController {
|
||||
.map(authority -> authority.getAuthority().replace("ROLE_", ""))
|
||||
.orElse(null);
|
||||
|
||||
if (role != null && role.equals("CUSTOMER")) {
|
||||
if (role != null && (role.equals("CUSTOMER") || role.equals("ADMIN"))) {
|
||||
User user = AuthenticationHelper.getAuthenticatedUser(userRepository);
|
||||
if (!request.getCustomerId().equals(user.getId())) {
|
||||
throw new org.springframework.security.access.AccessDeniedException("You can only create appointments for yourself");
|
||||
|
||||
@@ -224,7 +224,7 @@ function AppointmentsPage() {
|
||||
const [appointments, setAppointments] = useState([]);
|
||||
const [loadingAppointments, setLoadingAppointments] = useState(false);
|
||||
|
||||
const canBookAppointments = user?.role === "CUSTOMER";
|
||||
const canBookAppointments = user?.role === "CUSTOMER" || user?.role === "ADMIN";
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !user) {
|
||||
@@ -410,12 +410,6 @@ function AppointmentsPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user?.customerId) {
|
||||
setError("Customer account not found. Please contact support.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedPetIds.length === 0) {
|
||||
setError(isAdoptionService ? "Please select a pet to adopt." : "Please select at least one pet.");
|
||||
|
||||
@@ -426,7 +420,7 @@ function AppointmentsPage() {
|
||||
|
||||
try {
|
||||
const body = {
|
||||
customerId: user.customerId,
|
||||
customerId: user.customerId || user.id,
|
||||
storeId: Number(storeId),
|
||||
serviceId: Number(serviceId),
|
||||
employeeId: employeeId ? Number(employeeId) : undefined,
|
||||
@@ -435,12 +429,8 @@ function AppointmentsPage() {
|
||||
appointmentStatus: "Booked",
|
||||
};
|
||||
|
||||
if (isCustomerPetService) {
|
||||
body.customerPetIds = selectedPetIds;
|
||||
}
|
||||
|
||||
else {
|
||||
body.petIds = selectedPetIds;
|
||||
if (selectedPetIds.length > 0) {
|
||||
body.petId = selectedPetIds[0];
|
||||
}
|
||||
|
||||
const res = await fetch(`${API_BASE}/api/v1/appointments`, {
|
||||
|
||||
@@ -108,7 +108,7 @@ export default function ProfilePage() {
|
||||
}, [clearPetImageObjectUrls]);
|
||||
|
||||
useEffect(() => {
|
||||
if (user?.role === "CUSTOMER") {
|
||||
if (user?.role === "CUSTOMER" || user?.role === "ADMIN") {
|
||||
loadPets();
|
||||
}
|
||||
}, [user, loadPets]);
|
||||
@@ -419,7 +419,7 @@ export default function ProfilePage() {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{user.role === "CUSTOMER" && (
|
||||
{(user.role === "CUSTOMER" || user.role === "ADMIN") && (
|
||||
<div className="profile-pets-section">
|
||||
<div className="profile-pets-header">
|
||||
<h2 className="profile-pets-title">My Pets</h2>
|
||||
|
||||
Reference in New Issue
Block a user