mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-05 06:23:22 +00:00
fixed duplicated repo url issue
This commit is contained in:
@@ -332,15 +332,34 @@ router.post('/update', validateApiCredentials, [
|
||||
});
|
||||
}
|
||||
|
||||
// Create host repository relationship
|
||||
await tx.hostRepository.create({
|
||||
data: {
|
||||
hostId: host.id,
|
||||
repositoryId: repo.id,
|
||||
isEnabled: repoData.isEnabled !== false, // Default to enabled
|
||||
lastChecked: new Date()
|
||||
// Create host repository relationship (handle duplicates gracefully)
|
||||
try {
|
||||
await tx.hostRepository.create({
|
||||
data: {
|
||||
hostId: host.id,
|
||||
repositoryId: repo.id,
|
||||
isEnabled: repoData.isEnabled !== false, // Default to enabled
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user