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

Publications start and end years filter [RES-15] #22

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions downloadedFiles/xmls/7188784344595649.xml
karensamara marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/post-graduation/post-graduation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ export class PostGraduationController {
@Query('groupByProfessor', ParseBoolPipe) groupByProfessor: boolean,
@Query('groupByYear', ParseBoolPipe) groupByYear: boolean,
@Query('filter') filter: 'current' | 'concluded',
@Query('startYear') startYear: number,
@Query('endYear') endYear: number,
): Promise<StudentsDto[]> {
return await this.postGraduationService.get(
groupByProfessor,
groupByYear,
filter,
startYear,
endYear,
);
}
}
7 changes: 5 additions & 2 deletions src/post-graduation/post-graduation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class PostGraduationService {
groupByProfessor: boolean,
groupByYear: boolean,
filter: 'current' | 'concluded',
startYear: number,
endYear: number,
) {
const queryRunner = AppDataSource.createQueryRunner();

Expand All @@ -29,14 +31,15 @@ export class PostGraduationService {
LEFT JOIN advisee a ON a.professor_id=p.id
${
filter === 'concluded'
? 'WHERE a.year_start IS NULL AND a.year_end IS NOT NULL'
? ` WHERE a.year_start IS NULL AND a.year_end IS NOT NULL AND a.year_end >= ${startYear} AND a.year_end <= ${endYear}`
karensamara marked this conversation as resolved.
Show resolved Hide resolved
: ''
}
${
filter === 'current'
? 'WHERE a.year_end IS NULL AND a.year_start IS NOT NULL'
? ` WHERE a.year_end IS NULL AND a.year_start IS NOT NULL AND a.year_start >= ${startYear} AND a.year_start <= ${endYear}`
: ''
}

${
groupByProfessor && groupByYear
? 'GROUP BY p.id, year ORDER BY p.name ASC, year DESC;'
Expand Down
17 changes: 15 additions & 2 deletions src/projects/projects.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Controller, Get, ParseBoolPipe, Query } from '@nestjs/common';
import {
Controller,
Get,
ParseBoolPipe,
ParseIntPipe,
Query,
} from '@nestjs/common';
import { ApiOAuth2, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Roles } from 'nest-keycloak-connect';
import { SystemRoles } from 'src/types/enums';
Expand All @@ -25,7 +31,14 @@ export class ProjectsController {
async get(
@Query('groupByProfessor', ParseBoolPipe) groupByProfessor: boolean,
@Query('groupByYear', ParseBoolPipe) groupByYear: boolean,
@Query('startYear', ParseIntPipe) startYear: number,
@Query('endYear', ParseIntPipe) endYear: number,
): Promise<ProjectsDto[]> {
return await this.projectsService.get(groupByProfessor, groupByYear);
return await this.projectsService.get(
groupByProfessor,
groupByYear,
startYear,
endYear,
);
}
}
4 changes: 4 additions & 0 deletions src/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class ProjectsService {
async get(
groupByProfessor: boolean,
groupByYear: boolean,
startYear: number,
endYear: number,
): Promise<ProjectsDto[]> {
const queryRunner = AppDataSource.createQueryRunner();

Expand All @@ -30,6 +32,8 @@ export class ProjectsService {
LEFT JOIN project_financier pf ON pf.project_id=pr.id
LEFT JOIN financier f ON pf.financier_id=f.id
WHERE pr.year IS NOT NULL
AND pr.year >= ${startYear}
AND pr.year <= ${endYear}
${
groupByProfessor && groupByYear
? 'GROUP BY p.id, pr.year ORDER BY p.name ASC, pr.year DESC;'
Expand Down
12 changes: 11 additions & 1 deletion src/publications/publications.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Controller, Get, ParseBoolPipe, Query } from '@nestjs/common';
import {
Controller,
Get,
ParseBoolPipe,
ParseIntPipe,
Query,
} from '@nestjs/common';
import { ApiOAuth2, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Roles } from 'nest-keycloak-connect';
import { SystemRoles } from 'src/types/enums';
Expand Down Expand Up @@ -26,12 +32,16 @@ export class PublicationsController {
@Query('groupByYear', ParseBoolPipe) groupByYear: boolean,
@Query('articles', ParseBoolPipe) articles: boolean,
@Query('conferences', ParseBoolPipe) conferences: boolean,
@Query('startYear', ParseIntPipe) startYear: number,
@Query('endYear', ParseIntPipe) endYear: number,
): Promise<PublicationsDto[]> {
return await this.publicationsService.get(
articles,
conferences,
groupByProfessor,
groupByYear,
startYear,
endYear,
);
}
}
13 changes: 12 additions & 1 deletion src/publications/publications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class PublicationsService {
conferencePublications: boolean,
groupByProfessor: boolean,
groupByYear: boolean,
startYear: number,
endYear: number,
) {
const selectPublications = `
SELECT
Expand Down Expand Up @@ -60,16 +62,21 @@ export class PublicationsService {
FROM "professor" "p"
`;

const whereClause = ` WHERE pp.year >= ${startYear} AND pp.year <= ${endYear}`;

const groupBy =
(groupByProfessor && groupByYear ? ` GROUP BY p.name, p.id, year` : '') +
(groupByProfessor && !groupByYear ? ` GROUP BY p.name, p.id` : '') +
(!groupByProfessor && groupByYear ? ` GROUP BY year` : '');

const joinJournalPublications =
`JOIN "journal_publication" "pp" on "pp"."professor_id"=p.id` + groupBy;
`JOIN "journal_publication" "pp" on "pp"."professor_id"=p.id` +
whereClause +
groupBy;

const joinConferencePublications =
`JOIN "conference_publication" "pp" on "pp"."professor_id"=p.id` +
whereClause +
groupBy;

return (
Expand Down Expand Up @@ -102,6 +109,8 @@ export class PublicationsService {
conferencePublications: boolean,
groupByProfessor: boolean,
groupByYear: boolean,
startYear: number,
endYear: number,
) {
if (!journalPublications && !conferencePublications) return [];

Expand All @@ -115,6 +124,8 @@ export class PublicationsService {
conferencePublications,
groupByProfessor,
groupByYear,
startYear,
endYear,
),
);

Expand Down