database: create notification during vulnerability insertion

This commit is contained in:
Quentin Machu 2016-01-23 22:02:51 -05:00 committed by Jimmy Zelinskie
parent baed60e19b
commit 2690800331

View File

@ -196,12 +196,6 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability) er
tx.Rollback()
return handleError("i_vulnerability", err)
}
// Create NewVulnerabilityNotification.
notification := database.VulnerabilityNotification{NewVulnerability: vulnerability}
if err := pgSQL.insertNotification(tx, notification); err != nil {
return err
}
} else {
// Update vulnerability
if vulnerability.Description != existingVulnerability.Description ||
@ -228,6 +222,22 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability) er
return err
}
// Create notification.
var notification database.VulnerabilityNotification
if existingVulnerability.ID == 0 {
notification = database.VulnerabilityNotification{
NewVulnerability: vulnerability,
}
} else {
notification = database.VulnerabilityNotification{
OldVulnerability: &existingVulnerability,
NewVulnerability: vulnerability,
}
}
if err := pgSQL.insertNotification(tx, notification); err != nil {
return err
}
// Commit transaction.
err = tx.Commit()
if err != nil {