36
									
								
								src/models/creation/CreateAuth.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/models/creation/CreateAuth.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					import { IsEmail, IsOptional, IsString } from 'class-validator';
 | 
				
			||||||
 | 
					import { PasswordNeededError } from '../../errors/AuthError';
 | 
				
			||||||
 | 
					import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
 | 
				
			||||||
 | 
					import { Auth } from '../entities/Auth';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class CreateAuth {
 | 
				
			||||||
 | 
					    @IsOptional()
 | 
				
			||||||
 | 
					    @IsString()
 | 
				
			||||||
 | 
					    username?: string;
 | 
				
			||||||
 | 
					    @IsString()
 | 
				
			||||||
 | 
					    password: string;
 | 
				
			||||||
 | 
					    @IsEmail()
 | 
				
			||||||
 | 
					    @IsString()
 | 
				
			||||||
 | 
					    email?: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async toAuth(): Promise<Auth> {
 | 
				
			||||||
 | 
					        let newAuth: Auth = new Auth();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (this.email === undefined && this.username === undefined) {
 | 
				
			||||||
 | 
					            throw new UsernameOrEmailNeededError();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (!this.password) {
 | 
				
			||||||
 | 
					            throw new PasswordNeededError()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // TODO: jwt creation + return
 | 
				
			||||||
 | 
					        newAuth.access_token = ""
 | 
				
			||||||
 | 
					        newAuth.refresh_token = ""
 | 
				
			||||||
 | 
					        newAuth.access_token_expires_at = 1587349200
 | 
				
			||||||
 | 
					        newAuth.refresh_token_expires_at = 1587349200
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        console.log(newAuth)
 | 
				
			||||||
 | 
					        return newAuth;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user