Fix: UserManagement brak nazw (name w db.json), ProfileView hardcoded Anna (resolver pobiera dane po id)
This commit is contained in:
8
db.json
8
db.json
@@ -2,30 +2,38 @@
|
||||
"users": [
|
||||
{
|
||||
"id": "u1",
|
||||
"name": "Admin User",
|
||||
"email": "admin@reservations.dev",
|
||||
"password": "Admin1234!",
|
||||
"role": "admin",
|
||||
"joinedAt": "2023-06-01",
|
||||
"avatarUrl": "https://i.pravatar.cc/150?u=admin"
|
||||
},
|
||||
{
|
||||
"id": "u2",
|
||||
"name": "Anna Kowalski",
|
||||
"email": "anna.kowalski@example.com",
|
||||
"password": "Client1234!",
|
||||
"role": "client",
|
||||
"joinedAt": "2024-01-15",
|
||||
"avatarUrl": "https://i.pravatar.cc/150?u=anna"
|
||||
},
|
||||
{
|
||||
"id": "u3",
|
||||
"name": "Marek Nowak",
|
||||
"email": "marek.nowak@example.com",
|
||||
"password": "Client1234!",
|
||||
"role": "client",
|
||||
"joinedAt": "2024-02-20",
|
||||
"avatarUrl": "https://i.pravatar.cc/150?u=marek"
|
||||
},
|
||||
{
|
||||
"id": "u4",
|
||||
"name": "Julia Wisniewska",
|
||||
"email": "julia.wisniewska@example.com",
|
||||
"password": "Client1234!",
|
||||
"role": "client",
|
||||
"joinedAt": "2024-03-10",
|
||||
"avatarUrl": "https://i.pravatar.cc/150?u=julia"
|
||||
}
|
||||
],
|
||||
|
||||
27
src/main.jsx
27
src/main.jsx
@@ -17,6 +17,7 @@ import { SchemaLink } from '@apollo/client/link/schema';
|
||||
import { makeExecutableSchema } from '@graphql-tools/schema';
|
||||
// Importowanie głównego komponentu aplikacji
|
||||
import App from './App.jsx';
|
||||
import { API_URL } from './config.js';
|
||||
|
||||
// Instancja z konfiguracją react-query
|
||||
const queryClient = new QueryClient({
|
||||
@@ -84,16 +85,22 @@ const apolloClient = new ApolloClient({
|
||||
resolvers: {
|
||||
// Logika resolverów dla zapytań i mutacji GraphQL
|
||||
Query: {
|
||||
// Jeśli fronted pyta o profil użytkownika, zwracamy dane zdefiniowane w kodzie oraz url awatara
|
||||
userProfile: (_, { id }) => ({
|
||||
id,
|
||||
name: 'Anna Kowalski',
|
||||
email: 'anna.kowalski@example.com',
|
||||
role: 'client',
|
||||
joinedAt: '2024-01-15',
|
||||
reservationsCount: 3,
|
||||
avatarUrl: `https://i.pravatar.cc/150?u=${id}`,
|
||||
}),
|
||||
// Pobiera profil użytkownika z REST API po id, liczy jego rezerwacje
|
||||
userProfile: async (_, { id }) => {
|
||||
const [u, reservations] = await Promise.all([
|
||||
fetch(`${API_URL}/users/${id}`).then((r) => r.json()),
|
||||
fetch(`${API_URL}/reservations?userId=${id}`).then((r) => r.json()),
|
||||
]);
|
||||
return {
|
||||
id: u.id,
|
||||
name: u.name ?? u.email.split('@')[0],
|
||||
email: u.email,
|
||||
role: u.role,
|
||||
joinedAt: u.joinedAt ?? '2024-01-15',
|
||||
reservationsCount: reservations.length,
|
||||
avatarUrl: u.avatarUrl,
|
||||
};
|
||||
},
|
||||
// Jeśli fronted pyta o recenzje dla danego serwisu, filtrujemy recenzje w pamięci według serviceId
|
||||
serviceReviews: (_, { serviceId }) => reviewStore.filter((r) => r.serviceId === serviceId),
|
||||
// Jeśli fronted pyta o recenzje danego użytkownika, filtrujemy recenzje w pamięci według userId
|
||||
|
||||
Reference in New Issue
Block a user