78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
import { request } from '../lib/apiClient'
|
|
|
|
/* ============================================================
|
|
assignments.js — who owns a requisition, and who owns an application.
|
|
|
|
Two parallel tables behind four routes (backend/job/app.py):
|
|
job_assignments — recruiter OR hiring manager on a JOB POST
|
|
application_assignments — a recruiter on ONE APPLICATION
|
|
|
|
Rows are valid-time intervals: `valid_to === null` is the assignment in force
|
|
now. Fetch defaults to current-only; pass currentOnly: false for the history
|
|
log. Reassignment closes the previous open interval of the SAME role.
|
|
|
|
Recruiter pickers use /tasks/assignees/fetch; hiring-manager pickers use
|
|
/managers/fetch. Neither needs rbac_users.view. The current pointers also
|
|
live on job_posts (current_recruiter_id, hiring_manager_id) and PATCH
|
|
/jobs/update is the Jobs-screen write path.
|
|
============================================================ */
|
|
|
|
/** Current or historical owners of one requisition. */
|
|
export function listJob(jobPostId, { currentOnly, assignmentRole } = {}) {
|
|
return request('/job/assignments/fetch', {
|
|
params: {
|
|
job_post_id: jobPostId,
|
|
current_only: currentOnly,
|
|
assignment_role: assignmentRole,
|
|
},
|
|
})
|
|
}
|
|
|
|
/** Assign a recruiter to a requisition. Supersedes whoever held it. */
|
|
export function assignJob({ jobPostId, userId, assignmentRole }) {
|
|
return request('/job/assignments/create', {
|
|
method: 'POST',
|
|
body: {
|
|
job_post_id: jobPostId,
|
|
user_id: userId,
|
|
assignment_role: assignmentRole || 'primary_recruiter',
|
|
},
|
|
})
|
|
}
|
|
|
|
/** Current recruiter(s) on one application. */
|
|
export function listApplication(inboxId) {
|
|
return request('/candidate/assignments/fetch', { params: { inbox_id: inboxId } })
|
|
}
|
|
|
|
/** Assign a recruiter to one application. */
|
|
export function assignApplication({ inboxId, userId, assignmentRole }) {
|
|
return request('/candidate/assignments/create', {
|
|
method: 'POST',
|
|
body: {
|
|
inbox_id: inboxId,
|
|
user_id: userId,
|
|
assignment_role: assignmentRole || 'primary_recruiter',
|
|
},
|
|
})
|
|
}
|
|
|
|
/**
|
|
* The serializers return `user_id` and nothing else about the person, so the
|
|
* caller resolves names from the assignee list it already holds.
|
|
*/
|
|
export function toAssignmentView(row, namesById) {
|
|
return {
|
|
id: row.id,
|
|
userId: row.user_id,
|
|
name: row.user_name || namesById?.get(String(row.user_id)) || null,
|
|
assignedByName: row.assigned_by_name ?? null,
|
|
role: row.assignment_role || 'primary_recruiter',
|
|
jobPostId: row.job_post_id ?? null,
|
|
inboxId: row.inbox_id ?? null,
|
|
validFrom: row.valid_from ? new Date(row.valid_from) : null,
|
|
validTo: row.valid_to ? new Date(row.valid_to) : null,
|
|
assignedBy: row.assigned_by ?? null,
|
|
}
|
|
}
|