feat(invitations): let candidates read, view and decline their invitations
This commit is contained in:
1 parent
c410636b7f
commit
ac57c05aca
27 files changed
+3285
-21
No files matched your search
@@ -0,0 +1,129 @@
|
||||
-- Read one delivered invitation addressed to the candidate with the current
|
||||
-- name of the organization that sent it. A draft and an invitation of
|
||||
-- another candidate find nothing.
|
||||
-- name: ReadCandidateInvitationEntry :one
|
||||
SELECT
|
||||
invitation.id,
|
||||
invitation.organization_id,
|
||||
invitation.candidate_id,
|
||||
invitation.need_id,
|
||||
invitation.need_requirements_version,
|
||||
invitation.state,
|
||||
invitation.expiry_reason,
|
||||
invitation.version,
|
||||
invitation.terms_version,
|
||||
invitation.response_period_days,
|
||||
invitation.policy_version_id,
|
||||
invitation.response_deadline_at,
|
||||
invitation.salary_raise_used,
|
||||
invitation.created_by,
|
||||
invitation.created_at,
|
||||
invitation.updated_at,
|
||||
invitation.delivered_at,
|
||||
invitation.viewed_at,
|
||||
invitation.responded_at,
|
||||
terms.terms::text AS terms,
|
||||
organization.name AS organization_name
|
||||
FROM invitations AS invitation
|
||||
INNER JOIN invitation_terms_versions AS terms
|
||||
ON terms.invitation_id = invitation.id
|
||||
AND terms.version = invitation.terms_version
|
||||
INNER JOIN organizations AS organization
|
||||
ON organization.id = invitation.organization_id
|
||||
WHERE
|
||||
invitation.candidate_id = sqlc.arg(candidate_id)
|
||||
AND invitation.id = sqlc.arg(invitation_id)
|
||||
AND invitation.delivered_at IS NOT NULL;
|
||||
|
||||
-- Lock one delivered invitation addressed to the candidate. Only the
|
||||
-- invitation row is locked, never the organization.
|
||||
-- name: LockCandidateInvitation :one
|
||||
SELECT id
|
||||
FROM invitations
|
||||
WHERE
|
||||
candidate_id = sqlc.arg(candidate_id)
|
||||
AND id = sqlc.arg(invitation_id)
|
||||
AND delivered_at IS NOT NULL
|
||||
FOR UPDATE;
|
||||
|
||||
-- The compare-and-swap of the first view: it applies only to a delivered
|
||||
-- invitation at the version the caller read and before its deadline, and it
|
||||
-- keeps the deadline.
|
||||
-- name: RecordInvitationView :one
|
||||
UPDATE invitations
|
||||
SET
|
||||
state = 'viewed',
|
||||
version = sqlc.arg(next_version),
|
||||
viewed_at = sqlc.arg(viewed_at),
|
||||
updated_at = sqlc.arg(viewed_at)
|
||||
WHERE
|
||||
organization_id = sqlc.arg(organization_id)
|
||||
AND id = sqlc.arg(invitation_id)
|
||||
AND state = 'delivered'
|
||||
AND version = sqlc.arg(expected_version)
|
||||
AND response_deadline_at > sqlc.arg(viewed_at)
|
||||
AND sqlc.arg(next_version)::bigint = sqlc.arg(expected_version)::bigint + 1
|
||||
RETURNING id;
|
||||
|
||||
-- The compare-and-swap of a decline: it applies only to an answerable
|
||||
-- invitation at the version the caller read and before its deadline.
|
||||
-- name: DeclineInvitation :one
|
||||
UPDATE invitations
|
||||
SET
|
||||
state = 'declined',
|
||||
version = sqlc.arg(next_version),
|
||||
responded_at = sqlc.arg(declined_at),
|
||||
updated_at = sqlc.arg(declined_at)
|
||||
WHERE
|
||||
organization_id = sqlc.arg(organization_id)
|
||||
AND id = sqlc.arg(invitation_id)
|
||||
AND state IN ('delivered', 'viewed', 'counter')
|
||||
AND version = sqlc.arg(expected_version)
|
||||
AND response_deadline_at > sqlc.arg(declined_at)
|
||||
AND sqlc.arg(next_version)::bigint = sqlc.arg(expected_version)::bigint + 1
|
||||
RETURNING id;
|
||||
|
||||
-- name: InsertInvitationDecline :exec
|
||||
INSERT INTO invitation_declines (
|
||||
invitation_id,
|
||||
organization_id,
|
||||
reason,
|
||||
comment,
|
||||
declined_at
|
||||
) VALUES (
|
||||
sqlc.arg(invitation_id),
|
||||
sqlc.arg(organization_id),
|
||||
sqlc.arg(reason),
|
||||
sqlc.narg(comment),
|
||||
sqlc.arg(declined_at)
|
||||
);
|
||||
|
||||
-- name: ReadInvitationDecline :one
|
||||
SELECT
|
||||
invitation_id,
|
||||
organization_id,
|
||||
reason,
|
||||
comment,
|
||||
declined_at
|
||||
FROM invitation_declines
|
||||
WHERE
|
||||
organization_id = sqlc.arg(organization_id)
|
||||
AND invitation_id = sqlc.arg(invitation_id);
|
||||
|
||||
-- name: InsertInvitationDeclineResult :exec
|
||||
INSERT INTO invitation_decline_results (
|
||||
scope_hash,
|
||||
invitation_id,
|
||||
outcome
|
||||
) VALUES (
|
||||
sqlc.arg(scope_hash),
|
||||
sqlc.arg(invitation_id),
|
||||
sqlc.arg(outcome)
|
||||
);
|
||||
|
||||
-- name: GetInvitationDeclineResult :one
|
||||
SELECT
|
||||
invitation_id,
|
||||
outcome
|
||||
FROM invitation_decline_results
|
||||
WHERE scope_hash = sqlc.arg(scope_hash);
|
||||
Reference in new issue
Block a user