Created
December 3, 2022 05:16
-
-
Save leegilmorecode/5ab8c464ad217c47bec2f03457a5a238 to your computer and use it in GitHub Desktop.
A base class for our value objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { schemaValidator } from '@packages/schema-validator'; | |
interface ValueObjectProps { | |
[index: string]: any; | |
} | |
export abstract class ValueObject<T extends ValueObjectProps> { | |
protected props: T; | |
constructor(props: T) { | |
this.props = Object.freeze(props); | |
} | |
protected validate(schema: Record<string, any>): void { | |
schemaValidator(schema, this.props); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment