Skip to content

Commit c2a8471

Browse files
committed
fix: delete local intra_title_user when it doesn't exist on Intra
1 parent 5f3aa7f commit c2a8471

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/sync/titles.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,21 @@ export const syncTitles = async function(api: Fast42): Promise<void> {
8383
},
8484
});
8585
if (!patch.ok) {
86-
console.error(`Failed to update Intra user ${rankings[i].user.login} with title ID ${titleRecord.intra_title_id}, HTTP status ${patch.status} ${patch.statusText}`);
86+
if (patch.status == 404) {
87+
console.warn(`Intra title_user ID ${existingTitleUser.intra_title_user_id} for user ${rankings[i].user.login} not found on Intra. It may have been deleted manually. Removing intra_title_user_id from database... Next sync will recreate it.`);
88+
// Remove intra_title_user_id so it can be recreated
89+
await prisma.codamCoalitionTitleUser.update({
90+
where: {
91+
id: existingTitleUser.id,
92+
},
93+
data: {
94+
intra_title_user_id: null,
95+
},
96+
});
97+
}
98+
else {
99+
console.error(`Failed to update Intra user ${rankings[i].user.login} with title ID ${titleRecord.intra_title_id}, HTTP status ${patch.status} ${patch.statusText}`);
100+
}
87101
}
88102
} else {
89103
// User hasn't had a coalition title on Intra yet, create it

0 commit comments

Comments
 (0)