diff --git a/apps/server/src/modules/school/api/mapper/federal-state.response.mapper.ts b/apps/server/src/modules/school/api/mapper/federal-state.response.mapper.ts index 5369932ac33..762626c7f68 100644 --- a/apps/server/src/modules/school/api/mapper/federal-state.response.mapper.ts +++ b/apps/server/src/modules/school/api/mapper/federal-state.response.mapper.ts @@ -1,12 +1,16 @@ -import { County, FederalStateDto } from '../../domain'; +import { County, FederalState } from '../../domain'; import { CountyResponse, FederalStateResponse } from '../dto/response'; export class FederalStateResponseMapper { - public static mapToResponse(federalState: FederalStateDto): FederalStateResponse { - const counties = federalState.counties && this.mapToCountyResponses(federalState.counties); + public static mapToResponse(federalState: FederalState): FederalStateResponse { + const federalStateProps = federalState.getProps(); + const counties = federalStateProps.counties && this.mapToCountyResponses(federalStateProps.counties); const res = new FederalStateResponse({ - ...federalState, + id: federalState.id, + name: federalStateProps.name, + abbreviation: federalStateProps.abbreviation, + logoUrl: federalStateProps.logoUrl, counties, }); diff --git a/apps/server/src/modules/school/api/mapper/school-year.response.mapper.ts b/apps/server/src/modules/school/api/mapper/school-year.response.mapper.ts index bf05a41c8c8..20975ceba57 100644 --- a/apps/server/src/modules/school/api/mapper/school-year.response.mapper.ts +++ b/apps/server/src/modules/school/api/mapper/school-year.response.mapper.ts @@ -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; + } } diff --git a/apps/server/src/modules/school/api/mapper/school.response.mapper.ts b/apps/server/src/modules/school/api/mapper/school.response.mapper.ts index 32645886f30..f7027a6e6b3 100644 --- a/apps/server/src/modules/school/api/mapper/school.response.mapper.ts +++ b/apps/server/src/modules/school/api/mapper/school.response.mapper.ts @@ -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; } } diff --git a/apps/server/src/modules/school/api/mapper/system.response.mapper.ts b/apps/server/src/modules/school/api/mapper/system.response.mapper.ts index 46a53893281..5e4dfe3cd08 100644 --- a/apps/server/src/modules/school/api/mapper/system.response.mapper.ts +++ b/apps/server/src/modules/school/api/mapper/system.response.mapper.ts @@ -1,9 +1,22 @@ -import { SystemDto } from '../../domain'; +import { System } from '../../domain'; import { SystemResponse } from '../dto/response'; export class SystemResponseMapper { - public static mapToResponse(system: SystemDto): SystemResponse { - const res = new SystemResponse(system); + public static mapToResponse(system: System): SystemResponse { + const systemProps = system.getProps(); + + const res = new SystemResponse({ + id: system.id, + type: systemProps.type, + url: systemProps.url, + alias: systemProps.alias, + displayName: systemProps.displayName, + oauthConfig: systemProps.oauthConfig, + oidcConfig: systemProps.oidcConfig, + ldapConfig: systemProps.ldapConfig, + provisioningStrategy: systemProps.provisioningStrategy, + provisioningUrl: systemProps.provisioningUrl, + }); return res; } diff --git a/apps/server/src/modules/school/api/mapper/years.response.mapper.ts b/apps/server/src/modules/school/api/mapper/years.response.mapper.ts index d5f2241ac1f..a9a3993da98 100644 --- a/apps/server/src/modules/school/api/mapper/years.response.mapper.ts +++ b/apps/server/src/modules/school/api/mapper/years.response.mapper.ts @@ -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; } } diff --git a/apps/server/src/modules/school/api/school.controller.ts b/apps/server/src/modules/school/api/school.controller.ts index d44a7cd7c28..d59df46176b 100644 --- a/apps/server/src/modules/school/api/school.controller.ts +++ b/apps/server/src/modules/school/api/school.controller.ts @@ -2,10 +2,10 @@ import { Authenticate, CurrentUser } from '@modules/authentication/decorator/aut import { ICurrentUser } from '@modules/authentication/interface/user'; import { Controller, Get, Param, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { SchoolUc } from '../domain'; import { SchoolQueryParams, SchoolUrlParams } from './dto/param'; import { SchoolForExternalInviteResponse, SchoolResponse } from './dto/response'; import { SchoolResponseMapper } from './mapper'; +import { SchoolUc } from './school.uc'; @ApiTags('School') @Authenticate('jwt') @@ -21,9 +21,7 @@ export class SchoolController { @Param() urlParams: SchoolUrlParams, @CurrentUser() user: ICurrentUser ): Promise { - const school = await this.schoolUc.getSchool(urlParams.schoolId, user.userId); - - const res = SchoolResponseMapper.mapToResponse(school); + const res = await this.schoolUc.getSchool(urlParams.schoolId, user.userId); return res; } @@ -34,9 +32,7 @@ export class SchoolController { @Query() query: SchoolQueryParams, @CurrentUser() user: ICurrentUser ): Promise { - const schools = await this.schoolUc.getSchoolListForExternalInvite(query, user.schoolId); - - const res = SchoolResponseMapper.mapToListForExternalInviteResponse(schools); + const res = await this.schoolUc.getSchoolListForExternalInvite(query, user.schoolId); return res; } diff --git a/apps/server/src/modules/school/domain/uc/school.uc.ts b/apps/server/src/modules/school/api/school.uc.ts similarity index 69% rename from apps/server/src/modules/school/domain/uc/school.uc.ts rename to apps/server/src/modules/school/api/school.uc.ts index ef160126917..d291031af5c 100644 --- a/apps/server/src/modules/school/domain/uc/school.uc.ts +++ b/apps/server/src/modules/school/api/school.uc.ts @@ -3,11 +3,11 @@ import { AuthorizationService } from '@modules/authorization/domain/service/auth import { Injectable } from '@nestjs/common'; import { SortOrder } from '@shared/domain'; import { EntityId } from '@shared/domain/types/entity-id'; -import { SchoolDto, SchoolForExternalInviteDto } from '../dto'; -import { SchoolDtoMapper } from '../mapper'; -import { YearsDtoMapper } from '../mapper/years.dto.mapper'; -import { SchoolQuery } from '../query'; -import { SchoolService, SchoolYearService } from '../service'; +import { SchoolQuery } from '../domain/query'; +import { SchoolService, SchoolYearService } from '../domain/service'; +import { SchoolForExternalInviteResponse, SchoolResponse } from './dto/response'; +import { SchoolResponseMapper } from './mapper'; +import { YearsResponseMapper } from './mapper/years.response.mapper'; @Injectable() export class SchoolUc { @@ -17,7 +17,7 @@ export class SchoolUc { private readonly schoolYearService: SchoolYearService ) {} - public async getSchool(schoolId: EntityId, userId: EntityId): Promise { + public async getSchool(schoolId: EntityId, userId: EntityId): Promise { const school = await this.schoolService.getSchool(schoolId); const user = await this.authorizationService.getUserWithPermissions(userId); @@ -25,9 +25,9 @@ export class SchoolUc { this.authorizationService.checkPermission(user, school, authContext); const schoolYears = await this.schoolYearService.getAllSchoolYears(); - const yearsDto = YearsDtoMapper.mapToDto(school, schoolYears); + const yearsResponse = YearsResponseMapper.mapToResponse(school, schoolYears); - const dto = SchoolDtoMapper.mapToDto(school, yearsDto); + const dto = SchoolResponseMapper.mapToResponse(school, yearsResponse); return dto; } @@ -35,7 +35,7 @@ export class SchoolUc { public async getSchoolListForExternalInvite( query: SchoolQuery, ownSchoolId: EntityId - ): Promise { + ): Promise { const findOptions = { order: { name: SortOrder.asc, @@ -46,7 +46,7 @@ export class SchoolUc { // TODO: Do we want authorization here? At the moment there is no fitting permission. - const dtos = SchoolDtoMapper.mapToListForExternalInviteDtos(schools); + const dtos = SchoolResponseMapper.mapToListForExternalInviteResponses(schools); return dtos; } diff --git a/apps/server/src/modules/school/domain/dto/federal-state.dto.ts b/apps/server/src/modules/school/domain/dto/federal-state.dto.ts deleted file mode 100644 index 56cd03da233..00000000000 --- a/apps/server/src/modules/school/domain/dto/federal-state.dto.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { County } from '../type'; - -export class FederalStateDto { - constructor(props: FederalStateDto) { - this.id = props.id; - this.name = props.name; - this.abbreviation = props.abbreviation; - this.logoUrl = props.logoUrl; - this.counties = props.counties; - } - - id: string; - - name: string; - - abbreviation: string; - - logoUrl: string; - - counties?: County[]; -} diff --git a/apps/server/src/modules/school/domain/dto/index.ts b/apps/server/src/modules/school/domain/dto/index.ts deleted file mode 100644 index 2c1df0e358e..00000000000 --- a/apps/server/src/modules/school/domain/dto/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './federal-state.dto'; -export * from './school.dto'; -export * from './school-year.dto'; -export * from './school-for-external-invite.dto'; -export * from './system.dto'; -export * from './years.dto'; diff --git a/apps/server/src/modules/school/domain/dto/school-for-external-invite.dto.ts b/apps/server/src/modules/school/domain/dto/school-for-external-invite.dto.ts deleted file mode 100644 index a1ef4f6394e..00000000000 --- a/apps/server/src/modules/school/domain/dto/school-for-external-invite.dto.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { SchoolPurpose } from '../type'; - -export class SchoolForExternalInviteDto { - constructor(props: SchoolForExternalInviteDto) { - this.id = props.id; - this.name = props.name; - this.purpose = props.purpose; - } - - id: string; - - name: string; - - purpose?: SchoolPurpose; -} diff --git a/apps/server/src/modules/school/domain/dto/school-year.dto.ts b/apps/server/src/modules/school/domain/dto/school-year.dto.ts deleted file mode 100644 index 03427d4c131..00000000000 --- a/apps/server/src/modules/school/domain/dto/school-year.dto.ts +++ /dev/null @@ -1,16 +0,0 @@ -export class SchoolYearDto { - constructor(props: SchoolYearDto) { - this.id = props.id; - this.name = props.name; - this.startDate = props.startDate; - this.endDate = props.endDate; - } - - id: string; - - name: string; - - startDate: Date; - - endDate: Date; -} diff --git a/apps/server/src/modules/school/domain/dto/school.dto.ts b/apps/server/src/modules/school/domain/dto/school.dto.ts deleted file mode 100644 index b962c5c34a7..00000000000 --- a/apps/server/src/modules/school/domain/dto/school.dto.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { County, FileStorageType, SchoolFeature, SchoolPermissions, SchoolPurpose } from '../type'; -import { FederalStateDto } from './federal-state.dto'; -import { SchoolYearDto } from './school-year.dto'; -import { SystemDto } from './system.dto'; -import { YearsDto } from './years.dto'; - -export class SchoolDto { - constructor(props: SchoolDto) { - this.id = props.id; - this.name = props.name; - this.officialSchoolNumber = props.officialSchoolNumber; - this.federalState = props.federalState; - this.currentYear = props.currentYear; - this.purpose = props.purpose; - this.features = props.features; - this.county = props.county; - this.systems = props.systems; - this.inMaintenance = props.inMaintenance; - this.isExternal = props.isExternal; - this.logo_dataUrl = props.logo_dataUrl; - this.fileStorageType = props.fileStorageType; - this.language = props.language; - this.timezone = props.timezone; - this.permissions = props.permissions; - this.years = props.years; - } - - id: string; - - name: string; - - officialSchoolNumber?: string; - - currentYear?: SchoolYearDto; - - federalState: FederalStateDto; - - county?: County; - - purpose?: SchoolPurpose; - - features?: SchoolFeature[]; - - systems?: SystemDto[]; - - inMaintenance: boolean; - - isExternal: boolean; - - logo_dataUrl?: string; - - fileStorageType?: FileStorageType; - - language?: string; - - timezone?: string; - - permissions?: SchoolPermissions; - - years: YearsDto; -} diff --git a/apps/server/src/modules/school/domain/dto/system.dto.ts b/apps/server/src/modules/school/domain/dto/system.dto.ts deleted file mode 100644 index 92bcda27d6d..00000000000 --- a/apps/server/src/modules/school/domain/dto/system.dto.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { LdapConfig, OauthConfig, OidcConfig } from '../type'; - -export class SystemDto { - constructor(props: SystemDto) { - this.id = props.id; - this.type = props.type; - this.url = props.url; - this.alias = props.alias; - this.displayName = props.displayName; - this.oauthConfig = props.oauthConfig; - this.oidcConfig = props.oidcConfig; - this.ldapConfig = props.ldapConfig; - this.provisioningStrategy = props.provisioningStrategy; - this.provisioningUrl = props.provisioningUrl; - } - - id: string; - - type: string; - - url?: string; - - alias?: string; - - displayName?: string; - - oauthConfig?: OauthConfig; - - oidcConfig?: OidcConfig; - - ldapConfig?: LdapConfig; - - provisioningStrategy?: SystemProvisioningStrategy; - - provisioningUrl?: string; -} diff --git a/apps/server/src/modules/school/domain/dto/years.dto.ts b/apps/server/src/modules/school/domain/dto/years.dto.ts deleted file mode 100644 index 1b4311e73ff..00000000000 --- a/apps/server/src/modules/school/domain/dto/years.dto.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { SchoolYearDto } from './school-year.dto'; - -export class YearsDto { - constructor(props: YearsDto) { - this.schoolYears = props.schoolYears; - this.defaultYear = props.defaultYear; - this.activeYear = props.activeYear; - this.lastYear = props.lastYear; - this.nextYear = props.nextYear; - } - - schoolYears: SchoolYearDto[]; - - activeYear?: SchoolYearDto; - - defaultYear?: SchoolYearDto; - - lastYear?: SchoolYearDto; - - nextYear?: SchoolYearDto; -} diff --git a/apps/server/src/modules/school/domain/index.ts b/apps/server/src/modules/school/domain/index.ts index 6e37d6c3de4..c716418571b 100644 --- a/apps/server/src/modules/school/domain/index.ts +++ b/apps/server/src/modules/school/domain/index.ts @@ -1,7 +1,5 @@ export * from './do'; -export * from './dto'; export * from './interface'; export * from './query'; export * from './service'; export * from './type'; -export * from './uc'; diff --git a/apps/server/src/modules/school/domain/mapper/federal-state.dto.mapper.ts b/apps/server/src/modules/school/domain/mapper/federal-state.dto.mapper.ts deleted file mode 100644 index 6737b56f562..00000000000 --- a/apps/server/src/modules/school/domain/mapper/federal-state.dto.mapper.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { FederalState } from '../do'; -import { FederalStateDto } from '../dto'; - -export class FederalStateDtoMapper { - public static mapToDto(federalState: FederalState): FederalStateDto { - const federalStateProps = federalState.getProps(); - - const dto = new FederalStateDto({ - id: federalState.id, - name: federalStateProps.name, - abbreviation: federalStateProps.abbreviation, - logoUrl: federalStateProps.logoUrl, - counties: federalStateProps.counties, - }); - - return dto; - } -} diff --git a/apps/server/src/modules/school/domain/mapper/index.ts b/apps/server/src/modules/school/domain/mapper/index.ts deleted file mode 100644 index 5c945ae21d0..00000000000 --- a/apps/server/src/modules/school/domain/mapper/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './school.dto.mapper'; -export * from './school-year.dto.mapper'; diff --git a/apps/server/src/modules/school/domain/mapper/school-year.dto.mapper.ts b/apps/server/src/modules/school/domain/mapper/school-year.dto.mapper.ts deleted file mode 100644 index 5e7b8afcd5d..00000000000 --- a/apps/server/src/modules/school/domain/mapper/school-year.dto.mapper.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { SchoolYear } from '../do'; -import { SchoolYearDto } from '../dto'; - -export class SchoolYearDtoMapper { - public static mapToDto(schoolYear: SchoolYear): SchoolYearDto { - const schoolYearProps = schoolYear.getProps(); - - const dto = new SchoolYearDto({ - id: schoolYear.id, - name: schoolYearProps.name, - startDate: schoolYearProps.startDate, - endDate: schoolYearProps.endDate, - }); - - return dto; - } - - public static mapToDtos(schoolYears: SchoolYear[]): SchoolYearDto[] { - const dtos = schoolYears.map((schoolYear) => this.mapToDto(schoolYear)); - - return dtos; - } -} diff --git a/apps/server/src/modules/school/domain/mapper/school.dto.mapper.ts b/apps/server/src/modules/school/domain/mapper/school.dto.mapper.ts deleted file mode 100644 index fce7eb90da1..00000000000 --- a/apps/server/src/modules/school/domain/mapper/school.dto.mapper.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { School } from '../do'; -import { SchoolDto, SchoolForExternalInviteDto, YearsDto } from '../dto'; -import { FederalStateDtoMapper } from './federal-state.dto.mapper'; -import { SchoolYearDtoMapper } from './school-year.dto.mapper'; -import { SystemDtoMapper } from './system.dto.mapper'; - -export class SchoolDtoMapper { - public static mapToDto(school: School, years: YearsDto): SchoolDto { - const schoolProps = school.getProps(); - - const federalState = FederalStateDtoMapper.mapToDto(schoolProps.federalState); - const currentYear = schoolProps.currentYear && SchoolYearDtoMapper.mapToDto(schoolProps.currentYear); - const features = schoolProps.features && Array.from(schoolProps.features); - const systems = schoolProps.systems?.map((system) => SystemDtoMapper.mapToDto(system)); - - const dto = new SchoolDto({ - ...schoolProps, - currentYear, - federalState, - features, - systems, - inMaintenance: school.isInMaintenance(), - isExternal: school.isExternal(), - years, - }); - - return dto; - } - - public static mapToListForExternalInviteDtos(schools: School[]): SchoolForExternalInviteDto[] { - const dtos = schools.map((school) => this.mapToExternalInviteDto(school)); - - return dtos; - } - - private static mapToExternalInviteDto(school: School): SchoolForExternalInviteDto { - const schoolProps = school.getProps(); - - const dto = new SchoolForExternalInviteDto({ - id: school.id, - name: schoolProps.name, - purpose: schoolProps.purpose, - }); - - return dto; - } -} diff --git a/apps/server/src/modules/school/domain/mapper/system.dto.mapper.ts b/apps/server/src/modules/school/domain/mapper/system.dto.mapper.ts deleted file mode 100644 index 1614e353dad..00000000000 --- a/apps/server/src/modules/school/domain/mapper/system.dto.mapper.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { System } from '../do'; -import { SystemDto } from '../dto'; - -export class SystemDtoMapper { - public static mapToDto(system: System): SystemDto { - const systemProps = system.getProps(); - - const dto = new SystemDto({ - id: system.id, - type: systemProps.type, - url: systemProps.url, - alias: systemProps.alias, - displayName: systemProps.displayName, - oauthConfig: systemProps.oauthConfig, - oidcConfig: systemProps.oidcConfig, - ldapConfig: systemProps.ldapConfig, - provisioningStrategy: systemProps.provisioningStrategy, - provisioningUrl: systemProps.provisioningUrl, - }); - - return dto; - } -} diff --git a/apps/server/src/modules/school/domain/mapper/years.dto.mapper.ts b/apps/server/src/modules/school/domain/mapper/years.dto.mapper.ts deleted file mode 100644 index eb03f19baf0..00000000000 --- a/apps/server/src/modules/school/domain/mapper/years.dto.mapper.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { School, SchoolYear } from '../do'; -import { SchoolYearDto, YearsDto } from '../dto'; -import { SchoolYearDtoMapper } from './school-year.dto.mapper'; - -export class YearsDtoMapper { - public static mapToDto(school: School, schoolYears: SchoolYear[]): YearsDto { - const schoolYearDtos = SchoolYearDtoMapper.mapToDtos(schoolYears); - - 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: schoolYearDtos, - activeYear, - nextYear, - lastYear, - defaultYear, - }; - - return years; - } - - private static computeActiveYear(school: School, schoolYears: SchoolYear[]): SchoolYearDto | 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 && SchoolYearDtoMapper.mapToDto(activeYear); - - return dto; - } - - private static computeNextYear(schoolYears: SchoolYear[], activeYear?: SchoolYearDto): SchoolYearDto | undefined { - const indexOfActiveYear = schoolYears.findIndex((schoolYear) => schoolYear.id === activeYear?.id); - - const nextYear = schoolYears[indexOfActiveYear + 1]; - - const dto = nextYear && SchoolYearDtoMapper.mapToDto(nextYear); - - return dto; - } - - private static computeLastYear(schoolYears: SchoolYear[], activeYear?: SchoolYearDto): SchoolYearDto | undefined { - const indexOfActiveYear = schoolYears.findIndex((schoolYear) => schoolYear.id === activeYear?.id); - - const lastYear = schoolYears[indexOfActiveYear - 1]; - - const dto = lastYear && SchoolYearDtoMapper.mapToDto(lastYear); - - return dto; - } -} diff --git a/apps/server/src/modules/school/domain/uc/index.ts b/apps/server/src/modules/school/domain/uc/index.ts deleted file mode 100644 index e374a640a0f..00000000000 --- a/apps/server/src/modules/school/domain/uc/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './school.uc'; diff --git a/apps/server/src/modules/school/domain/uc/school.uc.spec.ts b/apps/server/src/modules/school/domain/uc/school.uc.spec.ts deleted file mode 100644 index 8e149420343..00000000000 --- a/apps/server/src/modules/school/domain/uc/school.uc.spec.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { Test, TestingModule } from '@nestjs/testing'; -import { AuthorizationService } from '@src/modules/authorization/'; -import { schoolFactory, schoolYearFactory } from '../testing'; -import { SchoolService, SchoolYearService } from '../service'; -import { SchoolUc } from './school.uc'; -import { SchoolDtoMapper } from '../mapper'; -import { YearsDtoMapper } from '../mapper/years.dto.mapper'; - -describe('SchoolUc', () => { - let service: SchoolUc; - let authorizationService: DeepMocked; - let schoolService: DeepMocked; - let schoolYearService: DeepMocked; - - beforeAll(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - SchoolUc, - { - provide: AuthorizationService, - useValue: createMock(), - }, - { - provide: SchoolService, - useValue: createMock(), - }, - { - provide: SchoolYearService, - useValue: createMock(), - }, - ], - }).compile(); - - service = module.get(SchoolUc); - authorizationService = module.get(AuthorizationService); - schoolService = module.get(SchoolService); - schoolYearService = module.get(SchoolYearService); - }); - describe('getSchool', () => { - describe('when authorization succeeds', () => { - const setup = () => { - const school = schoolFactory.build(); - schoolService.getSchool.mockResolvedValueOnce(school); - - const schoolYears = schoolYearFactory.buildList(3); - schoolYearService.getAllSchoolYears.mockResolvedValueOnce(schoolYears); - - authorizationService.checkPermission.mockImplementationOnce(() => {}); - - const yearsDto = YearsDtoMapper.mapToDto(school, schoolYears); - const dto = SchoolDtoMapper.mapToDto(school, yearsDto); - - return { dto }; - }; - - it('should return dto', async () => { - const { dto } = setup(); - - const result = await service.getSchool('1', '2'); - - expect(result).toEqual(dto); - }); - }); - - describe('when authorization fails', () => { - const setup = () => { - const school = schoolFactory.build(); - schoolService.getSchool.mockResolvedValueOnce(school); - - authorizationService.checkPermission.mockImplementationOnce(() => { - throw new Error('test'); - }); - }; - - it('should throw error', async () => { - setup(); - - await expect(service.getSchool('1', '2')).rejects.toThrowError('test'); - }); - }); - }); - - describe('getSchoolListForExternalInvite', () => { - const setup = () => { - const schools = schoolFactory.buildList(3); - schoolService.getAllSchoolsExceptOwnSchool.mockResolvedValueOnce(schools); - - const dtos = SchoolDtoMapper.mapToListForExternalInviteDtos(schools); - - return { dtos }; - }; - - it('should return dtos', async () => { - const { dtos } = setup(); - - const result = await service.getSchoolListForExternalInvite({}, '1'); - - expect(result).toEqual(dtos); - }); - }); -}); diff --git a/apps/server/src/modules/school/school-api.module.ts b/apps/server/src/modules/school/school-api.module.ts index ad40eb0e0ce..5ca5197ef0f 100644 --- a/apps/server/src/modules/school/school-api.module.ts +++ b/apps/server/src/modules/school/school-api.module.ts @@ -1,8 +1,8 @@ import { Module } from '@nestjs/common'; import { AuthorizationModule } from '@modules/authorization/authorization.module'; -import { SchoolController } from './api/controller'; -import { SchoolUc } from './domain'; import { SchoolModule } from './school.module'; +import { SchoolController } from './api/school.controller'; +import { SchoolUc } from './api/school.uc'; @Module({ imports: [SchoolModule, AuthorizationModule],