Browse Source

* Fixes

master
vvandenb 2 years ago
parent
commit
a4753a57cc
  1. 3
      back/src/users/dto/user.dto.ts
  2. 2
      back/src/users/entity/user.entity.ts
  3. 5
      back/src/users/users.controller.ts

3
back/src/users/dto/user.dto.ts

@ -1,4 +1,4 @@
import { IsNotEmpty, IsPositive, IsOptional, IsEmail, NotContains, MaxLength } from 'class-validator'
import { IsNotEmpty, IsPositive, IsOptional, IsEmail, NotContains, MaxLength, IsAlphanumeric } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { Express } from 'express'
@ -10,6 +10,7 @@ export class UserDto {
@IsNotEmpty()
@NotContains(' ')
@IsAlphanumeric()
@MaxLength(15)
readonly username: string

2
back/src/users/entity/user.entity.ts

@ -19,7 +19,7 @@ export class User {
@Column({ unique: true })
ftId: number
@Column({ unique: true, nullable: true })
@Column({ nullable: true })
email: string
@Column({ select: false, nullable: true })

5
back/src/users/users.controller.ts

@ -211,6 +211,11 @@ export class UsersController {
): Promise<User> {
const user = await this.usersService.findUser(+profile.id)
if (user == null) throw new BadRequestException('User not found.')
if (payload.username !== undefined) {
const user2: User | null = await this.usersService.findUserByName(payload.username).catch(() => null)
const user2ftId = user2?.ftId
if (user2 !== null && user2ftId !== +profile.id) throw new BadRequestException('Username already taken.')
}
await this.usersService.update(user, payload)
return user
}

Loading…
Cancel
Save