@veeyaainnovatives/attendance-sync-core
v1.0.0
Published
Core attendance sync functions for syncing biometric attendance data from local database to online API
Downloads
75
Maintainers
Readme
@veeyaainnovatives/attendance-sync-core
Core attendance sync functions for syncing biometric attendance data from local database to online API.
Installation
npm installUsage
Basic Usage
const { syncAttendance, syncDateRange } = require('@saleem-group/attendance-sync-core');
require('dotenv').config();
// Sync single date
await syncAttendance('2025-01-15');
// Sync date range
const result = await syncDateRange('2025-01-01', '2025-01-31', {}, syncAttendance);With Custom Configuration
Single Table Mode
const config = {
mssql: {
user: 'username',
password: 'password',
server: 'server',
database: 'database',
options: {
encrypt: true,
trustServerCertificate: true
}
},
externalApiUrl: 'https://api.example.com/sync',
apiSecretToken: 'your-token',
mode: 'single', // Single table mode
tableName: 'Attendance_All', // Single table for all attendance
empIdCol: 'EmployeeID',
dateTimeCol: 'DateTime',
logPayload: true,
logResponse: true,
logNoData: true
};
await syncAttendance('2025-01-15', config);ESSL/Dynamic Mode (Monthly Tables)
const config = {
mssql: { /* ... */ },
externalApiUrl: 'https://api.example.com/sync',
apiSecretToken: 'your-token',
mode: 'essl', // or 'dynamic' - Dynamic table name based on month/year
attendanceTableAlias: 'Attendance_', // Will generate: Attendance_1_2025, Attendance_2_2025, etc.
empIdCol: 'EmployeeID',
dateTimeCol: 'DateTime'
};
await syncAttendance('2025-01-15', config);
// Uses table: Attendance_1_2025 (January 2025)Table Name Modes
The package supports two modes for table name handling:
Single Table Mode (
mode: 'single'):- Uses a single table for all attendance data
- Requires
tableNameto be provided - Example:
tableName: 'Attendance_All'
ESSL/Dynamic Mode (
mode: 'essl'ormode: 'dynamic'):- Dynamically constructs table name based on month and year
- Requires
attendanceTableAliasto be provided - Automatically generates:
{alias}{month}_{year}(e.g.,Attendance_1_2025) - Can use custom pattern or function for advanced scenarios
API
syncAttendance(inputDate, config)
Syncs attendance data for a single date.
inputDate(string, optional): Date in YYYY-MM-DD format. Defaults to today.config(object, optional): Configuration objectmode(string): Table mode -'single'or'essl'/'dynamic'(default:'essl')tableName(string, required for 'single' mode): Direct table name (e.g., 'Attendance_All')attendanceTableAlias(string, required for 'essl' mode): Table prefix for monthly tables (e.g., 'Attendance_')empIdCol(string): Employee ID column namedateTimeCol(string): DateTime column name- Other config options (see above)
syncDateRange(fromDate, toDate, options, syncAttendanceFn, config)
Syncs attendance data for a date range.
fromDate(string): Start date in YYYY-MM-DD formattoDate(string): End date in YYYY-MM-DD formatoptions(object, optional): Options objectmaxDays(number): Maximum days allowed (default: 90)logProgress(boolean): Log progress (default: true)
syncAttendanceFn(function): The syncAttendance function to useconfig(object, optional): Configuration object
Returns a promise that resolves to:
{
success: boolean,
totalDays: number,
successCount: number,
failCount: number,
failedDates: string[]
}Environment Variables
The package uses environment variables if config is not provided:
MSSQL_SERVERMSSQL_USERMSSQL_PASSWORDMSSQL_DATABASEEXTERNAL_API_URLAPI_SECRET_TOKENATTENDANCE_TABLE_ALIAS_NAME- Table name prefix/aliasEMP_ID_COL_NAME- Employee ID column nameTRAN_DATE_TIME_COL_NAME- DateTime column nameMAX_SYNC_DAYS- Maximum days for date range sync
Table Name Configuration
Mode: 'single' - Single table for all attendance:
config.mode = 'single';
config.tableName = 'Attendance_All'; // RequiredMode: 'essl' or 'dynamic' - Dynamic table based on month/year:
config.mode = 'essl'; // or 'dynamic'
config.attendanceTableAlias = 'Attendance_'; // Required
// Automatically generates: Attendance_1_2025, Attendance_2_2025, etc.Advanced: Custom function for dynamic table name generation (ESSL mode):
config.mode = 'essl';
config.getTableName = (dateMoment, { month, year, date }) => {
return `CustomTable_${year}_${String(month).padStart(2, '0')}`;
};License
ISC
