Skip to content
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 (jobs,users,candidacy): Criação da entidade candi… #174

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions src/database/entities/candidacy-status.enum.ts
MikaelMelo1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum CandidacyStatus {
InProgress = 'em andamento',
Closed = 'encerrada',
NoInterest = 'sem interesse',
}

41 changes: 41 additions & 0 deletions src/database/entities/candidacy.entity.ts
MikaelMelo1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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;
}

4 changes: 4 additions & 0 deletions src/database/entities/jobs.entity.ts
MikaelMelo1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -135,4 +136,7 @@ export class JobsEntity {

@Column({ nullable: true })
content: string;

@OneToMany(() => CandidacyEntity, (candidacy) => candidacy.job)
candidacies: CandidacyEntity[];
}
4 changes: 4 additions & 0 deletions src/database/entities/users.entity.ts
MikaelMelo1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;

Expand Down
43 changes: 43 additions & 0 deletions src/modules/alert/repository/candidacy.repository.ts
MikaelMelo1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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<CandidacyEntity>,
) {}

async create(candidacy: CandidacyEntity): Promise<CandidacyEntity> {
return this.candidacyRepository.save(candidacy);
}

async updateStatus(id: string, status: CandidacyStatus): Promise<CandidacyEntity> {
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<CandidacyEntity[]> {
return await this.candidacyRepository.find({ where: { userId } });
}

}
Loading