import { Inject } from '@nestjs/common' ; import { FairCalendarView } from 'src/Application/FairCalendar/View/FairCalendarView' ; import { CooperativeNotFoundException } from '../Settings/Repository/CooperativeNotFoundException' ; import { ICooperativeRepository } from '../Settings/Repository/ICooperativeRepository' ; import { ICalendarOverview } from './ICalendarOverview' ; export class GetFairCalendarOverview { constructor ( @ Inject ( 'ICooperativeRepository' ) private readonly cooperativeRepository ) { } public async index ( items ) { const cooperative = await this . cooperativeRepository . find ( ) ; if ( ! cooperative ) { throw new CooperativeNotFoundException ( ) ; } const overviewInDays = { mission : 0 , dojo : 0 , formationConference : 0 , leave : 0 , support : 0 , other : 0 } ; for ( const { time , type : itemType , project } of items ) { const type = itemType . startsWith ( 'leave_' ) ? 'leave' : itemType ; const dayDuration = project ? project . dayDuration : cooperative . getDayDuration ( ) ; const days = time / dayDuration ; overviewInDays [ type ] = Math . round ( ( overviewInDays [ type ] + days ) * 100 ) / 100 ; } return overviewInDays ; } }