(dc): init reports feature

Initial step in creating a data reference
This commit is contained in:
Marcel Arndt 2024-07-18 13:43:14 +02:00
parent 53e945253c
commit 62eafe44dd
5 changed files with 119 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import { TicketSystemModule } from './modules/feat-tickets/ticket-system.module'
import { DatabaseModule } from './core/database/database.module'; import { DatabaseModule } from './core/database/database.module';
import { PostgresDialect } from 'kysely'; import { PostgresDialect } from 'kysely';
import { Pool } from 'pg'; import { Pool } from 'pg';
import { FeatReportsModule } from './modules/feat-reports/feat-reports.module';
@Module({ @Module({
imports: [ imports: [
@ -29,6 +30,7 @@ import { Pool } from 'pg';
ScheduleModule.forRoot(), ScheduleModule.forRoot(),
EventEmitterModule.forRoot(), EventEmitterModule.forRoot(),
FeatureImporterModule, FeatureImporterModule,
FeatReportsModule,
TicketSystemModule, TicketSystemModule,
], ],
controllers: [AppController], controllers: [AppController],

View File

@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { ReportsController } from './reports.controller';
import { ReportsService } from './reports.service';
import { PrismaModule } from 'src/core/database/prisma.module';
import { ReportsRepository } from './reports.repository';
@Module({
imports: [PrismaModule],
providers: [ReportsService, ReportsRepository],
controllers: [ReportsController],
})
export class FeatReportsModule {}

View File

@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { ReportsService } from './reports.service';
@Controller('reports')
export class ReportsController {
constructor(private readonly service: ReportsService) {}
@Get('/tours')
async getToursReport() {
return this.service.report();
}
}

View File

@ -0,0 +1,71 @@
import { Inject, Injectable } from '@nestjs/common';
import { Kysely, sql } from 'kysely';
import { KYSELY_CLIENT_PROVIDER_TOKEN } from 'src/core/database/database.module';
import { DB } from 'src/core/database/types';
@Injectable()
export class ReportsRepository {
constructor(
@Inject(KYSELY_CLIENT_PROVIDER_TOKEN) private readonly db: Kysely<DB>,
) {}
toursReport() {
return this.db
.selectFrom('Tour')
.select((eb) => [
'ordinanceType as Verordnungsart',
sql<string>`EXTRACT(MONTH FROM "startDate")`.as('MonthNumber'),
eb.fn.count<number>('operationId').as('TourCount'),
])
.groupBy('MonthNumber')
.groupBy('ordinanceType')
.execute();
}
patientsReport() {
return this.db
.selectFrom('Patient')
.select((eb) => eb.fn.countAll().as('PatientCount'))
.execute();
}
employeesReport() {
return this.db
.selectFrom('Employee')
.select((eb) => eb.fn.countAll().as('EmployeeCount'))
.execute();
}
attendanceRegistrationsReport() {
return this.db
.selectFrom('AttendanceRegistration')
.select((eb) => [
eb.fn.countAll().as('AttendanceRegistrationCount'),
sql<string>`EXTRACT(MONTH FROM "dateTime")`.as('MonthNumber'),
])
.groupBy('MonthNumber')
.execute();
}
workTimesReport() {
return this.db
.selectFrom('WorkTime')
.select((eb) => [
eb.fn.countAll().as('WorkTimeCount'),
sql<string>`EXTRACT(MONTH FROM "startDate")`.as('MonthNumber'),
])
.groupBy('MonthNumber')
.execute();
}
plannedTimesReport() {
return this.db
.selectFrom('PlannedTime')
.select((eb) => [
eb.fn.countAll().as('PlannedTimeCount'),
sql<string>`EXTRACT(MONTH FROM "startDate")`.as('MonthNumber'),
])
.groupBy('MonthNumber')
.execute();
}
}

View File

@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';
import { ReportsRepository } from './reports.repository';
@Injectable()
export class ReportsService {
constructor(private readonly repository: ReportsRepository) {}
async toursReport() {
return this.repository.toursReport();
}
report() {
return Promise.all([
this.repository.toursReport(),
this.repository.employeesReport(),
this.repository.patientsReport(),
this.repository.attendanceRegistrationsReport(),
this.repository.plannedTimesReport(),
this.repository.workTimesReport(),
]);
}
}