Sửa đổi dữ liệu của hệ thống theo ARCHITECTURE.md
This commit is contained in:
+8
-7
@@ -8,7 +8,7 @@ interface TourState {
|
||||
setTour: (tour: any) => void;
|
||||
updateLegs: (legs: any[]) => void;
|
||||
optimizeRouting: () => Promise<void>;
|
||||
fetchTour: (id: number) => Promise<void>;
|
||||
fetchTour: (id: string) => Promise<void>;
|
||||
fetchPublicTours: () => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -19,17 +19,18 @@ export const useTourStore = create<TourState>((set, get) => ({
|
||||
userRole: null,
|
||||
setTour: (tour) => set({ currentTour: tour }),
|
||||
updateLegs: (legs) => set({ legs }),
|
||||
fetchTour: async (id: number) => {
|
||||
// Giả sử user hiện tại có ID là 1 (Lộc Phạm - OWNER) để test
|
||||
const currentUserId = 1;
|
||||
const response = await fetch(`http://localhost:3001/api/v1/tours/${id}`);
|
||||
fetchTour: async (id: string) => {
|
||||
const API_BASE = `http://${window.location.hostname}:3001`;
|
||||
const response = await fetch(`${API_BASE}/api/v1/tours/${id}`);
|
||||
const data = await response.json();
|
||||
|
||||
const role = data.members?.find((m: any) => m.userId === currentUserId)?.role || 'VIEWER_EXTERNAL';
|
||||
// Lấy role từ danh sách participants (dữ liệu mẫu từ seed)
|
||||
const role = data.participants?.[0]?.role || 'VIEWER_ONLY';
|
||||
set({ currentTour: data, legs: data.legs || [], userRole: role });
|
||||
},
|
||||
fetchPublicTours: async () => {
|
||||
const response = await fetch(`http://localhost:3001/api/v1/tours/explore`);
|
||||
const API_BASE = `http://${window.location.hostname}:3001`;
|
||||
const response = await fetch(`${API_BASE}/api/v1/tours/explore`);
|
||||
const data = await response.json();
|
||||
set({ publicTours: data });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user