-
Notifications
You must be signed in to change notification settings - Fork 1
/
12-11-CatalogItem.js
124 lines (111 loc) Β· 2.13 KB
/
12-11-CatalogItem.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* p531 μμ
*/
class CatalogItem {
#id;
#title;
#tags;
constructor(id, title, tags) {
this.#id = id;
this.#title = title;
this.#tags = tags;
}
get id() {
return this.#id;
}
get title() {
return this.#title;
}
hasTag(arg) {
return this.#tags.includes(arg);
}
}
class Scroll {
#id;
#catalogItem;
#lastCleaned;
constructor(id, dateLastCleaned, catalogId, catalog) {
this.#id = id;
this.#catalogItem = catalog.get(catalogId);
this.#lastCleaned = dateLastCleaned;
}
get id() {
return this.#id;
}
get title() {
return this.#catalogItem.title;
}
hasTag(aString) {
return this.#catalogItem.hasTag(aString);
}
needsCleaning(targetDate) {
const threshold = this.hasTag("revered") ? 700 : 1500;
return this.daysSinceLastCleaning(targetDate) > threshold;
}
daysSinceLastCleaning(targetDate) {
return this.#lastCleaned.until(targetDate, Chronounit.DAYS);
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const Chronounit = {
DAYS: "...",
};
const aDocument = [
{
id: 1,
catalogData: {
id: 1,
title: "리ν©ν°λ§",
tags: ["μννΈμ¨μ΄ 곡ν", "μλ°μ€ν¬λ¦½νΈ"],
},
lastCleaned: {
until: (targetDate, ChronounitDAYS) => 2000,
},
},
{
id: 2,
catalogData: {
id: 2,
title: "μλ°μ€ν¬λ¦½νΈ μλ²½κ°μ΄λ",
tags: ["νλ‘κ·Έλλ° μΈμ΄", "μλ°μ€ν¬λ¦½νΈ"],
},
lastCleaned: {
until: (targetDate, ChronounitDAYS) => 500,
},
},
];
const LocalDate = {
parse: (date) => date,
};
const catalog = {
get: (id) => {
const catalogItem = aDocument.find((d) => d.id === id);
return new CatalogItem(
catalogItem.id,
catalogItem.catalogData.title,
catalogItem.catalogData.tags
);
},
};
/**
* μμ νΈμΆ
*/
const scrolls = aDocument.map(
(record) =>
new Scroll(
record.id,
LocalDate.parse(record.lastCleaned),
record.catalogData.id,
catalog
)
);
scrolls.forEach((s) =>
console.log(
s.id,
s.title,
s.hasTag("μλ°μ€ν¬λ¦½νΈ"),
s.needsCleaning("2022-12-09")
)
);