Skip to content

Commit 8e085bf

Browse files
committed
fix: remove unregistered pisciners from piscine overview
1 parent 2432c47 commit 8e085bf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/intra/cursus.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ export const syncCursus = async function(api: Fast42, syncDate: Date): Promise<v
170170
console.error(`Error updating cursus_user ${cursusUser.user.login} - ${cursusUser.cursus.name}: ${err}`);
171171
}
172172
}
173+
174+
// Find the cursus_users that were not returned by the API
175+
// This can happen if a pisciner unregistered from the piscine through Apply
176+
const missingCursusUsers = chunk.filter(cursusUser => !ongoingPiscineCursusesAPI.find(cursusUserAPI => cursusUserAPI.id === cursusUser.id));
177+
for (const missingCursusUser of missingCursusUsers) {
178+
console.warn(`Cursus_user ${missingCursusUser.id} of user ${missingCursusUser.user_id} was not returned by the API. Removing it from the database.`);
179+
await prisma.cursusUser.delete({
180+
where: {
181+
id: missingCursusUser.id,
182+
},
183+
});
184+
}
173185
}
174186

175187
// Mark synchronization as complete by updating the last_synced_at field

0 commit comments

Comments
 (0)