feat: implement Benefits & Automatic Deductions Engine - #166
Merged
Wilfred007 merged 6 commits intoMar 10, 2026
Conversation
- Add DB migration for benefit_plans, employee_benefit_enrollments, deduction_rules with RLS - Add Zod schemas for validation - Implement CRUD services and controllers for benefit plans, enrollments, deduction rules - Add draft payslip generation with deduction lines and wallet routing - Wire benefits routes under /api/v1/benefits with auth and tenant isolation - Add frontend service and employee portal deductions breakdown view - Support percentage and fixed deductions; route to treasury/provider wallets Closes Protocol-Guild#152
- Remove third argument from notifySuccess (API accepts 1–2) - Improve safeReject to JSON-stringify objects instead of '[object Object]' - Replace deprecated React.FormEvent with React.SyntheticEvent - Flatten nested ternary in safeReject to explicit if/else for clarity
- Resolve EmployeeEntry.tsx: keep main's API call logic and preserve lint fixes (React.SyntheticEvent, notifySuccess signature, void wrapper) - Resolve utils/api.ts: combine axios instance from main with utility functions from feature branch - No conflicts remain
- Add BackendEmployee and EmployeesResponse types; remove any - Type API response and error handling safely - Remove unnecessary async wrapper in handleSubmit; use real async/await - Fix floating promises with void where needed - Wrap form onSubmit to prevent no-misused-promises error - Ensure axios interceptor rejects with an Error instance
Contributor
|
@pope-h thank you for your contribution, kindly leave a star on the repo. Have a good day |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Benefits & Automatic Deductions Engine
Closes #152
Summary
Implements a flexible engine to handle non-salary payroll components like healthcare premiums, retirement contributions, and taxes. The engine calculates these deductions before submitting the final net pay to the Stellar network, and exposes an employee portal view of deduction breakdowns.
Features
Backend Changes
backend/src/db/migrations/021_create_benefits_and_deductions.sqlbenefit_plans,employee_benefit_enrollments,deduction_rulesbackend/src/schemas/benefitsSchema.tsbackend/src/services/benefitsService.tsgenerateDraftPayslip: combines deduction rules and tax rules, routes funds to walletsbackend/src/controllers/benefitsController.tsbackend/src/routes/benefitsRoutes.ts→ registered at/api/v1/benefits:organizationIdGET /me/deductionsFrontend Changes
frontend/src/services/benefitsApi.tsgetMyDeductionsDraftPayslipwrapperfrontend/src/hooks/useEmployeePortal.tsdeductionsDraftdatafrontend/src/pages/EmployeePortal.tsxAPI Endpoints
Employer (role: EMPLOYER)
POST /api/v1/benefits/organizations/:organizationId/plans– Create benefit planGET /api/v1/benefits/organizations/:organizationId/plans– List benefit plansPUT /api/v1/benefits/organizations/:organizationId/plans/:id– Update benefit planDELETE /api/v1/benefits/organizations/:organizationId/plans/:id– Delete benefit planPOST /api/v1/benefits/organizations/:organizationId/enrollments– Upsert employee enrollmentGET /api/v1/benefits/organizations/:organizationId/employees/:employeeId/enrollments– List enrollmentsPOST /api/v1/benefits/organizations/:organizationId/deduction-rules– Create deduction ruleGET /api/v1/benefits/organizations/:organizationId/deduction-rules– List deduction rulesPUT /api/v1/benefits/organizations/:organizationId/deduction-rules/:id– Update deduction ruleDELETE /api/v1/benefits/organizations/:organizationId/deduction-rules/:id– Delete deduction rulePOST /api/v1/benefits/organizations/:organizationId/draft-payslips– Generate draft payslipEmployee (role: EMPLOYEE)
GET /api/v1/benefits/me/deductions– Get current employee’s draft payslip with deduction breakdownSecurity & Multi-tenancy
organization_idfrom URL params for employer routeswallet_addressfrom JWTTesting
How to Use
/me/deductionsendpoint.Review Checklist
Ready for review and merge!