feat(profile): persist candidate edits and enforce company access

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 14:15:16 +03:00
1 parent 3ab6bd91a3
commit 73c7caa225
67 files changed
+5286 -229

No files matched your search

+76 -1
View File
@@ -60,7 +60,28 @@ SELECT
candidate_profile_claims.trust_level,
candidate_profile_claims.quote,
candidate_profile_claims.extraction_version,
candidate_profile_claims.confirmed_at
candidate_profile_claims.confirmed_at,
COALESCE(
(
SELECT jsonb_agg(
jsonb_build_object(
'first_index', confirmations.first_index,
'second_index', confirmations.second_index,
'first_period', jsonb_build_object(
'started_on', confirmations.first_started_on,
'ended_on', confirmations.first_ended_on
),
'second_period', jsonb_build_object(
'started_on', confirmations.second_started_on,
'ended_on', confirmations.second_ended_on
)
) ORDER BY confirmations.first_index, confirmations.second_index
)::text
FROM candidate_profile_overlap_confirmations AS confirmations
WHERE confirmations.user_id = candidate_profiles.user_id
),
'[]'::text
)::text AS parallel_period_acknowledgements
FROM candidate_profiles
LEFT JOIN candidate_profile_claims
ON candidate_profile_claims.user_id = candidate_profiles.user_id
@@ -100,3 +121,57 @@ INSERT INTO candidate_profile_claims (
sqlc.narg(extraction_version),
sqlc.narg(confirmed_at)
);
-- Replaces the current explicit decisions with those in the new profile.
-- The versioned profile row is advanced first in this same transaction.
-- name: DeleteCandidateProfileOverlapConfirmations :exec
DELETE FROM candidate_profile_overlap_confirmations
WHERE user_id = sqlc.arg(user_id);
-- name: InsertCandidateProfileOverlapConfirmation :exec
INSERT INTO candidate_profile_overlap_confirmations (
user_id,
first_index,
second_index,
first_started_on,
first_ended_on,
second_started_on,
second_ended_on
) VALUES (
sqlc.arg(user_id),
sqlc.arg(first_index),
sqlc.arg(second_index),
sqlc.arg(first_started_on),
sqlc.narg(first_ended_on),
sqlc.arg(second_started_on),
sqlc.narg(second_ended_on)
);
-- Every changed version appends exactly one private snapshot. The unique
-- key prevents a second snapshot for the same profile version.
-- name: AppendCandidateProfileHistory :exec
INSERT INTO candidate_profile_history (
user_id,
version,
changed_at,
snapshot
) VALUES (
sqlc.arg(user_id),
sqlc.arg(version),
sqlc.arg(changed_at),
sqlc.arg(snapshot)::jsonb
);
-- Saving a profile advances onboarding only from that exact step. A retry or
-- a save after a later step is already stored never regresses onboarding.
-- name: AdvanceCandidateOnboardingAfterProfile :exec
UPDATE users
SET
onboarding_step = 'candidate_questionnaire',
version = users.version + 1,
updated_at = GREATEST(users.updated_at, sqlc.arg(at)::timestamptz)
WHERE
users.id = sqlc.arg(user_id)
AND users.scenario = 'candidate'
AND users.email_verified_at IS NOT NULL
AND users.onboarding_step = 'candidate_profile';