52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
import { request } from '../lib/apiClient'
|
|
|
|
/* ============================================================
|
|
departments.js — backend/department/app.py routes.
|
|
|
|
created_by / updated_by come from the JWT on the server — do not send them.
|
|
`location` is a string[]; the form edits it as comma-separated text.
|
|
============================================================ */
|
|
|
|
export function list({ search, isActive, top, skip } = {}) {
|
|
return request('/department/fetch', {
|
|
params: { search: search || undefined, is_active: isActive, top, skip },
|
|
})
|
|
}
|
|
|
|
export function getById(recordId) {
|
|
return request('/department/fetch', { params: { record_id: recordId } })
|
|
}
|
|
|
|
export function create(body) {
|
|
return request('/department/create', { method: 'POST', body })
|
|
}
|
|
|
|
export function update(recordId, body) {
|
|
return request('/department/update', { method: 'PUT', params: { record_id: recordId }, body })
|
|
}
|
|
|
|
/** Department Head picker — `{data:[{id,name,email}]}`. The server defaults
|
|
* `role_id` to the department_head role when it is not sent. */
|
|
export function listHeads({ roleId, search, top, skip } = {}) {
|
|
return request('/department/heads/fetch', {
|
|
params: { role_id: roleId, search: search || undefined, top, skip },
|
|
})
|
|
}
|
|
|
|
/** Region / Location picker — `{data:["Karachi - Pakistan", …]}` from global_cities.py. */
|
|
export function listLocations({ search } = {}) {
|
|
return request('/department/locations/fetch', { params: { search: search || undefined } })
|
|
}
|
|
|
|
/** Active departments for pickers (Requisitions "From (Dept.)") — `{data:[{id,name}]}`. */
|
|
export function listNames({ search } = {}) {
|
|
return request('/department/names', { params: { search: search || undefined } })
|
|
}
|
|
|
|
export function toRows(res) {
|
|
const data = res?.data
|
|
if (Array.isArray(data)) return data
|
|
if (data) return [data]
|
|
return []
|
|
}
|