Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Make keys in DTO optional
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 22, 2020
1 parent c929153 commit 5e6d691
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
72 changes: 69 additions & 3 deletions src/modules/auth/auth.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,76 @@
import { IsEmail, IsString, MinLength } from 'class-validator';
import {
IsBoolean,
IsEmail,
IsIn,
IsLocale,
IsNotEmpty,
IsObject,
IsOptional,
IsString,
IsUrl,
Length,
MinLength,
} from 'class-validator';

export class RegisterDto {
@IsString()
@IsNotEmpty()
@MinLength(3)
name: string;

@IsEmail()
@IsNotEmpty()
email: string;

@IsBoolean()
@IsOptional()
checkLocationOnLogin: boolean;

@IsString()
@MinLength(3)
name: string;
@Length(2, 2)
@IsOptional()
countryCode: string;

@IsString()
@IsIn(['MALE', 'FEMALE', 'NONBINARY', 'UNKNOWN'])
@IsOptional()
gender: 'MALE' | 'FEMALE' | 'NONBINARY' | 'UNKNOWN';

@IsIn(['ACCOUNT', 'UPDATES', 'PROMOTIONS'])
@IsOptional()
notificationEmails: 'ACCOUNT' | 'UPDATES' | 'PROMOTIONS';

@IsString()
@IsOptional()
password: string | null;

@IsLocale()
@IsOptional()
prefersLanguage: string;

@IsString()
@IsIn(['NO_PREFERENCE', 'LIGHT', 'DARK'])
@IsOptional()
prefersColorScheme: 'NO_PREFERENCE' | 'LIGHT' | 'DARK';

@IsString()
@IsIn(['NO_PREFERENCE', 'REDUCE'])
@IsOptional()
prefersReducedMotion: 'NO_PREFERENCE' | 'REDUCE';

@IsUrl()
@IsOptional()
profilePictureUrl: string;

@IsString()
@IsOptional()
timezone: string;

@IsBoolean()
@IsOptional()
twoFactorEnabled: boolean;

@IsObject()
@IsOptional()
attributes: Record<string, any>;
}
14 changes: 14 additions & 0 deletions src/modules/user/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
IsIn,
IsLocale,
IsObject,
IsOptional,
IsString,
IsUrl,
Length,
Expand All @@ -11,46 +12,59 @@ import {

export class UpdateUserDto {
@IsBoolean()
@IsOptional()
checkLocationOnLogin: boolean;

@IsString()
@Length(2, 2)
@IsOptional()
countryCode: string;

@IsString()
@IsIn(['MALE', 'FEMALE', 'NONBINARY', 'UNKNOWN'])
@IsOptional()
gender: 'MALE' | 'FEMALE' | 'NONBINARY' | 'UNKNOWN';

@IsString()
@MinLength(3)
@IsOptional()
name: string;

@IsIn(['ACCOUNT', 'UPDATES', 'PROMOTIONS'])
@IsOptional()
notificationEmails: 'ACCOUNT' | 'UPDATES' | 'PROMOTIONS';

@IsString()
@IsOptional()
password: string | null;

@IsLocale()
@IsOptional()
prefersLanguage: string;

@IsString()
@IsIn(['NO_PREFERENCE', 'LIGHT', 'DARK'])
@IsOptional()
prefersColorScheme: 'NO_PREFERENCE' | 'LIGHT' | 'DARK';

@IsString()
@IsIn(['NO_PREFERENCE', 'REDUCE'])
@IsOptional()
prefersReducedMotion: 'NO_PREFERENCE' | 'REDUCE';

@IsUrl()
@IsOptional()
profilePictureUrl: string;

@IsString()
@IsOptional()
timezone: string;

@IsBoolean()
@IsOptional()
twoFactorEnabled: boolean;

@IsObject()
@IsOptional()
attributes: Record<string, any>;
}

0 comments on commit 5e6d691

Please sign in to comment.