-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(candidacy): candidacy entity, service & controller #185
Merged
+459
−6
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f3b9881
feat(Criação do Serviço de Candidatura:create(createCandidacyDto; get…
joselazarojunior c247373
feat (Correções e melhorias no serviço de candidaturas incluindo trat…
joselazarojunior 118797b
feat (Corrigido: dateaClosing --> dateClosing.)
joselazarojunior 82c6577
feat (Corrigido: Cadidacy.entity.ts.)
joselazarojunior 6961a21
:wrench: fix(candidacy): files
GuiTDS 284d830
fix conflicts
GuiTDS 3c59c94
:sparkles: feat(473): create candidacy module & controller
GuiTDS 51b6996
:wrench: fix(candidacy): update candidacy error handling
GuiTDS e6adf11
:sparkles: feat(candidacy): migration
GuiTDS dfe7126
fix(candidacy): add swagger decorators & change candidacy column name
GuiTDS afd61f3
fix(candidacies): entity column name
GuiTDS ccd58c1
Update data-source.ts
MikaelMelo1 3697025
Merge branch 'main' into feat-473
MikaelMelo1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
Column, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
ManyToOne, | ||
JoinColumn, | ||
} from 'typeorm'; | ||
import { UsersEntity } from './users.entity'; | ||
import { JobsEntity } from './jobs.entity'; | ||
import { CandidacyStatus } from './candidancy-status.enum'; | ||
|
||
@Entity('tb_candidacies') | ||
export class CandidacyEntity { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
@Column('uuid', { name: 'job_id' }) | ||
jobId: string; | ||
|
||
@Column('uuid', { name: 'user_id' }) | ||
userId: string; | ||
|
||
@Column({ type: 'enum', enum: CandidacyStatus }) | ||
status: CandidacyStatus; | ||
|
||
@Column({ | ||
type: 'timestamp', | ||
name: 'date_candidacy', | ||
default: () => 'CURRENT_TIMESTAMP', | ||
}) | ||
dateCandidacy: Date; | ||
|
||
@Column({ type: 'timestamp', nullable: true }) | ||
dateclosing: Date; | ||
|
||
@ManyToOne(() => UsersEntity) | ||
@JoinColumn({ name: 'user_id' }) | ||
user: UsersEntity; | ||
|
||
@ManyToOne(() => JobsEntity) | ||
@JoinColumn({ name: 'job_id' }) | ||
job: JobsEntity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum CandidacyStatus { | ||
InProgress = 'em andamento', | ||
Closed = 'encerrada', | ||
NoInterest = 'sem interesse', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GuiTDS marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
MigrationInterface, | ||
QueryRunner, | ||
Table, | ||
TableForeignKey, | ||
} from 'typeorm'; | ||
|
||
export class Candidacy1731094752487 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: 'tb_candidacies', | ||
columns: [ | ||
{ | ||
name: 'id', | ||
type: 'uuid', | ||
isPrimary: true, | ||
generationStrategy: 'uuid', | ||
default: 'uuid_generate_v4()', | ||
}, | ||
{ | ||
name: 'job_id', | ||
type: 'uuid', | ||
}, | ||
{ | ||
name: 'user_id', | ||
type: 'uuid', | ||
}, | ||
{ | ||
name: 'status', | ||
type: 'enum', | ||
enum: ['em andamento', 'encerrada', 'sem interesse'], | ||
}, | ||
{ | ||
name: 'date_candidacy', | ||
type: 'timestamp', | ||
default: 'CURRENT_TIMESTAMP', | ||
}, | ||
{ | ||
name: 'dateclosing', | ||
type: 'timestamp', | ||
isNullable: true, | ||
}, | ||
], | ||
}), | ||
true, | ||
); | ||
|
||
await queryRunner.createForeignKey( | ||
'tb_candidacies', | ||
new TableForeignKey({ | ||
columnNames: ['user_id'], | ||
referencedTableName: 'tb_users', | ||
referencedColumnNames: ['id'], | ||
}), | ||
); | ||
|
||
await queryRunner.createForeignKey( | ||
'tb_candidacies', | ||
new TableForeignKey({ | ||
columnNames: ['job_id'], | ||
referencedTableName: 'tb_jobs', | ||
referencedColumnNames: ['id'], | ||
}), | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable('tb_candidacies'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Module } from '@nestjs/common'; | ||
import { CandidacyEntity } from 'src/database/entities/candidacy.entity'; | ||
import { CandidacyRepository } from './repository/candidacy.repository'; | ||
import { CandidacyService } from './service/candidacy.service'; | ||
import { CandidacyController } from './controller/candidacy.controller'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([CandidacyEntity])], | ||
controllers: [CandidacyController], | ||
providers: [CandidacyService, CandidacyRepository], | ||
exports: [CandidacyService], | ||
}) | ||
export class CandidacyModule {} |
GuiTDS marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
BadRequestException, | ||
Body, | ||
Controller, | ||
Get, | ||
Patch, | ||
Post, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { CandidacyService } from '../service/candidacy.service'; | ||
import { CreateCandidacyDto } from '../dto/create-candidacy.dto'; | ||
import { LoggedUser } from 'src/modules/auth/decorator/logged-user.decorator'; | ||
import { UsersEntity } from 'src/database/entities/users.entity'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { UpdateCandidacyDto } from '../dto/update-candidacy.dto'; | ||
import { CandidacyStatus } from 'src/database/entities/candidancy-status.enum'; | ||
|
||
@Controller('candidacy') | ||
@UseGuards(AuthGuard('jwt')) | ||
export class CandidacyController { | ||
constructor(private readonly candidacyService: CandidacyService) {} | ||
|
||
@Post() | ||
async createCandidacy(@Body() createCandidacyDTO: CreateCandidacyDto) { | ||
return await this.candidacyService.create(createCandidacyDTO); | ||
} | ||
|
||
@Get() | ||
async getCandidacies(@LoggedUser() user: UsersEntity) { | ||
return await this.candidacyService.getCandidacyByUserId(user.id); | ||
} | ||
|
||
@Patch() | ||
async updateCandidacy(@Body() updateCandidacyDto: UpdateCandidacyDto) { | ||
if (updateCandidacyDto.status === CandidacyStatus.InProgress) { | ||
throw new BadRequestException( | ||
'Não é possível atualizar para o status "em andamento"', | ||
); | ||
} | ||
return await this.candidacyService.closeCandidacy( | ||
updateCandidacyDto.id, | ||
updateCandidacyDto.status, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IsUUID, IsNotEmpty } from 'class-validator'; | ||
|
||
export class CreateCandidacyDto { | ||
@IsUUID() | ||
@IsNotEmpty() | ||
userId: string; | ||
|
||
@IsUUID() | ||
@IsNotEmpty() | ||
jobId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsEnum, IsNotEmpty, IsUUID } from 'class-validator'; | ||
import { CandidacyStatus } from 'src/database/entities/candidancy-status.enum'; | ||
|
||
export class UpdateCandidacyDto { | ||
@ApiProperty() | ||
@IsUUID() | ||
@IsNotEmpty() | ||
id: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsEnum(CandidacyStatus) | ||
status: CandidacyStatus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
BadRequestException, | ||
Injectable, | ||
InternalServerErrorException, | ||
NotFoundException, | ||
} from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
import { CandidacyEntity } from '../../../database/entities/candidacy.entity'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { CandidacyStatus } from 'src/database/entities/candidancy-status.enum'; | ||
|
||
@Injectable() | ||
export class CandidacyRepository { | ||
constructor( | ||
@InjectRepository(CandidacyEntity) | ||
private candidacyRepository: Repository<CandidacyEntity>, | ||
) {} | ||
|
||
async createCandidacy(candidacy: CandidacyEntity): Promise<CandidacyEntity> { | ||
return this.candidacyRepository.save(candidacy); | ||
} | ||
|
||
async findAllByUserId(userId: string): Promise<CandidacyEntity[]> { | ||
if (!userId) { | ||
throw new BadRequestException('userId é obrigatório'); | ||
} | ||
try { | ||
const candidacy = await this.candidacyRepository.find({ | ||
where: { userId: userId }, | ||
}); | ||
if (!candidacy.length) { | ||
throw new NotFoundException( | ||
'Nenhuma candidatura encontrada para este usuário', | ||
); | ||
} | ||
return candidacy; | ||
} catch (error) { | ||
throw new BadRequestException( | ||
'Erro ao buscar candidaturas: ' + error.message, | ||
); | ||
} | ||
} | ||
|
||
async updateStatus( | ||
id: string, | ||
status: CandidacyStatus, | ||
): Promise<CandidacyEntity | null> { | ||
try { | ||
const candidacy = await this.candidacyRepository.findOne({ | ||
where: { id }, | ||
}); | ||
if (!candidacy) { | ||
throw new NotFoundException('Candidatura não encontrada'); | ||
} | ||
candidacy.status = status; | ||
await this.candidacyRepository.save(candidacy); | ||
|
||
return candidacy; | ||
} catch (error) { | ||
if (error instanceof NotFoundException) { | ||
throw error; | ||
} else { | ||
throw new InternalServerErrorException( | ||
'Erro ao atualizar o status da candidatura: ' + error.message, | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CandidacyService } from '../candidacy.service'; | ||
|
||
describe('CandidacyService', () => { | ||
let service: CandidacyService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [CandidacyService], | ||
}).compile(); | ||
|
||
service = module.get<CandidacyService>(CandidacyService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se não precisar registar hora pode deixar apenas o date, mas se precisar, mantem como está. na coluna do timestamp.
Vamos manter com camelCase para ficar show.