feat: add user operations to backend
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { PickType } from "@nestjs/swagger";
|
||||
import { PickType } from "@nestjs/mapped-types";
|
||||
import { UserDTO } from "./user.dto";
|
||||
|
||||
export class PublicUserDTO extends PickType(UserDTO, ["email"] as const) {}
|
||||
|
||||
6
backend/src/user/dto/updateOwnUser.dto.ts
Normal file
6
backend/src/user/dto/updateOwnUser.dto.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { OmitType, PartialType } from "@nestjs/mapped-types";
|
||||
import { UserDTO } from "./user.dto";
|
||||
|
||||
export class UpdateOwnUserDTO extends PartialType(
|
||||
OmitType(UserDTO, ["isAdmin"] as const)
|
||||
) {}
|
||||
4
backend/src/user/dto/updateUser.dto.ts
Normal file
4
backend/src/user/dto/updateUser.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from "@nestjs/mapped-types";
|
||||
import { UserDTO } from "./user.dto";
|
||||
|
||||
export class UpdateUserDto extends PartialType(UserDTO) {}
|
||||
@@ -1,17 +1,25 @@
|
||||
import { Expose, plainToClass } from "class-transformer";
|
||||
import { IsEmail, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
import {
|
||||
IsEmail,
|
||||
IsNotEmpty,
|
||||
IsString,
|
||||
Length,
|
||||
Matches,
|
||||
} from "class-validator";
|
||||
|
||||
export class UserDTO {
|
||||
@Expose()
|
||||
id: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Expose()
|
||||
@Matches("^[a-zA-Z0-9_.]*$", undefined, {
|
||||
message: "Username can only contain letters, numbers, dots and underscores",
|
||||
})
|
||||
@Length(3, 32)
|
||||
username: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@@ -25,4 +33,10 @@ export class UserDTO {
|
||||
from(partial: Partial<UserDTO>) {
|
||||
return plainToClass(UserDTO, partial, { excludeExtraneousValues: true });
|
||||
}
|
||||
|
||||
fromList(partial: Partial<UserDTO>[]) {
|
||||
return partial.map((part) =>
|
||||
plainToClass(UserDTO, part, { excludeExtraneousValues: true })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user