Skip to content

Commit

Permalink
[FEATURE] Proposer le QRCode des évènements via un pass Apple Wallet
Browse files Browse the repository at this point in the history
Merge pull request #2 from VincentHardouin/feat-add-pass
  • Loading branch information
VincentHardouin authored Oct 6, 2024
2 parents 5e446fe + 1b9e29c commit 229c18a
Show file tree
Hide file tree
Showing 47 changed files with 1,383 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache: npm

- name: Install
run: npm ci
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.env
.env
certs/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Voici les différentes étapes pour pouvoir préparer correctement sa venue :

![Les différentes étapes de réservation](./docs/étapes-reservation.png)

Le projet est composé actuellement de 4 grandes étapes :
Le projet est composé actuellement de 5 grandes étapes :

1. Vérifier qu'une nouvelle réservation a été demandée sur Gymlib
2. Remplir le formulaire de contremarque UCPA
3. Recevoir une notification dès que l'UCPA a validé les informations avec des créneaux arrangeants qui sont disponibles
4. Créer des évènements dans un calendrier et proposer une url pour s'abonner au calendrier `/reservations/calendar`.
5. Créer un pass Apple Wallet qui se met à jour pour chaque réservation

A venir :

1. Créer un pass Apple Wallet pour chaque évènement
2. Me notifier de créneaux qui m'arrangent qui se libèrent

