fix: sửa lỗi các nút bị che dưới thanh địa chỉ của chrome, hỗ trợ iphone upload ảnh heic
This commit is contained in:
Vendored
+31
-7
@@ -1695,7 +1695,7 @@ let UserController = class UserController {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async getAllUsers(req, q) {
|
||||
const currentUserId = req.user?.sub;
|
||||
const currentUserId = req.user?.id;
|
||||
const users = await this.prisma.user.findMany({
|
||||
where: q
|
||||
? {
|
||||
@@ -1718,18 +1718,32 @@ let UserController = class UserController {
|
||||
orderBy: { capturedAt: 'desc' }
|
||||
});
|
||||
}
|
||||
async updateUser(id, data) {
|
||||
async updateUser(id, data, req) {
|
||||
const requestingUser = req.user;
|
||||
const targetUser = await this.prisma.user.findUnique({ where: { id } });
|
||||
if (!targetUser) {
|
||||
throw new common_1.NotFoundException('Không tìm thấy người dùng');
|
||||
}
|
||||
if (targetUser.isAdmin && !requestingUser.isAdmin) {
|
||||
throw new common_1.ForbiddenException('Không có quyền thay đổi thông tin hoặc reset password của Quản trị viên');
|
||||
}
|
||||
if (!requestingUser.isAdmin && requestingUser.id !== id) {
|
||||
throw new common_1.ForbiddenException('Bạn không có quyền thực hiện hành động này');
|
||||
}
|
||||
if (data.password) {
|
||||
data.passwordHash = await bcrypt.hash(data.password, 10);
|
||||
delete data.password;
|
||||
}
|
||||
if (!requestingUser.isAdmin && data.isAdmin !== undefined) {
|
||||
delete data.isAdmin;
|
||||
}
|
||||
return this.prisma.user.update({
|
||||
where: { id },
|
||||
data,
|
||||
select: { id: true, email: true, name: true, isAdmin: true, isBlocked: true }
|
||||
});
|
||||
}
|
||||
async deleteUser(id) {
|
||||
async deleteUser(id, req) {
|
||||
const user = await this.prisma.user.findUnique({ where: { id } });
|
||||
if (!user)
|
||||
throw new common_1.NotFoundException('Không tìm thấy người dùng');
|
||||
@@ -1757,10 +1771,13 @@ let UserController = class UserController {
|
||||
}
|
||||
return { message: 'Đã xóa người dùng' };
|
||||
}
|
||||
async toggleBlock(id) {
|
||||
async toggleBlock(id, req) {
|
||||
const user = await this.prisma.user.findUnique({ where: { id } });
|
||||
if (!user)
|
||||
throw new common_1.NotFoundException('Người dùng không tồn tại');
|
||||
if (user.isAdmin) {
|
||||
throw new common_1.BadRequestException('Không thể khóa tài khoản Quản trị viên');
|
||||
}
|
||||
const updated = await this.prisma.user.update({
|
||||
where: { id },
|
||||
data: { isBlocked: !user.isBlocked },
|
||||
@@ -1771,6 +1788,7 @@ let UserController = class UserController {
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
(0, common_1.UseGuards)(admin_guard_1.AdminGuard),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)('q')),
|
||||
__metadata("design:type", Function),
|
||||
@@ -1790,27 +1808,33 @@ __decorate([
|
||||
(0, common_1.Patch)(':id'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__param(2, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:paramtypes", [String, Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "updateUser", null);
|
||||
__decorate([
|
||||
(0, exports.Roles)(client_1.ParticipantRole.OWNER),
|
||||
(0, common_1.Delete)(':id'),
|
||||
(0, common_1.UseGuards)(admin_guard_1.AdminGuard),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "deleteUser", null);
|
||||
__decorate([
|
||||
(0, exports.Roles)(client_1.ParticipantRole.OWNER, client_1.ParticipantRole.MANAGER),
|
||||
(0, common_1.Post)('block/:id'),
|
||||
(0, common_1.UseGuards)(admin_guard_1.AdminGuard),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "toggleBlock", null);
|
||||
UserController = __decorate([
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
|
||||
(0, common_1.Controller)('users'),
|
||||
(0, exports.Roles)(client_1.ParticipantRole.OWNER, client_1.ParticipantRole.MANAGER),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user