-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtistClass.ts
61 lines (56 loc) · 1.29 KB
/
ArtistClass.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
import { fetchArtistPosition } from './fetchGeoData';
function normalize(string: string): string {
return string.replaceAll(' ', '').toLowerCase();
}
interface ArtistInterface extends Artist {
_id: string;
position: [number, number];
}
class Artist {
artistName: string;
location: {
city: string;
streetname: string;
number: number;
};
slug: string;
tattoos: string[];
position: any;
dates: string[];
// construcor set to private, since it is only needed inside the static factory-method
private constructor(
artistName: string,
city: string,
streetname: string,
number: number,
tatoos: string[],
dates: string[]
) {
this.artistName = artistName;
this.location = { city, streetname, number };
this.slug = normalize(artistName);
this.tattoos = tatoos;
this.dates = dates;
}
// static ASYNC factory method.
public static async create(
artistName: string,
city: string,
streetname: string,
number: number,
tatoos: string[],
dates: string[]
) {
const artist = new Artist(
artistName,
city,
streetname,
number,
tatoos,
dates
);
artist.position = await fetchArtistPosition({ ...artist.location });
return artist;
}
}
export { Artist, type ArtistInterface };