Skip to content

Commit

Permalink
Merge pull request #8 from CinCoders/develop
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
dcruzb authored Nov 1, 2023
2 parents 6414a39 + b7d502f commit 158d14d
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 196 deletions.
4 changes: 4 additions & 0 deletions docs/USAGE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Then, you aditionally will put the client_id of your Keycloak realm (there's no
### Being enabled to test the API

After that, you will have the authorization to make requests and check the responses.

## Checking the downloaded XML paths

Update the current XML_PATH to the desired folder
423 changes: 256 additions & 167 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 37 additions & 13 deletions src/import-xml/import-xml.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export class ImportXmlService {
}

async updateXMLStatus(
filename: string,
id: string,
filename: string | undefined,
status: string,
professorName: string | undefined,
) {
Expand All @@ -117,7 +118,11 @@ export class ImportXmlService {
break;
}
case Status.PROGRESS: {
importXml = { status: status, professorName: professorName };
importXml = {
status: status,
professorName: professorName,
name: filename,
};
break;
}
case Status.CONCLUDED:
Expand All @@ -129,7 +134,7 @@ export class ImportXmlService {
await AppDataSource.createQueryBuilder()
.update(ImportXml)
.set(importXml)
.where('id=:name', { name: filename })
.where('id=:name', { name: id })
.execute();
}

Expand All @@ -146,10 +151,8 @@ export class ImportXmlService {
);
} else {
try {
await rename(
file.path,
this.XML_PATH + '/' + file.originalname.split('.')[0],
);
await rename(file.path, this.XML_PATH + '/' + file.originalname);
file.path = this.XML_PATH + '/' + file.originalname;
} catch (error) {
if (error instanceof Error) {
throw Error(
Expand All @@ -159,10 +162,9 @@ export class ImportXmlService {
throw Error('The file could not be renamed.');
}

xmlData = await readFile(
this.XML_PATH + '/' + file.originalname.split('.')[0],
{ encoding: 'latin1' },
);
xmlData = await readFile(this.XML_PATH + '/' + file.originalname, {
encoding: 'latin1',
});
}
const object = await parseStringPromise(xmlData);
return JSON.parse(JSON.stringify(object));
Expand Down Expand Up @@ -1052,6 +1054,9 @@ export class ImportXmlService {
this.XML_PATH + '/' + 'curriculo.xml',
this.XML_PATH + '/' + file.originalname.split('.')[0] + '.xml',
);
unlink(zipPath);
file.path =
this.XML_PATH + '/' + file.originalname.split('.')[0] + '.xml';
} catch (err) {
await logErrorToDatabase(err, EntityType.UNZIP, undefined);
}
Expand Down Expand Up @@ -1099,6 +1104,8 @@ export class ImportXmlService {
const importXml = new ImportXml();
importXml.id = files[i].filename;
importXml.name = files[i].originalname;
// importXml.originalfilename = files[i].originalname;
// importXml.filename = '';
importXml.user = username;
importXml.status = Status.PENDING;
importXml.startedAt = undefined;
Expand Down Expand Up @@ -1139,7 +1146,12 @@ export class ImportXmlService {
for (let i = 0; i < files.length; i++) {
await queryRunner.startTransaction();
try {
this.updateXMLStatus(files[i].filename, Status.LOADING, undefined);
this.updateXMLStatus(
files[i].filename,
undefined,
Status.LOADING,
undefined,
);
let importXmlLog = this.createImportLog(
files[i],
username,
Expand All @@ -1151,8 +1163,18 @@ export class ImportXmlService {

// se o professor não existir, criamos, se existir podemos usá-lo
professorDto = this.getProfessorData(json);
// renomear com o lattes do professor

await rename(
files[i].path,
this.XML_PATH + '/' + professorDto.identifier + '.xml',
);

const filename = professorDto.identifier + '.xml';

this.updateXMLStatus(
files[i].filename,
filename,
Status.PROGRESS,
professorDto.name,
);
Expand Down Expand Up @@ -1203,13 +1225,15 @@ export class ImportXmlService {
importXmlLog.message += 'SUCCESS';
this.updateXMLStatus(
files[i].filename,
filename,
Status.CONCLUDED,
professorDto.name,
);
} catch (err) {
importXmlLog.message += 'FAILED';
this.updateXMLStatus(
files[i].filename,
undefined,
Status.NOT_IMPORTED,
professorDto?.name,
);
Expand All @@ -1224,7 +1248,7 @@ export class ImportXmlService {
}
}
} finally {
queryRunner.release();
await queryRunner.release();
}
}
}
32 changes: 20 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ import { AppDataSource } from './app.datasource';
async function bootstrap() {
let options = {};
if (process.env.NODE_ENV === 'production') {
let httpsOptions = {};
httpsOptions = {
key: fs.readFileSync(
path.join(__dirname, '..', './certs/certificate.key'),
),
cert: fs.readFileSync(
path.join(__dirname, '..', './certs/certificate.crt'),
),
ca: fs.readFileSync(
path.join(__dirname, '..', './certs/intermediate.pem'),
),
};
const httpsOptions: {
key?: Buffer | null;
cert?: Buffer | null;
ca?: Buffer | null;
} = {};

httpsOptions.key = fs.readFileSync(
path.join(__dirname, '..', './certs/certificate.key'),
);
httpsOptions.cert = fs.readFileSync(
path.join(__dirname, '..', './certs/certificate.crt'),
);
const caCertificatePath = path.join(
__dirname,
'..',
'./certs/intermediate.pem',
);
if (fs.existsSync(caCertificatePath)) {
httpsOptions.ca = fs.readFileSync(caCertificatePath);
}
options = { ...options, httpsOptions };
}

Expand Down
2 changes: 1 addition & 1 deletion src/post-graduation/post-graduation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class PostGraduationService {

await queryRunner.connect();

const result = queryRunner.query(`
const result = await queryRunner.query(`
SELECT
${groupByProfessor ? 'p.id as "professorId",' : ''}
${groupByProfessor ? 'p.name as "professorName",' : ''}
Expand Down
2 changes: 1 addition & 1 deletion src/professor/professor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ProfessorService {

const queryRunner = AppDataSource.createQueryRunner();

const result = queryRunner.query(
const result = await queryRunner.query(
`
${
journalPublications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ export class JournalPublicationService {
if (journal.issn === journalPublication.issn) {
journalPublication.journal = journal;
journalPublication.qualis = journal.qualis;

if (journal.isTop) {
journalPublication.isTop = true;
}

await AppDataSource.createQueryBuilder(queryRunner)
.insert()
.into(JournalPublication)
.values(journalPublication)
.orUpdate(['qualis', 'journal_id'], ['id'])
.orUpdate(['qualis', 'journal_id', 'is_top'], ['id'])
.execute();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/professor/services/conference/conference.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ConferencePublicationService {
.into(ConferencePublication)
.values(conferencePublication)
.orUpdate(
['title', 'proceedings', 'qualis', 'conference_id'],
['title', 'proceedings', 'qualis', 'conference_id', 'is_top'],
['id'],
)
.execute();
Expand Down

0 comments on commit 158d14d

Please sign in to comment.