Voucher Validator
This lib validate vouchers.
Installation
$ npm install voucher-validator
# OR
$ yarn add voucher-validator
How to use
user document pattern:
-
372.061.670-39
or 37206167039
import { Validator } from 'voucher-validator';
const validator = new Validator();
const isValid = validator.Validate({
userDocument: '372.061.670-39',
product: 'MY_PRODUCT',
voucher: myVoucher
});
console.log(isValid);
> true
Get total to pay with discount
import { Validator } from 'voucher-validator';
const validator = new Validator();
const total = 1000;
const totalToPay = validator.CalculateTotalWithDiscount(total, voucher10);
console.log(totalToPay);
> 900
Get total of discount
import { Validator } from 'voucher-validator';
const validator = new Validator();
const total = 1000;
const totalDiscount = validator.GetDiscount(total, voucher10);
console.log(totalDiscount);
> 100
OR another option to validate voucher
import { VoucherValidator } from 'voucher-validator';
const validator = new VoucherValidator({
userDocument: '372.061.670-39',
product: 'MY_PRODUCT'
});
const isValid = validator.isSatisfiedBy(myVoucher);
console.log(isValid);
> true
Validations
- IsUsedVoucher
- IsOnRangeDate start date less than current and end date greater then current
- IsNominal and UserDocument Match
- IsValidProduct
- IsVoucherDeleted
Types
Voucher types
export interface Voucher {
codigoVoucher: string;
dataUtilizacao: Date;
idLote: string;
documentoVinculado: null | string;
valido: boolean;
idCliente: number;
idConvenio: number;
utilizado: boolean;
tipoCupom: 'GENERICO' | 'NOMINAL' | 'NAO NOMINAL';
login: string;
dataInicioValidade: Date;
dataFimValidade: Date;
quantidadeDesconto: number;
createdAt: Date;
deletedAt: Date | null;
produto: string;
id_produto: string;
}