Files
lincodex/backend/db/queries/contact_grants.sql
T

46 lines
1.2 KiB
SQL

-- Store the contact grant of an acceptance. The row is inserted in the same
-- transaction as its C4 consent record and the accepted state; the database
-- checks that the record, the invitation, and the candidate agree.
-- name: InsertContactGrant :exec
INSERT INTO contact_grants (
id,
organization_id,
candidate_id,
source_invitation_id,
consent_record_id,
terms_version,
fields,
consent_text_version,
granted_at
) VALUES (
sqlc.arg(id),
sqlc.arg(organization_id),
sqlc.arg(candidate_id),
sqlc.arg(source_invitation_id),
sqlc.arg(consent_record_id),
sqlc.arg(terms_version),
sqlc.arg(fields)::text [],
sqlc.arg(consent_text_version),
sqlc.arg(granted_at)
);
-- Read the grant of one invitation of one organization. An invitation of
-- another organization finds nothing.
-- name: GetContactGrantByInvitation :one
SELECT
id,
organization_id,
candidate_id,
source_invitation_id,
consent_record_id,
terms_version,
fields,
consent_text_version,
granted_at,
revoked_at,
revocation_reason
FROM contact_grants
WHERE
organization_id = sqlc.arg(organization_id)
AND source_invitation_id = sqlc.arg(invitation_id);