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
12 changes: 5 additions & 7 deletions src/import-xml/import-xml.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, HttpException, HttpStatus, Param, Post, Query, Res, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { Controller, Get, Param, Post, Query, Res, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { AnyFilesInterceptor } from '@nestjs/platform-express';
import { ApiOAuth2, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
Expand Down Expand Up @@ -77,17 +77,15 @@ export class ImportXmlController {
status: 200,
description: 'Imports the Lattes CVs of all professors',
})
@Post('professors/lattes/import')
async importAllProfessors(@AuthenticatedUser() user: any, @Res() res: Response) {
@Post('update-all')
async updateProfessors(@AuthenticatedUser() user: any, @Res() res: Response) {
const username = `${user.name} (${user.email})`;
const professorsCount = await this.professorService.count();

if (professorsCount === 0) {
throw new HttpException('Nenhum professor encontrado', HttpStatus.NOT_FOUND);
if (professorsCount > 0) {
this.importXmlService.executeBackgroundProfessorsUpdate(username);
}

this.importXmlService.executeBackgroundProfessorsUpdate(username);

return res.status(200).json({ professorsCount });
}

Expand Down
8 changes: 4 additions & 4 deletions src/import-xml/import-xml.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ImportXmlService {
if (extname(file.originalname) === '.zip') {
await this.unzipFile(file);
xmlData = await readFile(this.XML_PATH + '/' + file.originalname.split('.')[0] + '.xml', {
encoding: 'latin1',
encoding: 'utf8',
});
} else {
try {
Expand All @@ -209,7 +209,7 @@ export class ImportXmlService {
}

xmlData = await readFile(this.XML_PATH + '/' + file.originalname, {
encoding: 'latin1',
encoding: 'utf8',
});
}
const object = await parseStringPromise(xmlData);
Expand Down Expand Up @@ -1585,7 +1585,7 @@ export class ImportXmlService {
}
}

await this.enqueueFiles(tempFiles, username || 'atualizado automaticamente')
await this.enqueueFiles(tempFiles, username ?? 'Sistema')
} catch (error) {
await logErrorToDatabase(error, EntityType.IMPORT);
throw error;
Expand All @@ -1595,7 +1595,7 @@ export class ImportXmlService {
async importProfessorById(identifier: string, username: string): Promise<void> {
try {
const tempFile = await this.processProfessorData(identifier, username);
await this.enqueueFiles([tempFile], username || 'atualizado automaticamente');
await this.enqueueFiles([tempFile], username ?? 'Sistema');
} catch (error) {
await logErrorToDatabase(error, EntityType.IMPORT);
throw error;
Expand Down