mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-25 02:05:11 +02:00
feat: Onboarding
This commit is contained in:
@@ -7,13 +7,14 @@ import {
|
||||
NotFoundException,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { UserService } from './user.service';
|
||||
import { AuthGuard, GetUser } from '../auth/auth.guard';
|
||||
import { ApiNotFoundResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { CreateUserDto, UserDto } from './user.dto';
|
||||
import { User } from './user.entity';
|
||||
import { CreateUserDto, UpdateUserDto, UserDto } from './user.dto';
|
||||
import { Settings, User } from './user.entity';
|
||||
import { ApiException } from '@nanogiants/nestjs-swagger-api-exception-decorator';
|
||||
|
||||
@ApiTags('user')
|
||||
@@ -72,4 +73,25 @@ export class UserController {
|
||||
|
||||
return UserDto.fromEntity(user);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put(':id')
|
||||
@ApiOkResponse({ description: 'User updated', type: UserDto })
|
||||
async updateUser(
|
||||
@Param('id') id: string,
|
||||
@Body() updateUserDto: UpdateUserDto,
|
||||
@GetUser() callerUser: User,
|
||||
): Promise<UserDto> {
|
||||
if ((!callerUser.isAdmin && callerUser.id !== id) || !id) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
const user = await this.userService.findOne(id);
|
||||
if (updateUserDto.settings) user.settings = updateUserDto.settings;
|
||||
if (updateUserDto.onboardingDone)
|
||||
user.onboardingDone = updateUserDto.onboardingDone;
|
||||
|
||||
const updated = await this.userService.update(user);
|
||||
return UserDto.fromEntity(updated);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OmitType, PickType } from '@nestjs/swagger';
|
||||
import { OmitType, PartialType, PickType } from '@nestjs/swagger';
|
||||
import { User } from './user.entity';
|
||||
|
||||
export class UserDto extends OmitType(User, ['password'] as const) {
|
||||
@@ -8,6 +8,7 @@ export class UserDto extends OmitType(User, ['password'] as const) {
|
||||
name: entity.name,
|
||||
isAdmin: entity.isAdmin,
|
||||
settings: entity.settings,
|
||||
onboardingDone: entity.onboardingDone,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,6 +19,8 @@ export class CreateUserDto extends PickType(User, [
|
||||
'isAdmin',
|
||||
] as const) {}
|
||||
|
||||
export class UpdateUserDto extends OmitType(User, ['id'] as const) {}
|
||||
export class UpdateUserDto extends PartialType(
|
||||
PickType(User, ['settings', 'onboardingDone', 'name'] as const),
|
||||
) {}
|
||||
|
||||
export class SignInDto extends PickType(User, ['name', 'password'] as const) {}
|
||||
|
||||
@@ -112,9 +112,13 @@ export class User {
|
||||
password: string;
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@Column()
|
||||
@Column({ default: false })
|
||||
isAdmin: boolean = false;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@Column({ default: false })
|
||||
onboardingDone: boolean = false;
|
||||
|
||||
@ApiProperty({ required: true, type: Settings })
|
||||
@Column('json', { default: JSON.stringify(DEFAULT_SETTINGS) })
|
||||
settings = DEFAULT_SETTINGS;
|
||||
|
||||
Reference in New Issue
Block a user