### Common Validations in QR Scanner Hooks Source: https://context7_llms Outlines the common validation steps performed by all QR scanning hooks (useETicket, useQrDinamico, useCanje). These include checking ticket existence, type, secret, sector, and status. ```typescript // 1. Validation of Ticket in BD // 2. Validation of ticketType // 3. Validation of ticketSecret // 4. Validation of Sector // - Check if sector exists // - Check if sector is in allowedSectorIds // 5. Validation of State // - E_TICKET and QR_DINAMICO require VALIDATED // - CANJE requires PRINTED ``` -------------------------------- ### Manual Synchronization Trigger Source: https://context7_llms Details the manual synchronization process, initiated by a button in the Drawer Header. It's mandatory on the first use and optional for subsequent synchronizations. ```typescript // Trigger: Button in Drawer Header // First time: Mandatory before scanning // Subsequent: Optional, when user requires ``` -------------------------------- ### Session Context Authentication Functions (TypeScript) Source: https://context7_llms Provides functions for managing user authentication and session state. Key functions include logging in, logging out, and checking user authentication status by verifying tokens. ```typescript function Login() { // Authentication logic } function Logout() { // Logout logic } function checkUserAuth() { // Token verification logic } ``` -------------------------------- ### Configure Automatic Synchronization Interval (TypeScript) Source: https://context7_llms Defines the interval for automatic data synchronization. This configuration is set in a constants file and defaults to 2 minutes. The synchronization is automatically enabled after the first successful manual synchronization. ```typescript AUTO_SYNC_INTERVAL = 2 * 60 * 1000 // 2 minutes by default ``` -------------------------------- ### Scanner Hooks (TypeScript) Source: https://context7_llms A collection of hooks dedicated to managing the scanning functionality. This includes the main scanner logic, QR code processing, and specific handlers for different QR code types like E_TICKET, QR_DINAMICO, and CANJE. ```typescript import { useScanner } from './useScanner.hook'; import { useQrProcessor } from './useQrProcessor.hook'; import { useETicket } from './useETicket.hook'; import { useQrDinamico } from './useQrDinamico.hook'; import { useCanje } from './useCanje.hook'; ``` -------------------------------- ### Global State Management (TypeScript) Source: https://context7_llms Manages the global state of the application, including selected events, allowed sectors, event schedules, and synchronization status. This context is crucial for maintaining application-wide data. ```typescript const [selectedEvent, setSelectedEvent] = useState(null); const [allowedSectors, setAllowedSectors] = useState([]); const [eventSchedule, setEventSchedule] = useState({}); const [syncStatus, setSyncStatus] = useState('idle'); ``` -------------------------------- ### Sync Context Functions (TypeScript) Source: https://context7_llms Handles the synchronization of data within the application. It includes functions to initiate event synchronization and movement synchronization, and manages the progress and results of these operations. ```typescript function startEventSync() { // Logic to sync events } function startMovementsSync() { // Logic to sync movements } ``` -------------------------------- ### Sync Movements Service Functions (TypeScript) Source: https://context7_llms Provides core functionalities for synchronizing movements between the local device and the server. This includes sending and receiving movement data, validating tickets, and managing database cleanup. ```typescript function syncMovements() { // Send/receive movements } function validateTicket() { // Ticket validation logic } function cleanDatabase() { // Database cleanup logic } ``` -------------------------------- ### QR Code Structures and Validation Rules Source: https://context7_llms Defines the structure and validation requirements for different QR code types: QR_DINAMICO, E_TICKET, and CANJE. Includes specific validation logic for TOTP and printVersion. ```json { "type": "QR_DINAMICO", "ticketSecret": "564 895", "ticketId": 1 } ``` ```json { "type": "E_TICKET", "ticketSecret": "c3d290542735e352d5a9c2c4ba82ba3c375bf488f7bd70871bb64c906da8b16f", "ticketId": 1 } ``` ```json { "type": "CANJE", "ticketSecret": "5ec146ba753720975bea38985b49b702f2b7939137c54a9b8774320a1f4cceb6", "printVersion": 3, "ticketId": 1 } ``` -------------------------------- ### Scan Context Helper (TypeScript) Source: https://context7_llms Assists in constructing the context required for scanning operations. This helper function likely consolidates necessary data and configurations for the scanning module. ```typescript import { buildScanContext } from './scanContext.helper'; const scanDetails = { /* ... */ }; const context = buildScanContext(scanDetails); // Use context in scanner logic ``` -------------------------------- ### Format Time from UTC Helper (TypeScript) Source: https://context7_llms A utility function for formatting date and time values from UTC to a more human-readable format. This is useful for displaying timestamps consistently across the application. ```typescript import { formatTimeFromUTC } from './formatTimeFromUTC'; const utcTimestamp = '2023-10-27T10:00:00Z'; const formattedTime = formatTimeFromUTC(utcTimestamp); console.log(formattedTime); // e.g., '10:00 AM' ``` -------------------------------- ### Movement Logger State Mapping Source: https://context7_llms Illustrates the mapping between internal scanner status codes (STATUS_SCANNER) and the backend control status format (ControlStatus). This is used for logging successful and erroneous movements. ```typescript // STATUS_SCANNER -> ControlStatus // APROVED -> VALIDATED // JOINED -> ALREADY_USED // UNSUSCRIBED -> CANCELLED // REJECTED -> REJECTED // UNKNOWN -> NOT_FOUND // INVALID -> NOT_FOUND // ENTRY_INCORRECT -> WRONG_ACCESS ``` -------------------------------- ### QR Data Parsing Helper (TypeScript) Source: https://context7_llms A helper function responsible for validating the structure of QR code data. This ensures that the scanned data conforms to the expected format before further processing. ```typescript import { parseQrData } from './parseQrData.helper'; const qrData = '...'; // Scanned QR data if (parseQrData(qrData)) { // Process valid QR data } ``` -------------------------------- ### Synchronization Hooks (TypeScript) Source: https://context7_llms Hooks specifically designed for managing data synchronization processes. This includes hooks for synchronizing tickets and movements. ```typescript import { useTicketsSync } from './useTicketsSync.hook'; import { useSyncMovements } from './useSyncMovements.ts'; ``` -------------------------------- ### Tickets Sync Service Functions (TypeScript) Source: https://context7_llms Handles the synchronization of ticket data. It includes functions to fetch tickets from the server in a paginated manner and insert them into the local database. ```typescript function getEventTickets(page: number) { // Fetch tickets with pagination } function insertTickets(tickets: Ticket[]) { // Insert tickets into local DB } ``` -------------------------------- ### Database Service - Table Definitions (TypeScript) Source: https://context7_llms Defines the primary tables used in the local database service. These tables store information related to tickets, movements, sectors, and stored events for offline access. ```typescript interface Ticket {} interface TicketInfo {} interface Movement {} interface Sector {} interface StoredEvent {} ``` -------------------------------- ### Scanner Mode vs. Verification Mode (TypeScript) Source: https://context7_llms Differentiates between the 'Scan Mode' and 'Verification Mode'. In Scan Mode, the entry is consumed, ticket status updated, and movement recorded. In Verification Mode, only validation occurs without consuming the entry or recording movement. ```typescript const isVerifyMode = false; // Set to true for verification mode if (!isVerifyMode) { // Burn entry // Update ticket status // Record successful movement } else { // Only validate ticket // Do not burn entry // Do not update ticket status // Do not record movement } ``` -------------------------------- ### Sync Movements with Ticket Check Function (TypeScript) Source: https://context7_llms Performs a comprehensive synchronization process. It sends local movements, receives server movements, and verifies if an event has been cleared on the server. This is used for both manual and automatic synchronization. ```typescript function syncMovementsWithTicketCheck() { // Implementation for full synchronization } ``` -------------------------------- ### TOTP Validation Helper (TypeScript) Source: https://context7_llms Handles the validation of Time-based One-Time Passwords (TOTP) for dynamic QR codes. This is essential for ensuring the security and validity of dynamically generated codes. ```typescript import { Totp } from './Totp.helper'; const secret = '...'; // TOTP secret const token = '...'; // User provided token if (Totp.verify(token, secret)) { // Token is valid } ``` -------------------------------- ### Sync Movements Only Function (TypeScript) Source: https://context7_llms A function designed to send only movement data to the server. This is typically used during logout procedures or for cleaning up the local database. ```typescript function syncMovementsOnly() { // Implementation to send only movements } ``` -------------------------------- ### Ticket Burning Logic Source: https://context7_llms Describes the process of 'burning' a ticket, which involves updating its status to REDEEMED. This action is conditional on not being in verification mode and is performed by the scanner. ```typescript // Condition: !isVerifyMode // If Scanner mode: Burn ticket (update status to REDEEMED) // If Verify mode: Only validate, do not burn // Updates when burning: // ticketStatus -> REDEEMED // controllerId -> ID of the controller that burned // controlDatetime -> Date and time of burning ``` -------------------------------- ### Sector Validation Logic (TypeScript) Source: https://context7_llms Implements the logic for validating allowed sectors during the scanning process. It checks if the sector of a scanned ticket is present in the list of allowed sectors for the current event. If not, it returns an error status and does not register a movement. ```typescript const allowedSectorIds = [1, 2, 3]; // Example allowed sectors const ticketSectorId = 4; // Sector ID from scanned ticket if (!allowedSectorIds.includes(ticketSectorId)) { // return STATUS_SCANNER.ENTRY_INCORRECT // Do not register movement } ``` -------------------------------- ### Burn Time Validation Helper (TypeScript) Source: https://context7_llms Validates the 'burn time' or usage time for tickets. This helper function ensures that tickets are only used within their valid time window. ```typescript import { validateBurnTime } from './validateBurnTime.helper'; const ticket = { validUntil: '...' }; // Ticket data if (validateBurnTime(ticket)) { // Ticket is within valid time } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.