fixed duplicated repo url issue

This commit is contained in:
Muhammad Ibrahim
2025-09-19 15:59:45 +01:00
parent 51d6dd63b1
commit 6bc4316fbc
2 changed files with 28 additions and 8 deletions

1
.gitignore vendored
View File

@@ -143,3 +143,4 @@ manage-patchmon.sh
setup-installer-site.sh
install-server.*
notify-clients-upgrade.sh
debug-agent.sh

View File

@@ -332,7 +332,8 @@ router.post('/update', validateApiCredentials, [
});
}
// Create host repository relationship
// Create host repository relationship (handle duplicates gracefully)
try {
await tx.hostRepository.create({
data: {
hostId: host.id,
@@ -341,6 +342,24 @@ router.post('/update', validateApiCredentials, [
lastChecked: new Date()
}
});
} catch (error) {
// If it's a duplicate constraint error, update the existing record
if (error.code === 'P2002') {
await tx.hostRepository.updateMany({
where: {
hostId: host.id,
repositoryId: repo.id
},
data: {
isEnabled: repoData.isEnabled !== false,
lastChecked: new Date()
}
});
} else {
// Re-throw other errors
throw error;
}
}
}
}
});