import { Exclude, Expose } from 'class-transformer'; import { IsArray, IsBoolean, IsEnum, IsNotEmpty, IsString } from 'class-validator'; import { ISquareVendor, IToastVendor, IVendor, VendorMathType, VendorMetadataType, VendorProviderEnum } from '../interface'; export class VendorModel implements IVendor { @Exclude() _id: string | any; @Expose({ groups: ['read'] }) @IsNotEmpty({ always: true }) @IsString({ always: true }) merchantId: string; @Expose({ groups: ['read'] }) @IsNotEmpty({ always: true }) @IsString({ always: true }) storeId: string; /** * If true, the order will be sent to the pos system. * Otherwise will not be sent. */ @Expose({ groups: ['read'] }) @IsNotEmpty({ always: true }) @IsBoolean({ always: true }) isLiveMode?: boolean; @Expose({ groups: ['read', 'write'] }) @IsNotEmpty({ always: true }) @IsEnum(VendorProviderEnum, { always: true }) provider: VendorProviderEnum; @Exclude() @IsNotEmpty({ always: true }) @IsArray({ always: true }) metadata: VendorMetadataType; @Expose({ groups: ['read'] }) @IsNotEmpty({ always: true }) @IsArray({ always: true }) math: VendorMathType; isToast(): this is IToastVendor { return VendorProviderEnum.TOAST === this.provider; } isSquare(): this is ISquareVendor { return VendorProviderEnum.SQUARE === this.provider; } /** * Right now only square tips are taxable */ isTipsTaxable(): boolean { return !this.isToast(); } }