Skip to content

Commit

Permalink
fix: dont ovewrite category
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Aug 19, 2024
1 parent 3f107b0 commit 98e15a9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions apps/core/src/modules/NextUser/history/handlers/createHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function createHistory(
}

const hydratedComponentsPromises = studentHistory.components.map(
(component) => hydrateComponents(component),
(component) => hydrateComponents(component, studentHistory.ra),
);
const hydratedComponents = await Promise.all(hydratedComponentsPromises);
const course = transformCourseName(
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function createHistory(
};
}

async function hydrateComponents(component: StudentComponent) {
async function hydrateComponents(component: StudentComponent, ra: number) {
const subjects = await SubjectModel.find({
creditos: {
$exists: true,
Expand All @@ -123,6 +123,15 @@ async function hydrateComponents(component: StudentComponent) {
return;
}

const existingHistory = await HistoryModel.findOne({ ra });
let category = null;
if (existingHistory) {
const existingComponents = existingHistory.disciplinas.find(
(disciplina) => disciplina.codigo === component.codigo,
);
category = existingComponents?.categoria ?? null;
}

return {
conceito: component.resultado === '--' ? null : component.resultado,
periodo: component.periodo,
Expand All @@ -131,5 +140,6 @@ async function hydrateComponents(component: StudentComponent) {
codigo: component.codigo,
creditos: validComponent.credits,
disciplina: validComponent.name,
categoria: category,
};
}

0 comments on commit 98e15a9

Please sign in to comment.