Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/import-xml/import-xml.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ export class ImportXmlService {

renameFile = (oldPath: string, newPath: string) => {
return new Promise((resolve, reject) => {
fs.rename(oldPath, newPath, (err) => {
fs.rename(oldPath, newPath, err => {
if (err) {
console.error('Error occurred during file renaming:', err);
reject(err);
Expand Down Expand Up @@ -1364,7 +1364,7 @@ export class ImportXmlService {
await queryRunner.release();
}

this.insertDataToDatabase(files, username).catch((err) => {
this.insertDataToDatabase(files, username).catch(err => {
logErrorToDatabase(err, EntityType.XML, undefined);
});
}
Expand Down
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;
}
12 changes: 12 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 @@ -117,6 +118,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> {
return this.professorService.getExecutedActivities(lattes);
}

@ApiResponse({
status: 200,
description: 'Delete professor.',
Expand Down
34 changes: 33 additions & 1 deletion src/professor/professor.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { AppDataSource } from 'src/app.datasource';
import { Curriculum } from 'src/import-xml/curriculum.enum';
import { ProfessorPatentDto } from 'src/patents/dto/professor-patent.dto';
Expand Down Expand Up @@ -98,6 +98,38 @@ 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();

if (!result) {
throw new NotFoundException('Professor not found');
}

return result;
}

update(id: number, updateProfessorDto: UpdateProfessorDto) {
return `This action updates a #${id} professor`;
}
Expand Down
1 change: 1 addition & 0 deletions xmls/7188784344595649.xml

Large diffs are not rendered by default.