Skip to content

Commit

Permalink
fix basic PUT users
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Jun 3, 2024
1 parent 51800ef commit 50eed02
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 3 additions & 2 deletions api/src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { UsersService } from './users.service';
import { User } from '@shared/dto/users/user.entity';
import { CreateUserDto } from '@shared/dto/users/create-user.dto';
import { UpdateUserDto } from '@shared/dto/users/update-user.dto';

@Controller('users')
export class UsersController {
Expand All @@ -31,8 +32,8 @@ export class UsersController {
}

@Put(':id')
async update(@Param('id') id: string) {
return this.usersService.update(id);
async update(@Param('id') id: string, @Body() dto: UpdateUserDto) {
return this.usersService.update(id, dto);
}

@Delete(':id')
Expand Down
12 changes: 3 additions & 9 deletions api/src/modules/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { User } from '@shared/dto/users/user.entity';
import { CreateUserDto } from '@shared/dto/users/create-user.dto';
import { Repository, DataSource } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { UpdateUserDto } from '@shared/dto/users/update-user.dto';

@Injectable()
export class UsersService {
Expand All @@ -25,15 +26,8 @@ export class UsersService {
});
}

async update(id: string) {
const found = this.userRepository.findOne({
where: { id },
});
if (!found) {
throw new NotFoundException(`User with ID "${id}" not found`);
}

return found;
async update(id: string, dto: UpdateUserDto) {
return this.userRepository.update(id, dto);
}

async remove(id: string) {
Expand Down

0 comments on commit 50eed02

Please sign in to comment.