Skip to content

Commit

Permalink
Merge branch 'hotfix/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenkii committed Apr 23, 2023
2 parents 0749216 + 8deefeb commit 60417b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vacdm-backend",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "app.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface vacdmConfig {

eventUrl: string;
eventPrio: number;
eventPullInterval: number;

clientId: string;
clientSecret: string;
Expand Down Expand Up @@ -57,6 +58,7 @@ export default function config(): vacdmConfig {

eventUrl: process.env.EVENT_URL || 'https://slots.vatsim-germany.org/api/events/',
eventPrio: Number(process.env.EVENT_PRIO) || 5,
eventPullInterval: Number(process.env.EVENT_PULL_INTERVAL || 5),

vatsimAuthUrl: options.vatsimAuthUrl,
clientId: options.vatsimAuthClientId,
Expand Down
48 changes: 30 additions & 18 deletions backend/src/services/bookings.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
import axios from 'axios';
import config from '../config';
import dayjs from 'dayjs';
import Logger from '@dotfionn/logger';

export async function getAllBookings() {
try {
const events = await axios.get(
config().eventUrl
);
const logger = new Logger('vACDM:services:booking');

const relevantEvents = events.data.data.filter((e) =>
dayjs(new Date()) >= dayjs(e.startEvent) &&
dayjs(new Date()) <= dayjs(e.endEvent)
);
let lastPull: Date | null = null;
let relevantBookings: any[] | null = null;

const relevantBookings: any[] = [];

for (let event of relevantEvents) {
const bookings = await axios.get(event.links.bookings);
export async function getAllBookings() {
const duration = dayjs().diff(dayjs(lastPull), 'minute');

for (let booking of bookings.data.data) {
relevantBookings.push(booking);
try {
if (
relevantBookings === null ||
lastPull === null ||
duration > config().eventPullInterval
) {
logger.debug('Get latest Bookings');
const events = await axios.get(config().eventUrl);
lastPull = new Date();
const relevantEvents = events.data.data.filter(
(e) =>
dayjs(new Date()) >= dayjs(e.startEvent) &&
dayjs(new Date()) <= dayjs(e.endEvent)
);

relevantBookings = [];

for (let event of relevantEvents) {
const bookings = await axios.get(event.links.bookings);

for (let booking of bookings.data.data) {
relevantBookings.push(booking);
}
}
}

Expand All @@ -34,14 +48,12 @@ export async function pilotHasBooking(cid: number): Promise<boolean> {
const bookings = await getAllBookings();

return bookings.findIndex((b) => b.user === cid) != -1;


} catch (error) {
throw error;
}
}

export default {
getAllBookings,
pilotHasBooking
pilotHasBooking,
};
12 changes: 2 additions & 10 deletions backend/src/services/cdm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function determineInitialBlock(pilot: PilotDocument): {
};
}


export async function putPilotIntoBlock(
pilot: PilotDocument,
allPilots: PilotDocument[]
Expand Down Expand Up @@ -179,11 +180,6 @@ export async function cleanupPilots() {
})
.exec();

logger.debug(
new Date(Date.now() - config().timeframes.timeSinceInactive),
new Date()
);

logger.debug('pilotsToBeDeleted', pilotsToBeDeleted);

for (let pilot of pilotsToBeDeleted) {
Expand Down Expand Up @@ -231,9 +227,7 @@ export async function optimizeBlockAssignments() {

const datafeedData = await datafeedService.getRawDatafeed();

for (let pilot of allPilots) {
console.log(pilot.callsign);

for (let pilot of allPilots) {
if (pilot.hasBooking) {
continue;
}
Expand All @@ -252,8 +246,6 @@ export async function optimizeBlockAssignments() {


}

console.log('done');

const nowPlusTen = timeUtils.addMinutes(new Date(), 10);

Expand Down

0 comments on commit 60417b8

Please sign in to comment.