Sửa lỗi nhấn + để thêm thành viên của tour

This commit is contained in:
2026-06-14 17:16:19 +07:00
parent c6d0fdd5d1
commit 81e715ddb3
24 changed files with 515 additions and 239 deletions
+45 -4
View File
@@ -12,7 +12,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
};
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { Module, Controller, Get, Post, Body, Param, Patch, Delete, ParseUUIDPipe, NotFoundException, BadRequestException, UnauthorizedException, UseGuards, Req } from '@nestjs/common';
import { Module, Controller, Get, Post, Body, Param, Patch, Delete, ParseUUIDPipe, NotFoundException, BadRequestException, UnauthorizedException, UseGuards, Req, Query } from '@nestjs/common';
import { PrismaService } from './prisma.service.js';
import 'dotenv/config';
import * as bcrypt from 'bcrypt';
@@ -325,6 +325,28 @@ let TourController = class TourController {
throw new NotFoundException(`Không tìm thấy Tour với ID ${id}`);
return tour;
}
async addMember(tourId, body, req) {
const validRoles = ['OWNER', 'MANAGER', 'MEMBER', 'MEMBER_NO_FINANCE', 'VIEWER_ONLY'];
const role = validRoles.includes(body.role) ? body.role : 'MEMBER';
const participation = await this.prisma.tourParticipant.findUnique({
where: { tourId_userId: { tourId, userId: body.userId } },
});
if (participation) {
return this.prisma.tourParticipant.update({
where: { tourId_userId: { tourId, userId: body.userId } },
data: { role },
include: { user: { select: { id: true, name: true, email: true } } },
});
}
return this.prisma.tourParticipant.create({
data: {
tourId,
userId: body.userId,
role,
},
include: { user: { select: { id: true, name: true, email: true } } },
});
}
};
__decorate([
UseGuards(JwtAuthGuard),
@@ -416,6 +438,16 @@ __decorate([
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TourController.prototype, "getTourDetails", null);
__decorate([
UseGuards(JwtAuthGuard, TourRoleGuard),
Post(':tourId/members'),
__param(0, Param('tourId', ParseUUIDPipe)),
__param(1, Body()),
__param(2, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", Promise)
], TourController.prototype, "addMember", null);
TourController = __decorate([
Controller('v1/tours'),
__metadata("design:paramtypes", [PrismaService])
@@ -639,9 +671,17 @@ let UserController = class UserController {
constructor(prisma) {
this.prisma = prisma;
}
async getAllUsers() {
async getAllUsers(q) {
return this.prisma.user.findMany({
select: { id: true, email: true, name: true, isAdmin: true, isBlocked: true, createdAt: true }
where: q
? {
OR: [
{ name: { contains: q, mode: 'insensitive' } },
{ email: { contains: q, mode: 'insensitive' } },
],
}
: undefined,
select: { id: true, email: true, name: true, isAdmin: true, isBlocked: true, createdAt: true, phone: true, address: true }
});
}
async updateUser(id, data) {
@@ -677,8 +717,9 @@ let UserController = class UserController {
};
__decorate([
Get(),
__param(0, Query('q')),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], UserController.prototype, "getAllUsers", null);
__decorate([