1
1
import { CronJob } from 'cron' ;
2
2
3
3
import { config } from './config.js' ;
4
-
5
4
import { createServer } from './server.js' ;
6
- import { ReservationController } from './src/application/ReservationController.js' ;
7
- import { CreateReservationEventsUseCase } from './src/domain/usecases/CreateReservationEventsUseCase.js' ;
8
- import { GetActiveReservationsUseCase } from './src/domain/usecases/GetActiveReservationsUseCase.js' ;
9
- import { GetAllEventsUseCase } from './src/domain/usecases/GetAllEventsUseCase.js' ;
10
- import { HandleNewReservationUseCase } from './src/domain/usecases/HandleNewReservationUseCase.js' ;
11
- import { HandleScheduledReservationUseCase } from './src/domain/usecases/HandleScheduledReservationUseCase.js' ;
12
- import { NotifyUseCase } from './src/domain/usecases/NotifyUseCase.js' ;
13
- import { SubmitFormUseCase } from './src/domain/usecases/SubmitFormUseCase.js' ;
14
- import { Browser } from './src/infrastructure/Browser.js' ;
15
- import { CalendarRepository } from './src/infrastructure/CalendarRepository.js' ;
16
- import { ImapClient } from './src/infrastructure/ImapClient.js' ;
5
+ import { passController , reservationController } from './src/application/index.js' ;
6
+ import { authService } from './src/infrastructure/AuthService.js' ;
17
7
import { logger } from './src/infrastructure/logger.js' ;
18
- import { NotificationClient } from './src/infrastructure/NotificationClient.js' ;
19
- import { reservationRepository } from './src/infrastructure/ReservationRepository.js' ;
20
- import { TimeSlotDatasource } from './src/infrastructure/TimeSlotDatasource.js' ;
21
8
22
9
const parisTimezone = 'Europe/Paris' ;
23
10
24
11
main ( ) ;
25
12
26
13
async function main ( ) {
27
- const reservationController = await getReservationController ( ) ;
28
14
CronJob . from ( {
29
15
cronTime : config . cronTime ,
30
16
onTick : async ( ) => {
@@ -33,67 +19,9 @@ async function main() {
33
19
logger . info ( 'End job' ) ;
34
20
} ,
35
21
start : true ,
22
+ runOnInit : true ,
36
23
timeZone : parisTimezone ,
37
24
} ) ;
38
- const server = await createServer ( { reservationController } ) ;
25
+ const server = await createServer ( { reservationController, authService , passController } ) ;
39
26
await server . start ( ) ;
40
- }
41
-
42
- async function getReservationController ( ) {
43
- const gymlibImapClient = new ImapClient ( config . gymlib . imapConfig ) ;
44
- const handleNewReservationUseCase = new HandleNewReservationUseCase ( {
45
- imapClient : gymlibImapClient ,
46
- searchQuery : config . gymlib . searchQuery ,
47
- } ) ;
48
-
49
- const getActiveReservationsUseCase = new GetActiveReservationsUseCase ( {
50
- reservationRepository,
51
- } ) ;
52
-
53
- const browser = await Browser . create ( ) ;
54
- const submitFormUseCase = new SubmitFormUseCase ( {
55
- browser,
56
- reservationRepository,
57
- formInfo : config . ucpa . formInfo ,
58
- dryRun : ! config . ucpa . formSubmit ,
59
- } ) ;
60
-
61
- const ucpaImapClient = new ImapClient ( config . ucpa . imapConfig ) ;
62
- const timeSlotDatasource = new TimeSlotDatasource ( ) ;
63
- const notificationClient = new NotificationClient ( config . notification ) ;
64
- const notifyUseCase = new NotifyUseCase ( {
65
- imapClient : ucpaImapClient ,
66
- searchQuery : config . ucpa . searchQuery ,
67
- reservationRepository,
68
- timeSlotDatasource,
69
- notificationClient,
70
- timeSlotsPreferences : config . timeSlotsPreferences ,
71
- areaId : config . ucpa . areaId ,
72
- } ) ;
73
-
74
- const handleScheduledReservationUseCase = new HandleScheduledReservationUseCase ( {
75
- imapClient : ucpaImapClient ,
76
- searchQuery : config . ucpa . searchQuery ,
77
- reservationRepository,
78
- } ) ;
79
-
80
- const calendarRepository = new CalendarRepository ( config . calendar . name ) ;
81
-
82
- const createReservationEventsUseCase = new CreateReservationEventsUseCase ( {
83
- reservationRepository,
84
- calendarRepository,
85
- } ) ;
86
-
87
- const getAllEventsUseCase = new GetAllEventsUseCase ( { calendarRepository } ) ;
88
-
89
- return new ReservationController ( {
90
- handleNewReservationUseCase,
91
- getActiveReservationsUseCase,
92
- submitFormUseCase,
93
- notifyUseCase,
94
- handleScheduledReservationUseCase,
95
- createReservationEventsUseCase,
96
- getAllEventsUseCase,
97
- logger,
98
- } ) ;
99
- }
27
+ } ;
0 commit comments