Skip to content

Commit

Permalink
✨ feat: feat: Criação da service que busca o histórico de vagas com …
Browse files Browse the repository at this point in the history
…base nos filtros.
  • Loading branch information
leticiazalasik committed Nov 9, 2024
1 parent 79fa4d3 commit e5857d4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/modules/alert/service/applicationHistory.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ApplicationEntity } from '../../../database/entities/applications.entity';
import { JobsEntity } from '../../../database/entities/jobs.entity';
@Injectable()
export class ApplicationHistoryService {
constructor(
@InjectRepository(ApplicationEntity)
private applicationsRepository: Repository<ApplicationEntity>,
@InjectRepository(JobsEntity)
private jobsRepository: Repository<JobsEntity>,
) { }
async getApplicationHistory(userId: string, status?: string, page: number = 1, limit: number = 10): Promise<any[]> {
const query = this.applicationsRepository.createQueryBuilder('application')
.where('application.userId = :userId', { userId })
.leftJoinAndSelect('application.job', 'job');
if (status) {
query.andWhere('application.status = :status', { status });
}
query.orderBy('application.createdAt', 'DESC')
.skip((page - 1) * limit)
.take(limit);
const applications = await query.getMany();
return applications.map(application => ({
id: application.id,
jobId: application.job.id,
userId: application.user_id,
status: application.status,
createdAt: application.created_at.toISOString(),
jobTitle: application.job.title,
jobDescription: application.job.description,
}));
}
}

0 comments on commit e5857d4

Please sign in to comment.