La réservation du créneau se fait donc toujours manuellement sur le site de l'UCPA, mais toutes les étapes contraignantes
Expand Down
11 changes: 11 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function buildConfiguration() {
const config = {
environment: env.NODE_ENV || 'development',
port: env.PORT || 3000,
baseURL: env.BASE_URL || 'http://example.net',
secret: env.SECRET,
logging: {
enabled: isFeatureEnabled(env.LOG_ENABLED),
logLevel: env.LOG_LEVEL || 'info',
Expand Down Expand Up @@ -52,9 +54,18 @@ function buildConfiguration() {
id: env.CALENDAR_ID,
},
timeSlotsPreferences: getParsedJson(env.TIME_SLOTS_PREFERENCES),
certificates: {
signerKeyPassphrase: env.CERTIFICATES_SIGNER_KEY_PASSPHRASE,
},
pass: {
passTypeIdentifier: env.PASS_TYPE_IDENTIFIER,
teamIdentifier: env.PASS_TEAM_IDENTIFIER,
},
};
if (config.environment === 'test') {
config.logging.enabled = false;
config.secret = 'SECRET_FOR_TESTS';
config.pass.passTypeIdentifier = 'pass-identifier';
}

if (!verifyConfig(config)) {
Expand Down
40 changes: 40 additions & 0 deletions db/migrations/20240929100654_create_pass_tables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
const up = async function (knex) {
await knex.schema.createTable('devices', (table) => {
table.string('deviceLibraryIdentifier').primary();
table.string('pushToken').notNullable();
table.dateTime('created_at').notNullable().defaultTo(knex.fn.now());
});

await knex.schema.createTable('passes', (table) => {
table.string('passTypeIdentifier').notNullable();
table.string('serialNumber').notNullable().unique();
table.string('nextEvent').defaultTo(null);
table.timestamp('updated_at').notNullable().defaultTo(knex.fn.now());
});

await knex.schema.createTable('registrations', (table) => {
table.string('passTypeIdentifier');
table.string('serialNumber').references('passes.serialNumber');
table.string('deviceLibraryIdentifier').references('devices.deviceLibraryIdentifier');
table.dateTime('created_at').notNullable().defaultTo(knex.fn.now());
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
const down = async function (knex) {
await knex.schema.dropTable('registrations');
await knex.schema.dropTable('passes');
await knex.schema.dropTable('devices');
};

export {
down,
up,
};
Binary file added docs/favicon.ico
Binary file not shown.
82 changes: 5 additions & 77 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import { CronJob } from 'cron';

import { config } from './config.js';

import { createServer } from './server.js';
import { ReservationController } from './src/application/ReservationController.js';
import { CreateReservationEventsUseCase } from './src/domain/usecases/CreateReservationEventsUseCase.js';
import { GetActiveReservationsUseCase } from './src/domain/usecases/GetActiveReservationsUseCase.js';
import { GetAllEventsUseCase } from './src/domain/usecases/GetAllEventsUseCase.js';
import { HandleNewReservationUseCase } from './src/domain/usecases/HandleNewReservationUseCase.js';
import { HandleScheduledReservationUseCase } from './src/domain/usecases/HandleScheduledReservationUseCase.js';
import { NotifyUseCase } from './src/domain/usecases/NotifyUseCase.js';
import { SubmitFormUseCase } from './src/domain/usecases/SubmitFormUseCase.js';
import { Browser } from './src/infrastructure/Browser.js';
import { CalendarRepository } from './src/infrastructure/CalendarRepository.js';
import { ImapClient } from './src/infrastructure/ImapClient.js';
import { passController, reservationController } from './src/application/index.js';
import { authService } from './src/infrastructure/AuthService.js';
import { logger } from './src/infrastructure/logger.js';
import { NotificationClient } from './src/infrastructure/NotificationClient.js';
import { reservationRepository } from './src/infrastructure/ReservationRepository.js';
import { TimeSlotDatasource } from './src/infrastructure/TimeSlotDatasource.js';

const parisTimezone = 'Europe/Paris';

main();

async function main() {
const reservationController = await getReservationController();
CronJob.from({
cronTime: config.cronTime,
onTick: async () => {
Expand All @@ -33,67 +19,9 @@ async function main() {
logger.info('End job');
},
start: true,
runOnInit: true,
timeZone: parisTimezone,
});
const server = await createServer({ reservationController });
const server = await createServer({ reservationController, authService, passController });
await server.start();
}

async function getReservationController() {
const gymlibImapClient = new ImapClient(config.gymlib.imapConfig);
const handleNewReservationUseCase = new HandleNewReservationUseCase({
imapClient: gymlibImapClient,
searchQuery: config.gymlib.searchQuery,
});

const getActiveReservationsUseCase = new GetActiveReservationsUseCase({
reservationRepository,
});

const browser = await Browser.create();
const submitFormUseCase = new SubmitFormUseCase({
browser,
reservationRepository,
formInfo: config.ucpa.formInfo,
dryRun: !config.ucpa.formSubmit,
});

const ucpaImapClient = new ImapClient(config.ucpa.imapConfig);
const timeSlotDatasource = new TimeSlotDatasource();
const notificationClient = new NotificationClient(config.notification);
const notifyUseCase = new NotifyUseCase({
imapClient: ucpaImapClient,
searchQuery: config.ucpa.searchQuery,
reservationRepository,
timeSlotDatasource,
notificationClient,
timeSlotsPreferences: config.timeSlotsPreferences,
areaId: config.ucpa.areaId,
});

const handleScheduledReservationUseCase = new HandleScheduledReservationUseCase({
imapClient: ucpaImapClient,
searchQuery: config.ucpa.searchQuery,
reservationRepository,
});

const calendarRepository = new CalendarRepository(config.calendar.name);

const createReservationEventsUseCase = new CreateReservationEventsUseCase({
reservationRepository,
calendarRepository,
});

const getAllEventsUseCase = new GetAllEventsUseCase({ calendarRepository });

return new ReservationController({
handleNewReservationUseCase,
getActiveReservationsUseCase,
submitFormUseCase,
notifyUseCase,
handleScheduledReservationUseCase,
createReservationEventsUseCase,
getAllEventsUseCase,
logger,
});
}
};
Binary file added model.pass/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added model.pass/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added model.pass/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added model.pass/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added model.pass/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added model.pass/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions model.pass/pass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"formatVersion": 1,
"locations": [
{
"longitude": 2.371645,
"latitude": 48.896370
}
],
"organizationName": "Vincent Hardouin",
"description": "UCPA Reservation ticket",
"labelColor": "rgb(255, 255, 255)",
"foregroundColor": "rgb(255, 255, 255)",
"backgroundColor": "rgb(76, 19, 223)",
"eventTicket": {
"primaryFields": [
],
"secondaryFields": [
]
}
}
Loading

0 comments on commit 229c18a

Please sign in to comment.