Sửa đổi dữ liệu của hệ thống theo ARCHITECTURE.md

This commit is contained in:
2026-06-13 19:52:08 +07:00
parent 7fc80a49d0
commit b54707823c
33 changed files with 655 additions and 275 deletions
+9 -9
View File
@@ -9,11 +9,11 @@ export class TourRoleGuard implements CanActivate {
const request = context.switchToHttp().getRequest();
const user = request.user; // Giả sử đã qua AuthGuard (Passport/JWT)
// Lấy tourId từ URL params (:id hoặc :tourId)
const tourId = parseInt(request.params.id || request.params.tourId);
// UUID không cần parseInt
const tourId = request.params.id || request.params.tourId;
const path = request.url;
if (!user || isNaN(tourId)) {
if (!user || !tourId) {
throw new ForbiddenException("Thông tin xác thực hoặc mã Tour không hợp lệ.");
}
@@ -22,7 +22,7 @@ export class TourRoleGuard implements CanActivate {
* Chúng ta lưu kết quả vào request object để các interceptor hoặc controller
* sau này có thể dùng lại mà không cần query lại.
*/
const membership = await this.prisma.tourMember.findUnique({
const participation = await this.prisma.tourParticipant.findUnique({
where: {
tourId_userId: {
tourId: tourId,
@@ -31,20 +31,20 @@ export class TourRoleGuard implements CanActivate {
},
});
if (!membership) {
if (!participation) {
throw new ForbiddenException("Bạn không phải là thành viên của tour này.");
}
// Gắn thông tin vào request để sử dụng ở tầng Controller
request.tourMembership = membership;
request.tourParticipation = participation;
const role = membership.role;
const role = participation.role;
const isPlanPath = path.includes('/plans');
const isExpensePath = path.includes('/expenses');
// 1. Chặn MEMBER_PHOTO_ONLY và VIEWER_EXTERNAL truy cập Plans & Expenses
// Theo định nghĩa mới: MEMBER_NO_FINANCE và VIEWER_ONLY bị hạn chế
if (
(role === 'MEMBER_PHOTO_ONLY' || role === 'VIEWER_EXTERNAL') &&
(role === 'MEMBER_NO_FINANCE' || role === 'VIEWER_ONLY') &&
(isPlanPath || isExpensePath)
) {
throw new ForbiddenException("Bạn không có quyền xem kế hoạch và chi phí của tour này.");