| 1234567891011121314151617181920212223242526 |
- import { Controller, Get, Param, NotFoundException } from '@nestjs/common';
- import { UsersService } from 'src/services/user.service';
- import { RegisteredUser } from 'src/interface/interface';
- @Controller('users')
- export class UsersController {
- constructor(private readonly usersService: UsersService) {}
- // GET /users/:id → Fetch user by ID
- @Get(':id')
- async getUserById(@Param('id') id: string): Promise<Omit<RegisteredUser, 'password'>> {
- const user = await this.usersService.findById(id);
- if (!user) {
- throw new NotFoundException(`User with ID ${id} not found`);
- }
- const { password, ...safeUser } = user;
- return safeUser;
- }
- // GET /users → (Optional) List all users (for debugging)
- @Get()
- getAllUsers(): Omit<RegisteredUser, 'password'>[] {
- return this.usersService.getAllUsers();
- }
- }
|