diff --git a/src/database/entities/candidacy-status.enum.ts b/src/database/entities/candidacy-status.enum.ts new file mode 100644 index 0000000..7ab3d6b --- /dev/null +++ b/src/database/entities/candidacy-status.enum.ts @@ -0,0 +1,6 @@ +export enum CandidacyStatus { + InProgress = 'em andamento', + Closed = 'encerrada', + NoInterest = 'sem interesse', + } + \ No newline at end of file diff --git a/src/database/entities/candidacy.entity.ts b/src/database/entities/candidacy.entity.ts new file mode 100644 index 0000000..2fdc39e --- /dev/null +++ b/src/database/entities/candidacy.entity.ts @@ -0,0 +1,41 @@ +import { + Column, + Entity, + PrimaryGeneratedColumn, + ManyToOne, + JoinColumn, + } from 'typeorm'; + import { UsersEntity } from './users.entity'; + import { JobsEntity } from './jobs.entity'; +import { CandidacyStatus } from './candidacy-status.enum'; + + + @Entity('tb_candidacies') + export class CandidacyEntity { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Column('uuid') + jobId: string; + + @Column('uuid') + userId: string; + + @Column({ type: 'enum', enum: CandidacyStatus }) + status: CandidacyStatus; + + @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) + dateCandidacy: Date; + + @Column({ type: 'timestamp', nullable: true }) + dateclosing: Date; + + @ManyToOne(() => UsersEntity) + @JoinColumn({ name: 'userId' }) + user: UsersEntity; + + @ManyToOne(() => JobsEntity) + @JoinColumn({ name: 'jobId' }) + job: JobsEntity; + } + \ No newline at end of file diff --git a/src/database/entities/jobs.entity.ts b/src/database/entities/jobs.entity.ts index 192cd2f..80c2503 100644 --- a/src/database/entities/jobs.entity.ts +++ b/src/database/entities/jobs.entity.ts @@ -15,6 +15,7 @@ import { JobsTypeEnum } from '../../modules/jobs/enums/job-type.enum'; import { ApplicationEntity } from './applications.entity'; import { CommentsEntity } from './comments.entity'; import { CompaniesEntity } from './companies.entity'; +import { CandidacyEntity } from './candidacy.entity'; @Entity('tb_jobs') export class JobsEntity { @@ -135,4 +136,7 @@ export class JobsEntity { @Column({ nullable: true }) content: string; + + @OneToMany(() => CandidacyEntity, (candidacy) => candidacy.job) + candidacies: CandidacyEntity[]; } diff --git a/src/database/entities/users.entity.ts b/src/database/entities/users.entity.ts index 2f20bf3..62c6934 100644 --- a/src/database/entities/users.entity.ts +++ b/src/database/entities/users.entity.ts @@ -11,6 +11,7 @@ import { import { ApplicationEntity } from './applications.entity'; import { CurriculumEntity } from './curriculum.entity'; import { PersonalDataEntity } from './personal-data.entity'; +import { CandidacyEntity } from './candidacy.entity'; enum RolesEnum { ADMIN = 'ADMIN', @@ -72,6 +73,9 @@ export class UsersEntity { @OneToMany(() => ApplicationEntity, (application) => application.user) applications: ApplicationEntity[]; + @OneToMany(() => CandidacyEntity, (candidacy) => candidacy.user) + candidacies: CandidacyEntity[]; + @CreateDateColumn() created_at: Date; diff --git a/src/modules/alert/repository/candidacy.repository.ts b/src/modules/alert/repository/candidacy.repository.ts new file mode 100644 index 0000000..6655a35 --- /dev/null +++ b/src/modules/alert/repository/candidacy.repository.ts @@ -0,0 +1,43 @@ +import { Injectable } 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/candidacy-status.enum'; + + +@Injectable() +export class CandidacyRepository { + constructor( + @InjectRepository(CandidacyEntity) + private candidacyRepository: Repository, + ) {} + + async create(candidacy: CandidacyEntity): Promise { + return this.candidacyRepository.save(candidacy); + } + + async updateStatus(id: string, status: CandidacyStatus): Promise { + try { + const candidacyToUpdate = await this.candidacyRepository.findOne({ where: { id } }); + + if (!candidacyToUpdate) { + console.log(`Candidatura com ID ${id} não encontrada.`); + throw new Error(`Candidatura com ID ${id} não foi encontrada.`); + } + + candidacyToUpdate.status = status; + await this.candidacyRepository.save(candidacyToUpdate); + + return candidacyToUpdate; + } catch (error) { + console.error('Erro ao atualizar o status da candidatura:', error.message); + throw new Error('Erro ao atualizar o status da candidatura.'); + } + } + + + async findByUserId(userId: string): Promise { + return await this.candidacyRepository.find({ where: { userId } }); + } + +} \ No newline at end of file