UNPKG

@supernick135/face-scanner-client

Version:

Node.js client library for ZKTeco face scanning devices integration with comprehensive API support

194 lines (158 loc) 5.87 kB
/** * Scanner Client for Face Scanner API * Specialized client for scanner operations and scan data */ const FaceScannerClient = require('./FaceScannerClient'); class ScannerClient extends FaceScannerClient { constructor(options = {}) { super(options); } // Enhanced scan retrieval methods async getRecentScans(limit = 10) { return this.getScans({ limit, sortBy: 'timestamp', order: 'desc' }); } async getScansByDate(startDate, endDate, options = {}) { return this.getScans({ startDate: startDate.toISOString(), endDate: endDate.toISOString(), ...options }); } async getScansByDevice(deviceId, options = {}) { return this.getScans({ deviceId, ...options }); } async getTodayScans() { const today = new Date(); today.setHours(0, 0, 0, 0); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); return this.getScansByDate(today, tomorrow); } // Face detection and scanning async startScanning(deviceId) { return this.sendCommand(deviceId, { type: 'START_SCANNING' }); } async stopScanning(deviceId) { return this.sendCommand(deviceId, { type: 'STOP_SCANNING' }); } // Scan statistics async getScanStats(options = {}) { const params = new URLSearchParams(); if (options.startDate) params.append('startDate', options.startDate); if (options.endDate) params.append('endDate', options.endDate); if (options.deviceId) params.append('deviceId', options.deviceId); return this.http.get(`/scanner/stats?${params}`); } async getDailyScanStats(date = new Date()) { const startDate = new Date(date); startDate.setHours(0, 0, 0, 0); const endDate = new Date(startDate); endDate.setDate(endDate.getDate() + 1); return this.getScanStats({ startDate: startDate.toISOString(), endDate: endDate.toISOString() }); } async getMonthlyScanStats(year = new Date().getFullYear(), month = new Date().getMonth()) { const startDate = new Date(year, month, 1); const endDate = new Date(year, month + 1, 0, 23, 59, 59, 999); return this.getScanStats({ startDate: startDate.toISOString(), endDate: endDate.toISOString() }); } // Search and filter scans async searchScans(query, options = {}) { const params = new URLSearchParams(); params.append('q', query); if (options.limit) params.append('limit', options.limit); if (options.offset) params.append('offset', options.offset); return this.http.get(`/scanner/search?${params}`); } async getScansByUser(userId, options = {}) { return this.searchScans(`user:${userId}`, options); } // Scan export and reporting async exportScans(options = {}) { const params = new URLSearchParams(); if (options.startDate) params.append('startDate', options.startDate); if (options.endDate) params.append('endDate', options.endDate); if (options.format) params.append('format', options.format); // csv, json, xlsx if (options.deviceId) params.append('deviceId', options.deviceId); return this.http.get(`/scanner/export?${params}`); } async generateScanReport(options = {}) { const reportData = { type: options.type || 'daily', // daily, weekly, monthly startDate: options.startDate, endDate: options.endDate, deviceId: options.deviceId, includeImages: options.includeImages || false, format: options.format || 'json' }; return this.http.post('/scanner/reports', reportData); } // Real-time scan monitoring async getActiveScanSessions() { return this.http.get('/scanner/active-sessions'); } async getScannerHealth() { return this.http.get('/scanner/health'); } // Scan validation and quality checks async validateScan(scanId) { return this.http.post(`/scanner/scans/${scanId}/validate`); } async getImageQuality(scanId) { return this.http.get(`/scanner/scans/${scanId}/quality`); } // Batch operations async bulkValidateScans(scanIds) { return this.http.post('/scanner/bulk-validate', { scanIds }); } async bulkDeleteScans(scanIds) { return this.http.post('/scanner/bulk-delete', { scanIds }); } // Performance monitoring async getScannerPerformance(options = {}) { const params = new URLSearchParams(); if (options.startDate) params.append('startDate', options.startDate); if (options.endDate) params.append('endDate', options.endDate); if (options.deviceId) params.append('deviceId', options.deviceId); return this.http.get(`/scanner/performance?${params}`); } async getScanLatency(options = {}) { const params = new URLSearchParams(); if (options.deviceId) params.append('deviceId', options.deviceId); if (options.hours) params.append('hours', options.hours); return this.http.get(`/scanner/latency?${params}`); } // Utilities for common scanning workflows async quickScanStatus() { const [status, recentScans, stats] = await Promise.allSettled([ this.getScannerStatus(), this.getRecentScans(5), this.getDailyScanStats() ]); return { status: status.status === 'fulfilled' ? status.value : null, recentScans: recentScans.status === 'fulfilled' ? recentScans.value : null, dailyStats: stats.status === 'fulfilled' ? stats.value : null, errors: [status, recentScans, stats] .filter(r => r.status === 'rejected') .map(r => r.reason.message) }; } } module.exports = ScannerClient;