Skip to content

Commit

Permalink
fix: remove unregistered pisciners from piscine overview
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekBes committed Aug 16, 2024
1 parent 2432c47 commit 8e085bf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/intra/cursus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ export const syncCursus = async function(api: Fast42, syncDate: Date): Promise<v
console.error(`Error updating cursus_user ${cursusUser.user.login} - ${cursusUser.cursus.name}: ${err}`);
}
}

// Find the cursus_users that were not returned by the API
// This can happen if a pisciner unregistered from the piscine through Apply
const missingCursusUsers = chunk.filter(cursusUser => !ongoingPiscineCursusesAPI.find(cursusUserAPI => cursusUserAPI.id === cursusUser.id));
for (const missingCursusUser of missingCursusUsers) {
console.warn(`Cursus_user ${missingCursusUser.id} of user ${missingCursusUser.user_id} was not returned by the API. Removing it from the database.`);
await prisma.cursusUser.delete({
where: {
id: missingCursusUser.id,
},
});
}
}

// Mark synchronization as complete by updating the last_synced_at field
Expand Down

0 comments on commit 8e085bf

Please sign in to comment.