fix: khách mời join vào tour thông qua link mời
This commit is contained in:
Vendored
+10
-9
@@ -1419,9 +1419,17 @@ let TourController = class TourController {
|
|||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
||||||
this.cacheManager.del(`/api/v1/tours/explore`),
|
this.cacheManager.del(`/api/v1/tours/explore`),
|
||||||
|
this.cacheManager.del(`user-role:${userId}:${invitation.tourId}`),
|
||||||
]);
|
]);
|
||||||
return { success: true, tourId: invitation.tourId, message: 'Bạn đã là thành viên của tour này.' };
|
return { success: true, tourId: invitation.tourId, message: 'Bạn đã là thành viên của tour này.', shouldRefresh: true };
|
||||||
}
|
}
|
||||||
|
await Promise.all([
|
||||||
|
this.cacheManager.del(`user-role:${userId}:${invitation.tourId}`),
|
||||||
|
this.cacheManager.del(invitation.tourId),
|
||||||
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
||||||
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
||||||
|
this.cacheManager.del(`/api/v1/tours/explore`),
|
||||||
|
]);
|
||||||
await this.prisma.$transaction([
|
await this.prisma.$transaction([
|
||||||
this.prisma.tourParticipant.create({
|
this.prisma.tourParticipant.create({
|
||||||
data: {
|
data: {
|
||||||
@@ -1434,14 +1442,7 @@ let TourController = class TourController {
|
|||||||
where: { id: invitation.id }
|
where: { id: invitation.id }
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
await Promise.all([
|
return { success: true, tourId: invitation.tourId, message: `Bạn đã gia nhập hành trình "${invitation.tour.title}"!`, shouldRefresh: true };
|
||||||
this.cacheManager.del(invitation.tourId),
|
|
||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
|
||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
|
||||||
this.cacheManager.del(`/api/v1/tours/explore`),
|
|
||||||
this.cacheManager.del(`user-role:${userId}:${invitation.tourId}`),
|
|
||||||
]);
|
|
||||||
return { success: true, tourId: invitation.tourId, message: `Bạn đã gia nhập hành trình "${invitation.tour.title}"!` };
|
|
||||||
}
|
}
|
||||||
async mergeMember(tourId, body, req) {
|
async mergeMember(tourId, body, req) {
|
||||||
const { manualParticipantId, systemUserId } = body;
|
const { manualParticipantId, systemUserId } = body;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+12
-10
@@ -1585,10 +1585,20 @@ class TourController {
|
|||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
||||||
this.cacheManager.del(`/api/v1/tours/explore`),
|
this.cacheManager.del(`/api/v1/tours/explore`),
|
||||||
|
this.cacheManager.del(`user-role:${userId}:${invitation.tourId}`),
|
||||||
]);
|
]);
|
||||||
return { success: true, tourId: invitation.tourId, message: 'Bạn đã là thành viên của tour này.' };
|
return { success: true, tourId: invitation.tourId, message: 'Bạn đã là thành viên của tour này.', shouldRefresh: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Xóa cache TRƯỚC để đảm bảo không có race condition
|
||||||
|
await Promise.all([
|
||||||
|
this.cacheManager.del(`user-role:${userId}:${invitation.tourId}`),
|
||||||
|
this.cacheManager.del(invitation.tourId),
|
||||||
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
||||||
|
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
||||||
|
this.cacheManager.del(`/api/v1/tours/explore`),
|
||||||
|
]);
|
||||||
|
|
||||||
await this.prisma.$transaction([
|
await this.prisma.$transaction([
|
||||||
this.prisma.tourParticipant.create({
|
this.prisma.tourParticipant.create({
|
||||||
data: {
|
data: {
|
||||||
@@ -1602,15 +1612,7 @@ class TourController {
|
|||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await Promise.all([
|
return { success: true, tourId: invitation.tourId, message: `Bạn đã gia nhập hành trình "${invitation.tour.title}"!`, shouldRefresh: true };
|
||||||
this.cacheManager.del(invitation.tourId),
|
|
||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}`),
|
|
||||||
this.cacheManager.del(`/api/v1/tours/${invitation.tourId}/public`),
|
|
||||||
this.cacheManager.del(`/api/v1/tours/explore`),
|
|
||||||
this.cacheManager.del(`user-role:${userId}:${invitation.tourId}`),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return { success: true, tourId: invitation.tourId, message: `Bạn đã gia nhập hành trình "${invitation.tour.title}"!` };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Roles(ParticipantRole.OWNER, ParticipantRole.MANAGER)
|
@Roles(ParticipantRole.OWNER, ParticipantRole.MANAGER)
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ export const JoinTourPage: React.FC<JoinTourPageProps> = ({ onLoginSuccess, onGo
|
|||||||
|
|
||||||
setSuccessMsg(data.message || 'Bạn đã tham gia tour thành công!');
|
setSuccessMsg(data.message || 'Bạn đã tham gia tour thành công!');
|
||||||
setTourId(data.tourId);
|
setTourId(data.tourId);
|
||||||
|
// Đợi 500ms để đảm bảo các thay đổi cache ở backend hoàn tất trước khi tiếp tục
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
localStorage.removeItem('pendingInviteToken');
|
localStorage.removeItem('pendingInviteToken');
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError(err.message || 'Đã xảy ra lỗi.');
|
setError(err.message || 'Đã xảy ra lỗi.');
|
||||||
|
|||||||
@@ -51,9 +51,22 @@ export const useTourStore = create<TourState>((set, get) => ({
|
|||||||
fetchTour: async (id: string) => {
|
fetchTour: async (id: string) => {
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/v1/tours/${id}`, {
|
let response = await fetch(`/api/v1/tours/${id}`, {
|
||||||
headers: { 'Authorization': `Bearer ${token}` }
|
headers: { 'Authorization': `Bearer ${token}` }
|
||||||
});
|
});
|
||||||
|
// Thử lại một lần nếu gặp lỗi 403 hoặc 401 (có thể do cache vai trò cũ chưa được cập nhật)
|
||||||
|
if (response.status === 403 || response.status === 401) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
const retryResponse = await fetch(`/api/v1/tours/${id}`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Cache-Control': 'no-cache'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (retryResponse.ok) {
|
||||||
|
response = retryResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
// ...existing role detection...
|
// ...existing role detection...
|
||||||
|
|||||||
Reference in New Issue
Block a user