github-actions[bot]
Deploy Backend from GitHub Actions Commit: ca37b2a1c9dd5c702619ea7ae7b3260d2fb5663d
b185a6d | import { | |
| Controller, | |
| Get, | |
| Post, | |
| Body, | |
| Param, | |
| Query, | |
| Put, | |
| Delete, | |
| HttpCode, | |
| UseGuards, | |
| Req, | |
| ForbiddenException, | |
| } from "@nestjs/common"; | |
| import { UsersService } from "./users.service"; | |
| import { ApiTags, ApiOperation, ApiBearerAuth } from "@nestjs/swagger"; | |
| import { JwtAuthGuard } from "../auth/jwt-auth.guard"; | |
| import { RolesGuard } from "../auth/roles.guard"; | |
| import { Roles } from "../auth/roles.decorator"; | |
| import { RegisterDto } from "./dto/register.dto"; | |
| import { LoginDto } from "./dto/login.dto"; | |
| import { GoogleLoginDto } from "./dto/google-login.dto"; | |
| import { SupabaseLoginDto } from "./dto/supabase-login.dto"; | |
| import { UpdateUserDto } from "./dto/update-user.dto"; | |
| import { CreateFeedbackDto } from "./dto/create-feedback.dto"; | |
| ("Authentication & User Management") | |
| () | |
| export class UsersController { | |
| constructor(private usersService: UsersService) {} | |
| ("auth/register") | |
| ({ summary: "Register a new student account" }) | |
| async register(() dto: RegisterDto) { | |
| return this.usersService.register(dto.email, dto.name, dto.password); | |
| } | |
| ("auth/login") | |
| (200) | |
| ({ summary: "Login student account" }) | |
| async login(() dto: LoginDto) { | |
| return this.usersService.login(dto.email, dto.password); | |
| } | |
| ("auth/google") | |
| (200) | |
| ({ summary: "Authenticate with Google ID Token" }) | |
| async googleLogin(() dto: GoogleLoginDto) { | |
| return this.usersService.googleLogin(dto.idToken); | |
| } | |
| ("auth/supabase") | |
| (200) | |
| ({ summary: "Authenticate with Supabase JWT Token" }) | |
| async supabaseLogin(() dto: SupabaseLoginDto) { | |
| return this.usersService.supabaseLogin(dto.token); | |
| } | |
| ("users") | |
| (JwtAuthGuard, RolesGuard) | |
| ("admin") | |
| () | |
| ({ summary: "List all users (Admin)" }) | |
| async getUsers(("take") take?: string, ("skip") skip?: string) { | |
| const limit = take ? parseInt(take, 10) : 50; | |
| const offset = skip ? parseInt(skip, 10) : 0; | |
| return this.usersService.findAll(limit, offset); | |
| } | |
| ("users/:id") | |
| (JwtAuthGuard) | |
| () | |
| ({ summary: "Get details of a single user" }) | |
| async getUserById(("id") id: string, () req: any) { | |
| if (req.user.role !== "admin" && req.user.id !== id) { | |
| throw new ForbiddenException("You can only access your own user profile"); | |
| } | |
| return this.usersService.findById(id); | |
| } | |
| ("users/:id") | |
| (JwtAuthGuard, RolesGuard) | |
| ("admin") | |
| () | |
| ({ summary: "Update a user (Admin)" }) | |
| async updateUser(("id") id: string, () dto: UpdateUserDto) { | |
| return this.usersService.update(id, dto.name, dto.email, dto.streak); | |
| } | |
| ("users/:id") | |
| (JwtAuthGuard, RolesGuard) | |
| ("admin") | |
| () | |
| ({ summary: "Delete a user (Admin)" }) | |
| async deleteUser(("id") id: string) { | |
| return this.usersService.remove(id); | |
| } | |
| ("feedbacks") | |
| (JwtAuthGuard) | |
| () | |
| ({ summary: "Submit feedback (Student)" }) | |
| async createFeedback(() dto: CreateFeedbackDto, () req: any) { | |
| return this.usersService.createFeedback(req.user.id, dto.content); | |
| } | |
| ("feedbacks") | |
| (JwtAuthGuard, RolesGuard) | |
| ("admin") | |
| () | |
| ({ summary: "List all feedbacks (Admin)" }) | |
| async getFeedbacks() { | |
| return this.usersService.findAllFeedbacks(); | |
| } | |
| } | |