pub async fn update_certificate(
conn: &mut PgConnection,
certificate_id: Uuid,
date_issued: DateTime<Utc>,
name_on_certificate: Option<String>,
expected_updated_at: Option<DateTime<Utc>>,
) -> ModelResult<Option<GeneratedCertificate>>Expand description
Rewrites what an issued certificate prints: its holder-facing name and the date it is dated.
The issue date is created_at, which is the column the certificate and every listing of it
read, so date_issued is written unconditionally; pass the row’s current value to leave it be.
name_on_certificate of None leaves the name as it is.
expected_updated_at makes this a compare-and-swap: pass the updated_at of the row the
caller read and the write lands only if nothing has touched the row since, returning None
when something has. None skips the check, for a caller with no earlier read to protect.
Without it a name-only update silently restores the date another admin had just corrected.