-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPapersInterpreter.ts
75 lines (73 loc) · 3.28 KB
/
PapersInterpreter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Papers } from './Papers';
import { AccessPermit } from './papers/AccessPermit';
import { AccessPermitInterpreter } from './interpreters/paper/AccessPermitInterpreter';
import { DiplomaticAuthorizationInterpreter } from './interpreters/paper/DiplomaticAuthorizationInterpreter';
import { DiplomaticAuthorization } from './papers/DiplomaticAuthorization';
import { InputPapers } from './types';
import { GrantOfAsylum } from './papers/GrantOfAsylum';
import { GrantOfAsylumInterpreter } from './interpreters/paper/GrantOfAsylumInterpreter';
import { PassportInterpreter } from './interpreters/paper/PassportInterpreter';
import { Passport } from './papers/Passport';
import { CertificateOfVaccinationInterpreter } from './interpreters/paper/CertificateOfVaccinationInterpreter';
import { CertificateOfVaccination } from './papers/CertificateOfVaccination';
import { IdCardInterpreter } from './interpreters/paper/IdCardInterpreter';
import { IdCard } from './papers/IdCard';
import { WorkPassInterpreter } from './interpreters/paper/WorkPassInterpreter';
import { WorkPass } from './papers/WorkPass';
export class PapersInterpreter {
private inputKeyInterpreterMap = {
access_permit: {
interpreter: new AccessPermitInterpreter(),
addToPapers: (papers: Papers) => (accessPermit: AccessPermit) => {
papers.setAccessPermit(accessPermit);
}
},
diplomatic_authorization: {
interpreter: new DiplomaticAuthorizationInterpreter(),
addToPapers: (papers: Papers) => (diplomaticAuthorization: DiplomaticAuthorization) => {
papers.setDiplomaticAuthorization(diplomaticAuthorization);
}
},
grant_of_asylum: {
interpreter: new GrantOfAsylumInterpreter(),
addToPapers: (papers: Papers) => (grantOfAsylum: GrantOfAsylum) => {
papers.setGrantOfAsylum(grantOfAsylum);
}
},
passport: {
interpreter: new PassportInterpreter(),
addToPapers: (papers: Papers) => (passport: Passport) => {
papers.setPassport(passport);
}
},
certificate_of_vaccination: {
interpreter: new CertificateOfVaccinationInterpreter(),
addToPapers: (papers: Papers) => (certificateOfVaccination: CertificateOfVaccination) => {
papers.setCertificateOfVaccination(certificateOfVaccination);
}
},
ID_card: {
interpreter: new IdCardInterpreter(),
addToPapers: (papers: Papers) => (idCard: IdCard) => {
papers.setIdCard(idCard);
}
},
work_pass: {
interpreter: new WorkPassInterpreter(),
addToPapers: (papers: Papers) => (workPass: WorkPass) => {
papers.setWorkPass(workPass);
}
}
};
public interpret (inputPapers: InputPapers): Papers {
const papers = new Papers();
for (var key in inputPapers) {
if (inputPapers.hasOwnProperty(key)) {
const { interpreter, addToPapers } = this.inputKeyInterpreterMap[key];
const paper = interpreter.interpret(inputPapers[key]);
addToPapers(papers)(paper);
}
}
return papers;
}
}