Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function bootstrap() {

await AppDataSource.initialize()
.then(() => console.log('LOG [Typeorm] Success connection'))
.catch((error) => console.log(error));
.catch(error => console.log(error));

const document = SwaggerModule.createDocument(app, config);

Expand Down
16 changes: 16 additions & 0 deletions src/professor/dto/executed-activities.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ApiTags, ApiProperty } from '@nestjs/swagger';

@ApiTags('ExecutedActivitiesDto')
export class ExecutedActivitiesDto {
@ApiProperty({ name: 'projects', type: Boolean })
projects!: boolean;

@ApiProperty({ name: 'publications', type: Boolean })
publications!: boolean;

@ApiProperty({ name: 'supervisions', type: Boolean })
supervisions!: boolean;

@ApiProperty({ name: 'patents', type: Boolean })
patents!: boolean;
}
29 changes: 29 additions & 0 deletions src/professor/professor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ProfessorPublicationsDto } from './dto/professor-publications.dto';
import { ProfessorTableDto } from './dto/professor-table.dto';
import { Professor } from './entities/professor.entity';
import { ProfessorService } from './professor.service';
import { ExecutedActivitiesDto } from './dto/executed-activities.dto';

@Roles({ roles: [SystemRoles.USERS] })
@ApiTags('Professor Module')
Expand Down Expand Up @@ -95,6 +96,23 @@ export class ProfessorController {
return this.professorService.getStudents(filter, id, lattes);
}

@ApiResponse({
status: 200,
description: 'Returns professor supervisions.',
isArray: true,
type: AdviseeFormatDto,
})
@Get('professor-supervisions')
getProfessorSupervisions(
@Query('lattes', new ValidationPipe({ transform: true })) lattes: string,
): Promise<AdviseeFormatDto[]> {
if (!lattes) {
throw new Error('Lattes precisa ser informado.');
}

return this.professorService.getProfessorSupervisions(lattes);
}
Comment thread
eliseucbrito marked this conversation as resolved.
Outdated

@ApiResponse({
status: 200,
description: 'Returns professor projects.',
Expand All @@ -117,6 +135,17 @@ export class ProfessorController {
return this.professorService.getPatents(id, lattes);
}

@ApiResponse({
status: 200,
description: 'Returns activities the professor executed.',
isArray: false,
type: ExecutedActivitiesDto,
})
@Get('executed-activities')
getExecutedActivities(@Query() { lattes }: { lattes: string }): Promise<ExecutedActivitiesDto> {
Comment thread
eliseucbrito marked this conversation as resolved.
Outdated
return this.professorService.getExecutedActivities(lattes);
}

@ApiResponse({
status: 200,
description: 'Delete professor.',
Expand Down
38 changes: 38 additions & 0 deletions src/professor/professor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,44 @@ export class ProfessorService {
return result;
}

async getExecutedActivities(lattes: string) {
const result = await AppDataSource.createQueryBuilder()
.select([
`CASE WHEN EXISTS (
SELECT 1 FROM "project" pr WHERE pr.professor_id = p.id
) THEN true ELSE false END AS projects`,

`CASE WHEN EXISTS (
SELECT 1 FROM "conference_publication" cp WHERE cp.professor_id = p.id
) OR EXISTS (
SELECT 1 FROM "journal_publication" jp WHERE jp.professor_id = p.id
) THEN true ELSE false END AS publications`,

`CASE WHEN EXISTS (
SELECT 1 FROM "advisee" a WHERE a.professor_id = p.id
) THEN true ELSE false END AS supervisions`,

`CASE WHEN EXISTS (
SELECT 1 FROM "patent" pt WHERE pt.professor_id = p.id
) THEN true ELSE false END AS patents`,
])
.from('professor', 'p')
.where('p.identifier = :identifier', { identifier: lattes })
.getRawOne();

return result;
}

async getProfessorSupervisions(lattes: string) {
const result = await AppDataSource.getRepository(Advisee)
.createQueryBuilder('a')
.innerJoin('a.professor', 'p')
.where('p.identifier = :identifier', { identifier: lattes })
.getMany();

return result;
}
Comment thread
eliseucbrito marked this conversation as resolved.
Outdated

update(id: number, updateProfessorDto: UpdateProfessorDto) {
return `This action updates a #${id} professor`;
}
Expand Down