HR-ATS-Portal/backend/job/job_post/serializers.py

64 lines
2.8 KiB
Python

def serialize_job_post(row) -> dict:
return {
"id": str(row.id),
"title": row.title,
"employment_type": row.employment_type,
"location": row.location,
"experience_min": row.experience_min,
"experience_max": row.experience_max,
"requirements": list(row.requirements or []),
"optional_skills": list(row.optional_skills or []),
"salary": row.salary,
"description": row.description,
"post_text": row.post_text,
"channel_id": row.channel_id,
"platform": row.platform,
"is_active": row.is_active,
"is_deleted": row.is_deleted,
"buffer_post_id": row.buffer_post_id,
"buffer_external_link": row.buffer_external_link,
"buffer_sent_at": row.buffer_sent_at.isoformat() if row.buffer_sent_at else None,
"status": row.status,
"buffer_error": row.buffer_error,
"created_by": str(row.created_by) if row.created_by else None,
"created_by_name": row.user.name if getattr(row, "user", None) else None,
"created_at": row.created_at.isoformat() if row.created_at else None,
"updated_at": row.updated_at.isoformat() if row.updated_at else None,
}
def serialize_job_row(row, *, recruiter_name=None) -> dict:
"""Requisition view of a job post, for the Jobs screen.
Deliberately separate from serialize_job_post: that payload is shared by the
inbox, candidate and matching paths, and widening it would change five
response shapes at once.
"""
return {
"id": str(row.id),
"title": row.title,
"department": row.department or None,
"location": row.location,
"employment_type": row.employment_type,
"vacancies": row.vacancies,
"platform": row.platform or None,
# Two different lifecycles, never conflate: requisition_status is hiring
# (open/closed/on_hold), status is Buffer publishing (draft/scheduled/...).
"requisition_status": row.requisition_status,
"status": row.status,
"experience_min": row.experience_min,
"experience_max": row.experience_max,
"salary": row.salary,
"requirements": list(row.requirements or []),
"optional_skills": list(row.optional_skills or []),
"description": row.description,
"is_active": row.is_active,
"closed_at": row.closed_at.isoformat() if row.closed_at else None,
"current_recruiter_id": str(row.current_recruiter_id) if row.current_recruiter_id else None,
"recruiter_name": recruiter_name,
"created_by": str(row.created_by) if row.created_by else None,
"created_by_name": row.user.name if getattr(row, "user", None) else None,
"created_at": row.created_at.isoformat() if row.created_at else None,
"updated_at": row.updated_at.isoformat() if row.updated_at else None,
}