refactor(server): domain/infra (#1298)

* refactor: user repository

* refactor: user module

* refactor: move database into infra

* refactor(cli): use user core

* chore: import path

* chore: tests
This commit is contained in:
Jason Rasmussen
2023-01-11 21:34:36 -05:00
committed by GitHub
parent 89a6ed2a5b
commit 131caa20eb
182 changed files with 701 additions and 676 deletions

View File

@@ -0,0 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { Express } from 'express';
export class CreateProfileImageDto {
@ApiProperty({ type: 'string', format: 'binary' })
file!: Express.Multer.File;
}

View File

@@ -0,0 +1,27 @@
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { CreateUserDto } from './create-user.dto';
describe('create user DTO', () => {
it('validates the email', async () => {
const params: Partial<CreateUserDto> = {
email: undefined,
password: 'password',
firstName: 'first name',
lastName: 'last name',
};
let dto: CreateUserDto = plainToInstance(CreateUserDto, params);
let errors = await validate(dto);
expect(errors).toHaveLength(1);
params.email = 'invalid email';
dto = plainToInstance(CreateUserDto, params);
errors = await validate(dto);
expect(errors).toHaveLength(1);
params.email = 'valid@email.com';
dto = plainToInstance(CreateUserDto, params);
errors = await validate(dto);
expect(errors).toHaveLength(0);
});
});

View File

@@ -0,0 +1,53 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsNotEmpty, IsEmail } from 'class-validator';
export class CreateUserDto {
@IsEmail()
@Transform(({ value }) => value?.toLowerCase())
@ApiProperty({ example: 'testuser@email.com' })
email!: string;
@IsNotEmpty()
@ApiProperty({ example: 'password' })
password!: string;
@IsNotEmpty()
@ApiProperty({ example: 'John' })
firstName!: string;
@IsNotEmpty()
@ApiProperty({ example: 'Doe' })
lastName!: string;
}
export class CreateAdminDto {
@IsNotEmpty()
isAdmin!: true;
@IsEmail()
@Transform(({ value }) => value?.toLowerCase())
email!: string;
@IsNotEmpty()
password!: string;
@IsNotEmpty()
firstName!: string;
@IsNotEmpty()
lastName!: string;
}
export class CreateUserOAuthDto {
@IsEmail()
@Transform(({ value }) => value?.toLowerCase())
email!: string;
@IsNotEmpty()
oauthId!: string;
firstName?: string;
lastName?: string;
}

View File

@@ -0,0 +1,4 @@
export * from './create-profile-image.dto';
export * from './create-user.dto';
export * from './update-user.dto';
export * from './user-count.dto';

View File

@@ -0,0 +1,28 @@
import { IsEmail, IsNotEmpty, IsOptional } from 'class-validator';
export class UpdateUserDto {
@IsNotEmpty()
id!: string;
@IsEmail()
@IsOptional()
email?: string;
@IsOptional()
password?: string;
@IsOptional()
firstName?: string;
@IsOptional()
lastName?: string;
@IsOptional()
isAdmin?: boolean;
@IsOptional()
shouldChangePassword?: boolean;
@IsOptional()
profileImagePath?: string;
}

View File

@@ -0,0 +1,12 @@
import { Transform } from 'class-transformer';
import { IsBoolean, IsOptional } from 'class-validator';
export class UserCountDto {
@IsBoolean()
@IsOptional()
@Transform(({ value }) => value === 'true')
/**
* When true, return the number of admins accounts
*/
admin?: boolean = false;
}