@mybus/ticketing v2.1.1
@mybus/ticketing provides several utilities for managing tickets for a user of a Monkey Factory application, including:
List of ticketing interfaces. Ticket validation rules Conversion of a ticket to ASN1 (barcode) format
- List of interfaces of the ticketing part,
- Rules for validating a ticket,
- QrCode generation,
- Conversion of a ticket to ASN1 format (barcode),
- Information about the validity of a ticket at a given time
Validation Rules
When validating a ticket, it will go through several rules (functions that return a Boolean). Only if all rules are correctly passed will the ticket be considered valid.
AllowedNetwork(ticket: Ticket): booleanIs the ticket being validated in a network where it can be used?
EnabledTicket(ticket: Ticket): booleanIs the ticket enabled?
PassengerCount(ticket: Ticket): booleanDoes the ticket have the correct number of passengers? A ticket may not have any associated passengers. However, if it does, it must ensure that this does not exceed the allowed limit.
UserAge(ticket: Ticket): booleanDoes the user who wants to use the ticket have the required age?
UserId(ticket: Ticket): booleanIs the user one of the passengers on the ticket?
UserProfiles(ticket: Ticket): booleanDoes the user have the correct profiles (e.g. "mulhouse:-26ans") to use this ticket?
ValidDate(ticket: Ticket): booleanIs the ticket still valid (not expired) and still validatable?
ValidationCount(ticket: Ticket): booleanHas the ticket reached its maximum number of possible validations?
ValidationDelay(ticket: Ticket): booleanHas the ticket completed its last validation?
It is possible to use each rule independently.
AllowedTransfer(ticket: Ticket): booleanIs not part of the validation rules but can be called to check if a ticket can be transferred or not.
Example for using the UserId rule independently:
import { UserId } from '@mybus/ticketing';
new UserId().validate(ticket, { userId: '9a8ab5c8-9f27-441e-bc96-3095fae38e0a' });Getting ticket status
It is possible to request information about a ticket in use.
getTicketInformation(ticket: TicketDto): Information
/*
* Returns
* state: under validation, invalid, expired, ...
* expireAt: date when the ticket will expire
* countdown?: time remaining (in seconds) before expiration
*/To only get the state of the ticket,
/*
* returns: `UNDER_VALIDATION | COMPLETED | UNCOMPOSTED | COMING_SOON`
*/
getTicketState(ticket, validation?): TicketState`Générer un QrCode pour un ticket
getQrCode(ticket: TicketDto): QrCodeOutput
/*
* Returns
* origin: QrCodeOrigin
* internal?: QrCodeInternal
* external?: QrCodeExternal
*/ASN1 conversion
convertTicketToHex(ticket: Ticket): stringReturns a hexadecimal string representing the ticket in ASN1 format.
convertHexToTicketId(uicBarCodeHex: string): string | nullProvides the inverse transformation.
Testing rules
All unit tests in this library are done on the same date (the date is mocked with Jest). The arbitrarily chosen date is Friday, September 30, 2022 at 4:33 PM. All tickets used in tests from test.config.ts are generated around this date. In other words, when you are running tests, you should consider yourself at this date and modify the dates of tickets and validations accordingly.
10 months ago
1 year ago
7 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago