import { EnumValueObject } from '../value-object/EnumValueObject' ; import { InvalidArgumentError } from '../value-object/InvalidArgumentError' ; export enum OrderTypes { ASC = 'asc' , DESC = 'desc' , NONE = 'none' } export class OrderType extends EnumValueObject < OrderTypes > { constructor ( value ) { super ( value , Object . values ( OrderTypes ) ) ; } static fromValue ( value ) { switch ( value ) { case OrderTypes . ASC : return new OrderType ( OrderTypes . ASC ) ; case OrderTypes . DESC : return new OrderType ( OrderTypes . DESC ) ; default : throw new InvalidArgumentError ( `The order type ${ value } is invalid` ) ; } } public isNone ( ) { return this . value === OrderTypes . NONE ; } public isAsc ( ) { return this . value === OrderTypes . ASC ; } protected throwErrorForInvalidValue ( value ) { throw new InvalidArgumentError ( `The order type ${ value } is invalid` ) ; } }