feat: implement full-stack ratings system for appointments with user submission and pending ratings dashboard integration

This commit is contained in:
2026-07-21 23:49:16 -03:00
parent b26c3e58d1
commit 383a5bc6b4
17 changed files with 1505 additions and 20 deletions
+22 -18
View File
@@ -3,6 +3,26 @@ import { ApiError } from "@models/Server.Error.model";
import axios from "@config/axios.config";
class ApiService {
private normalizeError(error: unknown): ApiError {
if (error && typeof error === "object" && "response" in error) {
const response = (error as { response?: { data?: any; status?: number } }).response;
const data = response?.data;
if (data) {
const msg = data.desc || data.message || JSON.stringify(data.details || data) || "No pudimos completar la operación.";
return new ApiError(data.code || response?.status || 500, msg);
}
return new ApiError(response?.status || 500, "No pudimos comunicarnos con el servidor.");
}
if (error instanceof Error) {
return new ApiError(500, error.message);
}
return new ApiError(500, "No pudimos comunicarnos con el servidor.");
}
/**
* Sends a HTTP POST request to the specified endpoint with the provided data
* and returns a promise that resolves to the response data.
@@ -19,14 +39,7 @@ class ApiService {
resolve(response.data);
})
.catch((error) => {
try {
const data = error.response.data;
const msg = data.desc || data.message || JSON.stringify(data.details || data);
reject(new ApiError(data.code || error.response.status || 500, msg));
} catch {
const errorMessage = process.env.VITE_API_UNAVAILABLE as string;
reject(new ApiError(500, errorMessage));
}
reject(this.normalizeError(error));
});
});
}
@@ -44,16 +57,7 @@ class ApiService {
resolve(response.data);
})
.catch((error) => {
try {
console.error("Full API Error:", error.response?.data);
const data = error.response.data;
const msg = data.desc || data.message || JSON.stringify(data.details || data);
reject(new ApiError(data.code || error.response.status || 500, msg));
} catch (e) {
console.error(e);
const errorMessage = process.env.VITE_API_UNAVAILABLE as string;
reject(new ApiError(500, errorMessage));
}
reject(this.normalizeError(error));
});
});
}