voucher-validator
Version:
This lib provide validator to check business rules for a voucher
74 lines (73 loc) • 2.6 kB
TypeScript
import { Voucher, VoucherProps } from "../types";
export interface ValidateProps extends VoucherProps {
voucher: Voucher;
}
export declare class Validator {
/**
* @description calculate total to pay applying the discount
* @param total Product price total
* @param voucher Object
* @returns total to pay with discount
*/
CalculateTotalWithDiscount(total: number, voucher: Voucher): number;
/**
* @description check voucher start date and end date with current date
* @param voucher Object
* @returns true if current date is greater than start date and less than end date
*/
IsOnRangeDate(voucher: Voucher): boolean;
/**
* @description check if voucher has a document
* @param document string
* @param voucher Object
* @returns true if voucher has document and false if not
*/
HasDocument(document: string | null, voucher: Voucher): boolean;
/**
* @description check if voucher has a product
* @param product string
* @param voucher Object
* @returns true if voucher has product and false if not
*/
HasProduct(product: string, voucher: Voucher): boolean;
/**
* @description check if voucher has a convenio
* @param convenio string or number
* @param voucher Object
* @returns true if voucher has convenio and false if not
*/
HasConvenio(convenio: number | string, voucher: Voucher): boolean;
/**
* @description check if voucher has a client
* @param cliente string or number
* @param voucher Object
* @returns true if voucher has cliente and false if not
*/
HasCliente(cliente: number | string, voucher: Voucher): boolean;
/**
* @description calculate total of discount applied
* @param total Product price total
* @param voucher Object
* @returns total of discount
*/
GetDiscount(total: number, voucher: Voucher): number;
/**
* @description compare a code string with voucher code
* @param voucher Voucher
* @param code string
* @returns true if voucher code is equal or case is different
*/
Compare(voucher: Voucher, code: string): boolean;
/**
* @description validate all voucher properties
* @param props Props
* @returns true if is valid voucher and false case not
* @access IsUsedVoucher
* @access IsOnRangeDate
* @access IsNominal and UserDocument Match
* @access IsValidProduct
* @access IsVoucherDeleted
*/
Validate(props: ValidateProps): boolean;
}
export default Validator;