Symmetrisch zu Modul-27/28-Fix fuer Colony/Apiary: kein Weg, einen versehentlich deaktivierten Benutzer wieder zu aktivieren. Neuer POST :id/activate-Endpunkt setzt isActive zurueck auf true und loescht deactivatedAt; ConflictException wenn bereits aktiv.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { Role } from '../../generated/prisma';
|
|
import { Roles } from '../auth/decorators/roles.decorator';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
import { UpdateUserDto } from './dto/update-user.dto';
|
|
import { UsersService } from './users.service';
|
|
|
|
@ApiTags('users')
|
|
@ApiBearerAuth()
|
|
@Controller('users')
|
|
@Roles(Role.ADMIN)
|
|
export class UsersController {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@Get()
|
|
findAll() {
|
|
return this.usersService.findAll();
|
|
}
|
|
|
|
@Post()
|
|
create(@Body() dto: CreateUserDto, @CurrentUser() actor: AuthenticatedUser) {
|
|
return this.usersService.create(dto, actor.id);
|
|
}
|
|
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.usersService.findSummaryById(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateUserDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.usersService.update(id, dto, actor.id);
|
|
}
|
|
|
|
@Post(':id/deactivate')
|
|
deactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
|
return this.usersService.deactivate(id, actor.id);
|
|
}
|
|
|
|
@Post(':id/activate')
|
|
activate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
|
return this.usersService.activate(id, actor.id);
|
|
}
|
|
}
|