@classytic/payroll 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @classytic/payroll might be problematic. Click here for more details.

package/src/init.js CHANGED
@@ -3,6 +3,27 @@ import logger, { setLogger } from './utils/logger.js';
3
3
 
4
4
  let initialized = false;
5
5
 
6
+ /**
7
+ * Initialize HRM/Payroll framework
8
+ *
9
+ * @param {Object} options - Initialization options
10
+ * @param {Model} options.EmployeeModel - Employee model (required)
11
+ * @param {Model} options.PayrollRecordModel - Payroll record model (required)
12
+ * @param {Model} options.TransactionModel - Transaction model (required)
13
+ * @param {Model} options.AttendanceModel - Optional attendance model for integration
14
+ * @param {Object} options.logger - Optional custom logger
15
+ *
16
+ * @example Multi-Tenant (default)
17
+ * initializeHRM({
18
+ * EmployeeModel,
19
+ * PayrollRecordModel,
20
+ * TransactionModel
21
+ * });
22
+ *
23
+ * @example Single-Tenant
24
+ * // For single-tenant apps, add organizationId with default value in your Employee schema:
25
+ * // organizationId: { type: ObjectId, required: true, default: () => FIXED_ORG_ID }
26
+ */
6
27
  export function initializeHRM({ EmployeeModel, PayrollRecordModel, TransactionModel, AttendanceModel = null, logger: customLogger }) {
7
28
  // Allow users to inject their own logger
8
29
  if (customLogger) {
@@ -136,11 +136,18 @@ export function employeePlugin(schema, options = {}) {
136
136
  });
137
137
  };
138
138
 
139
- schema.pre('save', function(next) {
139
+ /**
140
+ * Pre-save hook to automatically update salary calculations
141
+ * when compensation is modified.
142
+ *
143
+ * Mongoose v9 compatible - uses async function without next callback
144
+ * - Use throw instead of next(err) for errors
145
+ * - Use return instead of return next()
146
+ */
147
+ schema.pre('save', async function() {
140
148
  if (this.isModified('compensation')) {
141
149
  this.updateSalaryCalculations();
142
150
  }
143
- next();
144
151
  });
145
152
 
146
153
  schema.index({ organizationId: 1, employeeId: 1 }, { unique: true });