Thêm tính năng owner có thể thêm thành viên, member thêm thành viên sẽ pending

This commit is contained in:
2026-06-14 22:14:40 +07:00
parent 7cc724a133
commit c6341aa12f
16 changed files with 395 additions and 23 deletions
+21 -3
View File
@@ -342,7 +342,13 @@ let TourController = class TourController {
include: { user: { select: { id: true, name: true, email: true } } },
});
}
const currentRole = req.user.tourParticipation?.role;
let currentRole = req.user.tourParticipation?.role;
if (!currentRole) {
const participation = await this.prisma.tourParticipant.findUnique({
where: { tourId_userId: { tourId, userId: req.user.id } },
});
currentRole = participation?.role;
}
if (!currentRole || !(currentRole === 'OWNER' || currentRole === 'MANAGER')) {
const joinRequest = await this.prisma.joinRequest.create({
data: {
@@ -407,7 +413,13 @@ let TourController = class TourController {
return joinRequest;
}
async acceptJoinRequest(tourId, requestId, req) {
const role = req.user.tourParticipation?.role;
let role = req.user.tourParticipation?.role;
if (!role) {
const participation = await this.prisma.tourParticipant.findUnique({
where: { tourId_userId: { tourId, userId: req.user.id } },
});
role = participation?.role;
}
if (!role || !(role === 'OWNER' || role === 'MANAGER')) {
throw new ForbiddenException('Bạn không có quyền chấp nhận yêu cầu tham gia.');
}
@@ -446,7 +458,13 @@ let TourController = class TourController {
return { success: true, message: 'Đã chấp nhận yêu cầu tham gia.' };
}
async rejectJoinRequest(tourId, requestId, req) {
const role = req.user.tourParticipation?.role;
let role = req.user.tourParticipation?.role;
if (!role) {
const participation = await this.prisma.tourParticipant.findUnique({
where: { tourId_userId: { tourId, userId: req.user.id } },
});
role = participation?.role;
}
if (!role || !(role === 'OWNER' || role === 'MANAGER')) {
throw new ForbiddenException('Bạn không có quyền từ chối yêu cầu tham gia.');
}