-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournalController.ts
47 lines (38 loc) · 1.17 KB
/
journalController.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
import { CreateJournalDTO, Journal } from "./journal.ts";
import { JournalRepository } from "./journalRepository.ts";
export class JournalController {
constructor(
private readonly journalRepository: JournalRepository,
) {}
async add(journal: Journal) {
await this.journalRepository.add(journal);
}
async delete(journal: Journal | null) {
if (!journal) {
return;
}
// If the journal is not a favorite, just delete it.
if (!journal.getIsFavorite()) {
await this.journalRepository.delete(journal);
return;
}
// If the journal is a favorite, open the confirmation window and set it to pending deletion.
await this.journalRepository.delete(journal);
}
async setFavorite(journal: Journal) {
if (journal.getIsFavorite()) {
return;
}
await this.journalRepository.setFavorite(journal);
}
async addFromFormSubmit(createJournalInput: CreateJournalDTO) {
const newJournal = Journal.create(createJournalInput);
await this.add(newJournal);
}
resetPendingDeletion() {
this.journalRepository.resetPendingDeletion();
}
setConfirmationModal() {
this.journalRepository.setConfirmationModal();
}
}