-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
141 additions
and
508 deletions.
There are no files selected for viewing
12 changes: 8 additions & 4 deletions
12
apps/server/src/modules/school/api/mapper/federal-state.response.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 16 additions & 3 deletions
19
apps/server/src/modules/school/api/mapper/school-year.response.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { SchoolYearDto } from '../../domain'; | ||
import { SchoolYear } from '../../domain'; | ||
import { SchoolYearResponse } from '../dto/response'; | ||
|
||
export class SchoolYearResponseMapper { | ||
public static mapToResponse(schoolYear: SchoolYearDto): SchoolYearResponse { | ||
const res = new SchoolYearResponse(schoolYear); | ||
public static mapToResponse(schoolYear: SchoolYear): SchoolYearResponse { | ||
const schoolYearProps = schoolYear.getProps(); | ||
|
||
const res = new SchoolYearResponse({ | ||
id: schoolYear.id, | ||
name: schoolYearProps.name, | ||
startDate: schoolYearProps.startDate, | ||
endDate: schoolYearProps.endDate, | ||
}); | ||
|
||
return res; | ||
} | ||
|
||
public static mapToResponses(schoolYears: SchoolYear[]): SchoolYearResponse[] { | ||
const dtos = schoolYears.map((schoolYear) => this.mapToResponse(schoolYear)); | ||
|
||
return dtos; | ||
} | ||
} |
46 changes: 26 additions & 20 deletions
46
apps/server/src/modules/school/api/mapper/school.response.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
import { SchoolDto, SchoolForExternalInviteDto } from '../../domain'; | ||
import { SchoolForExternalInviteResponse, SchoolResponse } from '../dto/response'; | ||
import { School } from '../../domain'; | ||
import { SchoolForExternalInviteResponse, SchoolResponse, YearsResponse } from '../dto/response'; | ||
import { FederalStateResponseMapper } from './federal-state.response.mapper'; | ||
import { SchoolYearResponseMapper } from './school-year.response.mapper'; | ||
import { SystemResponseMapper } from './system.response.mapper'; | ||
import { YearsResponseMapper } from './years.response.mapper'; | ||
|
||
export class SchoolResponseMapper { | ||
public static mapToResponse(school: SchoolDto): SchoolResponse { | ||
const federalState = FederalStateResponseMapper.mapToResponse(school.federalState); | ||
const currentYear = school.currentYear && SchoolYearResponseMapper.mapToResponse(school.currentYear); | ||
const features = school.features && Array.from(school.features); | ||
const systems = school.systems?.map((system) => SystemResponseMapper.mapToResponse(system)); | ||
const years = YearsResponseMapper.mapToResponse(school.years); | ||
|
||
const res = new SchoolResponse({ | ||
...school, | ||
federalState, | ||
public static mapToResponse(school: School, years: YearsResponse): SchoolResponse { | ||
const schoolProps = school.getProps(); | ||
|
||
const federalState = FederalStateResponseMapper.mapToResponse(schoolProps.federalState); | ||
const currentYear = schoolProps.currentYear && SchoolYearResponseMapper.mapToResponse(schoolProps.currentYear); | ||
const features = schoolProps.features && Array.from(schoolProps.features); | ||
const systems = schoolProps.systems?.map((system) => SystemResponseMapper.mapToResponse(system)); | ||
|
||
const dto = new SchoolResponse({ | ||
...schoolProps, | ||
currentYear, | ||
federalState, | ||
features, | ||
systems, | ||
inMaintenance: school.isInMaintenance(), | ||
isExternal: school.isExternal(), | ||
years, | ||
}); | ||
|
||
return res; | ||
return dto; | ||
} | ||
|
||
public static mapToListForExternalInviteResponse( | ||
schools: SchoolForExternalInviteDto[] | ||
): SchoolForExternalInviteResponse[] { | ||
public static mapToListForExternalInviteResponses(schools: School[]): SchoolForExternalInviteResponse[] { | ||
const dtos = schools.map((school) => this.mapToExternalInviteResponse(school)); | ||
|
||
return dtos; | ||
} | ||
|
||
private static mapToExternalInviteResponse(school: SchoolForExternalInviteDto): SchoolForExternalInviteResponse { | ||
const res = new SchoolForExternalInviteResponse(school); | ||
private static mapToExternalInviteResponse(school: School): SchoolForExternalInviteResponse { | ||
const schoolProps = school.getProps(); | ||
|
||
const dto = new SchoolForExternalInviteResponse({ | ||
id: school.id, | ||
name: schoolProps.name, | ||
purpose: schoolProps.purpose, | ||
}); | ||
|
||
return res; | ||
return dto; | ||
} | ||
} |
19 changes: 16 additions & 3 deletions
19
apps/server/src/modules/school/api/mapper/system.response.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 60 additions & 5 deletions
65
apps/server/src/modules/school/api/mapper/years.response.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,65 @@ | ||
import { YearsDto } from '../../domain'; | ||
import { YearsResponse } from '../dto/response'; | ||
import { School, SchoolYear } from '../../domain'; | ||
import { SchoolYearResponse, YearsResponse } from '../dto/response'; | ||
import { SchoolYearResponseMapper } from './school-year.response.mapper'; | ||
|
||
export class YearsResponseMapper { | ||
public static mapToResponse(years: YearsDto) { | ||
const res = new YearsResponse(years); | ||
public static mapToResponse(school: School, schoolYears: SchoolYear[]): YearsResponse { | ||
const schoolYearResponses = SchoolYearResponseMapper.mapToResponses(schoolYears); | ||
|
||
return res; | ||
const activeYear = this.computeActiveYear(school, schoolYears); | ||
const nextYear = this.computeNextYear(schoolYears, activeYear); | ||
const lastYear = this.computeLastYear(schoolYears, activeYear); | ||
const defaultYear = activeYear || nextYear; | ||
|
||
const years = { | ||
schoolYears: schoolYearResponses, | ||
activeYear, | ||
nextYear, | ||
lastYear, | ||
defaultYear, | ||
}; | ||
|
||
return years; | ||
} | ||
|
||
private static computeActiveYear(school: School, schoolYears: SchoolYear[]): SchoolYearResponse | undefined { | ||
let activeYear = school.getProps().currentYear; | ||
|
||
if (!activeYear) { | ||
const now = new Date(); | ||
activeYear = schoolYears.find( | ||
(schoolYear) => schoolYear.getProps().startDate <= now && schoolYear.getProps().endDate >= now | ||
); | ||
} | ||
|
||
const dto = activeYear && SchoolYearResponseMapper.mapToResponse(activeYear); | ||
|
||
return dto; | ||
} | ||
|
||
private static computeNextYear( | ||
schoolYears: SchoolYear[], | ||
activeYear?: SchoolYearResponse | ||
): SchoolYearResponse | undefined { | ||
const indexOfActiveYear = schoolYears.findIndex((schoolYear) => schoolYear.id === activeYear?.id); | ||
|
||
const nextYear = schoolYears[indexOfActiveYear + 1]; | ||
|
||
const dto = nextYear && SchoolYearResponseMapper.mapToResponse(nextYear); | ||
|
||
return dto; | ||
} | ||
|
||
private static computeLastYear( | ||
schoolYears: SchoolYear[], | ||
activeYear?: SchoolYearResponse | ||
): SchoolYearResponse | undefined { | ||
const indexOfActiveYear = schoolYears.findIndex((schoolYear) => schoolYear.id === activeYear?.id); | ||
|
||
const lastYear = schoolYears[indexOfActiveYear - 1]; | ||
|
||
const dto = lastYear && SchoolYearResponseMapper.mapToResponse(lastYear); | ||
|
||
return dto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
apps/server/src/modules/school/domain/dto/federal-state.dto.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
apps/server/src/modules/school/domain/dto/school-for-external-invite.dto.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
apps/server/src/modules/school/domain/dto/school-year.dto.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.