1 import Form from './Form';
2 import { Person, Relation } from './Person';
4 export default class TaxReturn {
6 private _people: Person[] = [];
7 private _forms: Form[] = [];
9 constructor(year: number) {
17 addPerson(person: Person) {
18 if (person.relation == Relation.Dependent) {
19 throw new UnsupportedFeatureError('Dependents are not supported');
21 if (person.relation == Relation.Self || person.relation == Relation.Spouse) {
22 const others = this._people.filter(p => p.relation == person.relation);
23 if (others.length > 0) {
24 throw new InconsistencyError('Cannot have more than one Self or Spouse');
27 this._people.push(person);
30 getPerson(name: RegExp | string): Person {
31 const people = this._people.filter(p => p.name.search(name) !== -1);
32 if (people.length != 1) {
33 throw new Error(`Person ${name} not found or too imprecise`);
42 export class InconsistencyError extends Error {
45 export class UnsupportedFeatureError extends Error {