Skip to Content
Recodocs

Employee self-service (`/api/me`)

Session-bound console APIs for an employee's profile, pay, documents, attendance, leave, expenses, and team approvals.

7 min read

What this API area is for

A self-service operation belongs to the signed-in employee. The route should resolve that relationship within the host rather than asking a caller to choose an arbitrary employee record.

These routes expose employee self-service in the console: reads and actions tied to the signed-in person, not to arbitrary employee ids in the request. Every handler resolves the employee from the console session (console_user linked to app_user.employee_id). Payslips, tax worksheets, and documents are scoped so another person's id returns the same 404 as a missing record.

Staff users may call the same paths for their own records. The module docstring says these are the only /api paths an employee session may reach (auth_routes._EMPLOYEE_PATHS). With console sign-in off there is no person to bind to, so handlers answer 404.

Leave and expense flows use the same runtimes as the Slack bot and MCP tools (leave_runtime, expenses_runtime), with requested_via="console" where applicable. Previews are dry runs; submits recompute. Managers review direct reports' pending leave and expense claims under team request endpoints, using the same decide() paths as Slack, keyed by reviewer employee_id.

Routes

MethodPathPermissionHandlerWhat it does
GET/api/meself.usemy_profileReturns profile fields, current role assignment, manager, work schedule, and count of direct reports (for showing team requests).
GET/api/me/payslipsself.usemy_payslipsLists issued payslips for the session employee, with parsed rows from rows_snapshot.
GET/api/me/payslips/{payslip_id}/pdfself.usemy_payslip_pdfServes the PDF file for an issued payslip owned by the employee via issuance plan payslip_filename.
GET/api/me/taxself.usemy_taxLists issued TDS worksheets for the employee.
GET/api/me/tax/{worksheet_id}/pdfself.usemy_tax_pdfServes the TDS PDF for an issued worksheet via issuance plan tds_filename.
GET/api/me/documentsself.usemy_documentsLists active documents that have a ready version and are filed for the employee or granted to the session principal (not revoked, not expired).
GET/api/me/documents/{document_key}self.usemy_document_contentDownloads the latest ready version; records access with event_type downloaded and data {"self_service": true}.
GET/api/me/attendanceself.usemy_attendanceReturns attendance marks and check-in events since a computed start date (query days, default 90).
GET/api/me/assetsself.usemy_assetsLists non-returned asset assignments and active workstation assignments.
GET/api/me/leaveself.usemy_leaveReturns leave balance (or unavailable message on ValueError) and the employee's leave requests.
POST/api/me/leave/previewself.usepreview_my_leaveDry-run leave creation through leave_runtime.create_request (dry_run=True).
POST/api/me/leaveself.userequest_my_leaveSubmits leave; may notify reviewer on Slack when configured.
POST/api/me/leave/{request_key}/cancelself.usecancel_my_leaveCancels the employee's own leave request via leave_runtime.cancel.
GET/api/me/expensesself.usemy_expensesLists expense claims for the employee.
POST/api/me/expenses/previewself.usepreview_my_expenseDry-run expense submit via expenses_runtime.submit (dry_run=True).
POST/api/me/expensesself.useclaim_my_expenseSubmits an expense claim; may notify reviewer on Slack when configured.
GET/api/me/team/requestsself.usemy_team_requestsLists in-review leave and expense requests where the session employee is reviewer (excluding their own).
POST/api/me/team/requests/{kind}/{key}/decideself.usedecide_team_requestForwards decision to leave_runtime.decide or expenses_runtime.decide for kind leave or expense; audits console decisions.

Request and response models

Query parameters

RouteParameterTypeDefaultBehaviour in code
GET /api/me/attendancedaysint90Window start is max(1, min(days, 366)) days before today.

LeaveBody (POST leave and leave preview)

FieldTypeNotes
start_datestrRequired.
end_datestrRequired.
leave_typestrDefault "combined_paid".
reasonstr | NoneOptional.
half_dayboolDefault false.
emergencyboolDefault false.

Extra JSON fields are rejected (extra="forbid").

ExpenseBody (POST expenses and expenses preview)

FieldTypeNotes
amountstrRequired.
categorystrRequired.
descriptionstrRequired.
expense_datestrRequired.
receipt_notestr | NoneOptional.

