From fd325b7748ff2546ac639eb77c733fb37d6f25b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Sat, 28 Sep 2024 19:56:39 -0300 Subject: [PATCH 1/7] =?UTF-8?q?:construction:=20Feat=20(jobs,users,candida?= =?UTF-8?q?cy):=20Cria=C3=A7=C3=A3o=20da=20entidade=20candidacy=20e=20do?= =?UTF-8?q?=20reposit=C3=B3rio=20candidacy=20com=20m=C3=A9todos=20create,?= =?UTF-8?q?=20findByUsuarioId=20e=20updateStatus.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/entities/candidacy.entity.ts | 39 ++++++++++++++++++ src/database/entities/jobs.entity.ts | 4 ++ src/database/entities/users.entity.ts | 4 ++ .../alert/repository/candidacy.repository.ts | 40 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 src/database/entities/candidacy.entity.ts create mode 100644 src/modules/alert/repository/candidacy.repository.ts diff --git a/src/database/entities/candidacy.entity.ts b/src/database/entities/candidacy.entity.ts new file mode 100644 index 0000000..3e2a6c5 --- /dev/null +++ b/src/database/entities/candidacy.entity.ts @@ -0,0 +1,39 @@ +import { + Column, + Entity, + PrimaryGeneratedColumn, + ManyToOne, + JoinColumn, + } from 'typeorm'; + import { UsersEntity } from './users.entity'; + import { JobsEntity } from './jobs.entity'; + + @Entity('tb_candidacies') + export class CandidacyEntity { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Column('uuid') + vagaId: string; + + @Column('uuid') + usuarioId: string; + + @Column({ type: 'enum', enum: ['em andamento', 'encerrada', 'sem interesse'] }) + status: string; + + @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) + dataCandidatura: Date; + + @Column({ type: 'timestamp', nullable: true }) + dataEncerramento: Date; + + @ManyToOne(() => UsersEntity) + @JoinColumn({ name: 'usuarioId' }) + user: UsersEntity; + + @ManyToOne(() => JobsEntity) + @JoinColumn({ name: 'vagaId' }) + 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..242a01b 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.user) + 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..9982ecd --- /dev/null +++ b/src/modules/alert/repository/candidacy.repository.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@nestjs/common'; +import { Repository } from 'typeorm'; +import { CandidacyEntity } from '../../../database/entities/candidacy.entity'; // Certifique-se de importar a entidade correta +import { InjectRepository } from '@nestjs/typeorm'; + +@Injectable() +export class CandidacyRepository { + constructor( + @InjectRepository(CandidacyEntity) + private candidacyRepository: Repository, + ) {} + + async create(candidacy: CandidacyEntity): Promise { + return this.candidacyRepository.save(candidacy); + } + + async findByUsuarioId(userId: string): Promise { + return this.candidacyRepository.find({ where: { user: { id: userId } } }); + } + + async updateStatus(id: string, status: string): Promise { + try { + const candidacies = await this.candidacyRepository.find({ where: { id } }); + + if (candidacies.length === 0) { + return undefined; + } + const candidacyToUpdate = candidacies[0]; + candidacyToUpdate.status = status; + + await this.candidacyRepository.save(candidacyToUpdate); + + return candidacyToUpdate; + } catch (error) { + + return undefined; + } + } + +} From 9cb2da0dfe96c4e40dce7e3d215f51dcea16bc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Mon, 7 Oct 2024 18:31:56 -0300 Subject: [PATCH 2/7] =?UTF-8?q?:sparkles:=20Feat=20(candidacy-entity,=20ca?= =?UTF-8?q?ndidacy-repository,=20candidacy-status-enum):=20Padroniza=C3=A7?= =?UTF-8?q?=C3=A3o=20dos=20atributos=20em=20ingl=C3=AAs=20e=20cria=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20um=20enum=20para=20o=20status=20de=20vaga.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/entities/candidacy-status.enum.ts | 6 ++++++ src/database/entities/candidacy.entity.ts | 17 +++++++++-------- .../alert/repository/candidacy.repository.ts | 14 ++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 src/database/entities/candidacy-status.enum.ts diff --git a/src/database/entities/candidacy-status.enum.ts b/src/database/entities/candidacy-status.enum.ts new file mode 100644 index 0000000..540f0ed --- /dev/null +++ b/src/database/entities/candidacy-status.enum.ts @@ -0,0 +1,6 @@ +export enum CandidacyStatus { + EmAndamento = 'em andamento', + Encerrada = 'encerrada', + SemInteresse = 'sem interesse', + } + \ No newline at end of file diff --git a/src/database/entities/candidacy.entity.ts b/src/database/entities/candidacy.entity.ts index 3e2a6c5..aa75082 100644 --- a/src/database/entities/candidacy.entity.ts +++ b/src/database/entities/candidacy.entity.ts @@ -7,6 +7,7 @@ import { } from 'typeorm'; import { UsersEntity } from './users.entity'; import { JobsEntity } from './jobs.entity'; +import { CandidacyStatus } from './candidacy-status.enum'; @Entity('tb_candidacies') export class CandidacyEntity { @@ -14,26 +15,26 @@ import { id: string; @Column('uuid') - vagaId: string; + vacancyId: string; @Column('uuid') - usuarioId: string; + userId: string; - @Column({ type: 'enum', enum: ['em andamento', 'encerrada', 'sem interesse'] }) - status: string; + @Column({ type: 'enum', enum: CandidacyStatus }) + status: CandidacyStatus; @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) - dataCandidatura: Date; + dateCandidacy: Date; @Column({ type: 'timestamp', nullable: true }) - dataEncerramento: Date; + dateclosing: Date; @ManyToOne(() => UsersEntity) - @JoinColumn({ name: 'usuarioId' }) + @JoinColumn({ name: 'userId' }) user: UsersEntity; @ManyToOne(() => JobsEntity) - @JoinColumn({ name: 'vagaId' }) + @JoinColumn({ name: 'vacancyId' }) job: JobsEntity; } \ No newline at end of file diff --git a/src/modules/alert/repository/candidacy.repository.ts b/src/modules/alert/repository/candidacy.repository.ts index 9982ecd..bb2dd87 100644 --- a/src/modules/alert/repository/candidacy.repository.ts +++ b/src/modules/alert/repository/candidacy.repository.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { Repository } from 'typeorm'; import { CandidacyEntity } from '../../../database/entities/candidacy.entity'; // Certifique-se de importar a entidade correta import { InjectRepository } from '@nestjs/typeorm'; +import { CandidacyStatus } from 'src/database/entities/candidacy-status.enum'; @Injectable() export class CandidacyRepository { @@ -14,27 +15,24 @@ export class CandidacyRepository { return this.candidacyRepository.save(candidacy); } - async findByUsuarioId(userId: string): Promise { - return this.candidacyRepository.find({ where: { user: { id: userId } } }); - } - - async updateStatus(id: string, status: string): Promise { + async updateStatus(id: string, status: CandidacyStatus): Promise { try { const candidacies = await this.candidacyRepository.find({ where: { id } }); if (candidacies.length === 0) { return undefined; } - const candidacyToUpdate = candidacies[0]; + + const candidacyToUpdate = candidacies[0]; candidacyToUpdate.status = status; await this.candidacyRepository.save(candidacyToUpdate); return candidacyToUpdate; } catch (error) { - - return undefined; + return undefined; } } + } From 4ec73c0b7456dc15d7d81cb9a3dccdd0fa98b10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Mon, 7 Oct 2024 18:42:45 -0300 Subject: [PATCH 3/7] =?UTF-8?q?:bug:=20Fix=20(jobs-entity):=20Corre=C3=A7?= =?UTF-8?q?=C3=B5es=20da=20liga=C3=A7=C3=A3o=20de=20tabelas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/entities/jobs.entity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/entities/jobs.entity.ts b/src/database/entities/jobs.entity.ts index 242a01b..80c2503 100644 --- a/src/database/entities/jobs.entity.ts +++ b/src/database/entities/jobs.entity.ts @@ -137,6 +137,6 @@ export class JobsEntity { @Column({ nullable: true }) content: string; - @OneToMany(() => CandidacyEntity, (candidacy) => candidacy.user) + @OneToMany(() => CandidacyEntity, (candidacy) => candidacy.job) candidacies: CandidacyEntity[]; } From ebdf7d7616e48fc393a42ddc23c905b62455dc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Mon, 7 Oct 2024 18:49:44 -0300 Subject: [PATCH 4/7] =?UTF-8?q?:bug:=20Fix=20(candidacy-entity):=20Padroni?= =?UTF-8?q?za=C3=A7=C3=A3o=20do=20nome=20do=20atributo=20para=20job.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/entities/candidacy.entity.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/entities/candidacy.entity.ts b/src/database/entities/candidacy.entity.ts index aa75082..4a42e6f 100644 --- a/src/database/entities/candidacy.entity.ts +++ b/src/database/entities/candidacy.entity.ts @@ -15,7 +15,7 @@ import { CandidacyStatus } from './candidacy-status.enum'; id: string; @Column('uuid') - vacancyId: string; + jobId: string; @Column('uuid') userId: string; @@ -34,7 +34,7 @@ import { CandidacyStatus } from './candidacy-status.enum'; user: UsersEntity; @ManyToOne(() => JobsEntity) - @JoinColumn({ name: 'vacancyId' }) + @JoinColumn({ name: 'jobId' }) job: JobsEntity; } \ No newline at end of file From b3ad650841e6df6301352c5b70335b99d042d3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Mon, 7 Oct 2024 20:32:19 -0300 Subject: [PATCH 5/7] =?UTF-8?q?:sparkles:=20Feat=20(candidacy-entity,=20ca?= =?UTF-8?q?ndidacy-repository)=20optado=20pelo=20m=C3=A9todo=20findOne=20e?= =?UTF-8?q?=20retirada=20a=20verifica=C3=A7ao=20de=20array=20e=20criado=20?= =?UTF-8?q?o=20m=C3=A9todo=20findByUserId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/entities/candidacy.entity.ts | 1 + .../alert/repository/candidacy.repository.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/database/entities/candidacy.entity.ts b/src/database/entities/candidacy.entity.ts index 4a42e6f..2fdc39e 100644 --- a/src/database/entities/candidacy.entity.ts +++ b/src/database/entities/candidacy.entity.ts @@ -8,6 +8,7 @@ import { import { UsersEntity } from './users.entity'; import { JobsEntity } from './jobs.entity'; import { CandidacyStatus } from './candidacy-status.enum'; + @Entity('tb_candidacies') export class CandidacyEntity { diff --git a/src/modules/alert/repository/candidacy.repository.ts b/src/modules/alert/repository/candidacy.repository.ts index bb2dd87..d46a3ed 100644 --- a/src/modules/alert/repository/candidacy.repository.ts +++ b/src/modules/alert/repository/candidacy.repository.ts @@ -1,9 +1,10 @@ import { Injectable } from '@nestjs/common'; import { Repository } from 'typeorm'; -import { CandidacyEntity } from '../../../database/entities/candidacy.entity'; // Certifique-se de importar a entidade correta +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( @@ -17,15 +18,11 @@ export class CandidacyRepository { async updateStatus(id: string, status: CandidacyStatus): Promise { try { - const candidacies = await this.candidacyRepository.find({ where: { id } }); - - if (candidacies.length === 0) { + const candidacyToUpdate = await this.candidacyRepository.findOne({ where: { id } }); + if (!candidacyToUpdate) { return undefined; } - const candidacyToUpdate = candidacies[0]; - candidacyToUpdate.status = status; - await this.candidacyRepository.save(candidacyToUpdate); return candidacyToUpdate; @@ -34,5 +31,8 @@ export class CandidacyRepository { } } - -} + async findByUserId(userId: string): Promise { + return await this.candidacyRepository.find({ where: { userId } }); + } + +} \ No newline at end of file From b10a1e13693526c16ac51851884209dcf0a2b034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Mon, 14 Oct 2024 19:12:32 -0300 Subject: [PATCH 6/7] =?UTF-8?q?:sparkles:=20Padroniza=C3=A7=C3=A3o=20de=20?= =?UTF-8?q?nome=20dos=20enuns=20para=20ingl=C3=AAs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/entities/candidacy-status.enum.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/database/entities/candidacy-status.enum.ts b/src/database/entities/candidacy-status.enum.ts index 540f0ed..7ab3d6b 100644 --- a/src/database/entities/candidacy-status.enum.ts +++ b/src/database/entities/candidacy-status.enum.ts @@ -1,6 +1,6 @@ export enum CandidacyStatus { - EmAndamento = 'em andamento', - Encerrada = 'encerrada', - SemInteresse = 'sem interesse', + InProgress = 'em andamento', + Closed = 'encerrada', + NoInterest = 'sem interesse', } \ No newline at end of file From 16dc3c166182a73635a97e9f21b41489bc0465d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Zalasik?= Date: Mon, 14 Oct 2024 19:46:10 -0300 Subject: [PATCH 7/7] =?UTF-8?q?:sparkles:=20Feat=20(candidacy.repository):?= =?UTF-8?q?=20Altera=C3=A7=C3=A3o=20no=20tratamento=20de=20erro=20de=20und?= =?UTF-8?q?efined=20para=20console.log=20e=20utiliza=C3=A7=C3=A3o=20do=20t?= =?UTF-8?q?hrow=20new=20Error.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/repository/candidacy.repository.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/alert/repository/candidacy.repository.ts b/src/modules/alert/repository/candidacy.repository.ts index d46a3ed..6655a35 100644 --- a/src/modules/alert/repository/candidacy.repository.ts +++ b/src/modules/alert/repository/candidacy.repository.ts @@ -16,21 +16,26 @@ export class CandidacyRepository { return this.candidacyRepository.save(candidacy); } - async updateStatus(id: string, status: CandidacyStatus): Promise { + async updateStatus(id: string, status: CandidacyStatus): Promise { try { - const candidacyToUpdate = await this.candidacyRepository.findOne({ where: { id } }); + const candidacyToUpdate = await this.candidacyRepository.findOne({ where: { id } }); + if (!candidacyToUpdate) { - return undefined; + 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) { - return undefined; + 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 } }); }