HR-ATS-Portal/frontend/src/api/sheet.js

85 lines
3.0 KiB
JavaScript

import { request } from '../lib/apiClient'
/**
* Google Sheet form-data mirror (backend/g_sheet/).
*
* Read endpoints accept inbox.view OR settings.view. Import / write / delete stay
* under settings.view on the server — this module only covers what Inbox needs.
*/
/** Distinct sheet tab names already imported into form_data. */
export function listFormDataSheets() {
return request('/sheet/form-data/sheets')
}
/**
* Paginated form_data rows.
*
* `offset` / `limit` map 1:1 to the backend Query params (not skip/top).
* Optional `processing_state` / `is_duplicate` power the Sheet Forms tabs.
*
* `has_linkedin` / `has_resume` are tri-valued on the wire, the same convention
* `is_duplicate` uses: omit for no filter, false to find the rows MISSING the
* link. buildUrl drops undefined but keeps false, so `undefined` sends no param.
*/
export function listFormData({
sheet, search, offset = 0, limit, processing_state, is_duplicate,
hasLinkedin, hasResume, city, source, assigned, no_suggestions,
has_suggestions, job_post_ids,
} = {}) {
return request('/sheet/form-data/fetch', {
params: {
sheet, search, offset, limit, processing_state, is_duplicate,
has_linkedin: hasLinkedin, has_resume: hasResume, city, source, assigned, no_suggestions,
has_suggestions, job_post_ids,
},
})
}
/** Unfiltered form_data total for a sheet. Called once when Sheet Forms opens. */
export function countFormData({ sheet } = {}) {
return request('/sheet/form-data/count', { params: { sheet } })
}
/**
* Tab badge counts for one sheet (or all sheets when sheet omitted).
*
* Takes the same narrowing filters as the list, because a badge reading 612
* above twelve visible rows reads as a bug. It deliberately does NOT take
* processing_state or is_duplicate: those two ARE the tabs, and passing them
* would make every badge report the tab the user is already on.
*/
export function fetchFormCounts({ sheet, search, hasLinkedin, hasResume, city, source, assigned, job_post_ids } = {}) {
return request('/sheet/form-data/counts', {
params: { sheet, search, has_linkedin: hasLinkedin, has_resume: hasResume, city, source, assigned, job_post_ids },
})
}
/** One form_data row by UUID. */
export function getFormData(recordId) {
return request(`/sheet/form-data/${recordId}`)
}
/** Set or clear form_data.job_post_id (job_post_id: null clears). */
export function assignJobPost(recordId, jobPostId) {
return request(`/sheet/form-data/${recordId}/assign-job-post`, {
method: 'PATCH',
body: { job_post_id: jobPostId },
})
}
/** unread | imported | processed | rejected — same allowlist as inbox. */
export function setProcessingState(recordId, processingState) {
return request(`/sheet/form-data/${recordId}/processing-state`, {
method: 'PATCH',
body: { processing_state: processingState },
})
}
export function setDuplicate(recordId, isDuplicate) {
return request(`/sheet/form-data/${recordId}/duplicate`, {
method: 'PATCH',
body: { is_duplicate: isDuplicate },
})
}