Extra JSON fields are rejected.

DecisionBody (POST team decide)

FieldTypeNotes
decisionstrRequired.
notestr | NoneOptional.

Representative JSON responses

Handlers return dict unless noted. Shapes follow SQL row keys and runtime return values.

GET /api/me

{
  "profile": { "...": "employee profile columns" },
  "role": { "...": "role_assignment row or null" },
  "manager": { "name", "email" } or null,
  "work_schedule": { "...": "schedule row or null" },
  "direct_reports": 0
}

Profile columns include: name, email, phone, employee_code, date_of_joining, date_of_birth, personal_address, pan_number, tax_regime, bank_account_no, ifsc (unmasked for the owner).

GET /api/me/payslips: { "payslips": [ { id, pay_period, fiscal_year, pay_date, currency, days_in_month, paid_days, lop_days, gross_earnings, total_deductions, net_pay, rows } ] }.

GET /api/me/tax: { "worksheets": [ worksheet row dicts ] }.

GET /api/me/documents: { "documents": [ metadata without version_key ] }.

GET /api/me/attendance: { "marks": [...], "check_ins": [...] }.

GET /api/me/assets: { "assets": [...], "workstations": [...] }.

GET /api/me/leave: { "balance": { ... } or { "unavailable": "..." }, "requests": [...] }.

GET /api/me/expenses: { "claims": [...] }.

GET /api/me/team/requests: { "leave": [...], "expenses": [...] }.

PDF routes return FileResponse (application/pdf). Document download returns raw bytes with Content-Disposition: attachment and detected_mime or application/octet-stream.

Leave, expense, preview, cancel, and decide endpoints return the dict produced by leave_runtime or expenses_runtime (structure defined in those packages, not duplicated here).

Behaviour and errors

Session and scoping (_me)

  • No console_user on the request → 404 not_found, message "Self-service needs console sign-in".
  • Console user not linked to an employee → 404, "Your console account is not linked to an employee".
  • Look up payslip, tax, and leave keys with the session employee id; a document key must be filed for that employee or granted to the session principal. For team decide, match reviewer_employee_id to that id (unknown kind, missing row, or own request is 404 Not found).

File resolution (_file_in_docs)

PDF filenames must be a non-empty string without path separators, resolve inside the tenant docs_dir, and exist as a file; otherwise 404.

Validation and runtime refusals (_refused)

  • ValueError from leave/expense runtimes → 400 with error.code "invalid", message str(exc), retryable: false.
  • ApprovedStateChangedError from leave paths → 409 with error.code "conflict".

Team decide:

  • Unknown kind (not leave or expense) → 404.
  • Row not found for reviewer, or reviewer is the requester → 404.
  • ValueError from decide → 400 invalid.
  • Result outcome in already_decided or balance_blocked → 409 with error.code set to the outcome string and result included in the body.
  • Other non-decided outcomes → 404.
  • Successful decided → writes agent_audit with action {kind}.decided, actor_type operator, metadata decision and channel: console, then returns the runtime result.

Console permission gate (before handler)

For signed-in users, route_roles.gate checks ROUTE_PERMISSIONS for the handler. Missing permission mapping → 403 denied. Policy denial → 403 with policy reason. public permissions skip the role check. These checks apply in addition to handler-level scoping.

Status code summary

CodeTypical cause
400Leave/expense/cancel/decide validation (invalid).
403Role or policy denies route permission (denied).
404No session employee, unscoped resource, bad document file, unknown team kind, or failed decide lookup.
409Approved state changed on leave (conflict); team decide already_decided or balance_blocked.

How the permission model applies

Each handler is registered in ROUTE_PERMISSIONS under the key self_service_routes.<handler_name> with permission self.use. That permission is a ceiling: the console refuses to start if any route lacks an entry (require_complete), and gate refuses signed-in users whose role does not hold the permission. The route still enforces employee-only data access in code; permissions do not widen scope beyond the signed-in person's records and reviewer responsibilities.

All eighteen handlers in this module map to self.use. The docstring says an employee session may reach only these /api paths (auth_routes._EMPLOYEE_PATHS). Staff with broader roles still hit the same permission name, but handlers bind the caller with _me and return that employee's rows, plus team-request rows for which that employee is the reviewer.

How is this page?

Last updated on