Files
avicenna/service/data-hub/data-connector/src/modules/app-playground/playground.service.ts
T
Marcel Arndt ce676f20a4 commit working state
Too many changes to split them up. This commit contains roughly two months worth of work.

This commit introduces the first aggregate and rewrites the ticket system to follow DDD patterns.
It adds Spartan NG as the new component library. TanStack Query to replace GraphQL. Oh and Prisma is
almost over as well.
2026-02-11 16:50:09 +01:00

58 lines
1.7 KiB
TypeScript

import { Inject, Injectable } from '@nestjs/common';
import { Kysely } from 'kysely';
import { KYSELY_CLIENT_PROVIDER_TOKEN } from 'src/core/database/database.module';
import { DB } from 'src/core/database/types';
import { CarEntityService } from '../feat-business-objects/car-entity/car-entity.service';
import { CarEntity } from '../feat-business-objects/car-entity/car.entity';
@Injectable()
export class PlaygroundService {
constructor(
@Inject(KYSELY_CLIENT_PROVIDER_TOKEN) private readonly db: Kysely<DB>,
private readonly carService: CarEntityService,
) {}
async getCarsByOperationDay(day: Date) {
const ordinanceTypes = ['KTW', 'TSW', 'BTW'];
const cars = await Promise.all(
ordinanceTypes.map((ot) =>
this.carService.getCarsForOperationDay(day, ot),
),
);
return cars
.flat(2)
.filter(({ carName }) => !!carName)
.map((car) => this.carMapper(car))
.filter(
({ tours }) =>
tours.filter(
({ optimizationInMinutes }) => optimizationInMinutes !== 0,
).length > 0,
);
}
private carMapper(car: CarEntity) {
return {
name: car.carName,
drivers: car['plannedTimes'].map((pt) => ({
name: `${pt.firstname} ${pt.surname}`,
})),
tours: car['tours'].map((tour) => ({
id: tour.id,
operationId: tour.operationId,
ordinanceType: tour.ordinanceType,
startDate: tour.startDate,
optimizationInMinutes: tour.optimizationInMinutes,
departedForPickup: tour.startBegin,
arrivedAtPickup: tour.startEnd,
departedPickup: tour.target,
arrivedAtTarget: tour.targetBegin,
completed: tour.empty,
})),
};
}
}