Camada: Domain: Entity
Camada: Domain: Entity
Entity:
export class newProfile {
constructor(
public readonly value: string,
public readonly description: string,
){}
}
}
Repository:
import { newProfile, Profile } from "src/Domain/Entities/Assist/profile.entity";
@Injectable()
export class ProfileService {
constructor(
@Inject('ProfileRepository')
private readonly profileRepository: ProfileRepository
){}
if (checkProfile) {
throw new ConflictException(`Profile with value '${data.value}' already
exists.`);
} else {
const profile = new newProfile(data.value, data.description);
return this.profileRepository.create(data);
}
}
if (!locateProfile) {
throw new NotFoundException(`Profile with ID '${data.id}' not found.`);
} else {
const checkProfile = await
this.profileRepository.findByValue(data.value);
} else {
const profile = new Profile(+data.id, data.value, data.description);
return this.profileRepository.update(profile);
}
}
}
if (!locateProfile) {
throw new NotFoundException(`Profile with ID '${id}' not found.`);
} else {
return this.profileRepository.delete(+id);
}
}
}
}
Camada: Application
UseCases:
create-profile.use-case
import { Injectable } from "@nestjs/common";
@Injectable()
export class CreateProfileUseCase {
constructor(private readonly profileService: ProfileService) { }
delete-profile.use-case
import { Injectable } from "@nestjs/common";
@Injectable()
export class DeleteProfileUseCase {
constructor(private readonly profileService: ProfileService) { }
@Injectable()
export class FindAllProfilesUseCase {
constructor(private readonly profileService: ProfileService) { }
find-profile-by-id.use-case
import { Injectable } from "@nestjs/common";
@Injectable()
export class FindProfileByIdUseCase {
constructor(private readonly profileService: ProfileService) { }
find-profile-by-value.use-case
import { Injectable } from "@nestjs/common";
@Injectable()
export class FindProfileByValueUseCase {
constructor(private readonly profileService: ProfileService) { }
@Injectable()
export class UpdateProfileUseCase {
constructor(private readonly profileService: ProfileService) { }
DTO:
profile.create-dto
import { IsAlpha, IsNotEmpty, IsString, Length, Matches } from "class-validator";
profile.update-dto
import { PartialType } from '@nestjs/mapped-types';
import { ProfileCreateDto } from './profile.create-dto';
import { IsNotEmpty, IsInt } from 'class-validator';
@Controller('profile')
export class ProfileController {
constructor(
private readonly createProfileUseCase: CreateProfileUseCase,
private readonly updateProfileUseCase: UpdateProfileUseCase,
private readonly deleteProfileUseCase: DeleteProfileUseCase,
private readonly findAllProfilesUseCase: FindAllProfilesUseCase,
private readonly findProfileByIdUseCase: FindProfileByIdUseCase,
private readonly findProfileByValueUseCase: FindProfileByValueUseCase,
){}
@Post()
async create(@Body() data: ProfileCreateDto) {
return this.createProfileUseCase.execute(data)
}
@Patch()
async update(@Body() data: ProfileUpdateDto) {
return this.updateProfileUseCase.execute(data)
}
@Delete()
async remove(@Body() data: ProfileUpdateDto) {
return this.deleteProfileUseCase.execute(+data.id);
}
@Get()
async findAll() {
return this.findAllProfilesUseCase.execute();
}
@Get(':id')
async findById(@Param('id') id: number) {
return this.findProfileByIdUseCase.execute(id);
}
@Get(':value')
async findByValue(@Param('value') value: string) {
return this.findProfileByValueUseCase.execute(value);
}
}
Camada: Infrastructre
Module:
import { Module } from "@nestjs/common";
import { PrismaModule } from "src/Infrastructure/Prisma/prisma.module";
import { ProfileService } from "src/Domain/Services/Assist/profile.service";
import { ProfileController } from
"src/Interface/Controllers/Assist/profile.controller";
import { PrismaProfileRepository } from
"src/Infrastructure/Repositories/Assist/prisma-profile.repository";
import { CreateProfileUseCase } from
"src/Application/use-cases/Assist/profile/create-profile.use-case";
import { UpdateProfileUseCase } from
"src/Application/use-cases/Assist/profile/update-profile.use-case";
import { DeleteProfileUseCase } from
"src/Application/use-cases/Assist/profile/delete-profile.use-case";
import { FindAllProfilesUseCase } from
"src/Application/use-cases/Assist/profile/find-all-profiles.use-case";
import { FindProfileByIdUseCase } from
"src/Application/use-cases/Assist/profile/find-profile-by-id.use-case";
import { FindProfileByValueUseCase } from
"src/Application/use-cases/Assist/profile/find-profile-by-value.use-case";
@Module({
imports: [PrismaModule],
exports: [ProfileService],
controllers: [ProfileController],
providers: [
ProfileService, PrismaProfileRepository,
CreateProfileUseCase,
UpdateProfileUseCase,
DeleteProfileUseCase,
FindAllProfilesUseCase,
FindProfileByIdUseCase,
FindProfileByValueUseCase,
{
provide: 'ProfileRepository',
useClass: PrismaProfileRepository
},
],
}) export class ProfileModule { }
Prisma Repository:
import { Injectable } from "@nestjs/common";
import { PrismaService } from "src/Infrastructure/Prisma/prisma.service";
@Injectable()
export class PrismaProfileRepository implements ProfileRepository {
constructor(private readonly prisma: PrismaService) { }
@Module({
imports: [
PrismaModule,
UserModule,
],
controllers: [],
providers: [],
})
export class AppModule { }