86 lines
3.3 KiB
TypeScript
86 lines
3.3 KiB
TypeScript
import { Identifiable, InternshipProgramEntry } from "@/data";
|
|
import { CourseDTO, courseDtoTransformer } from "@/api/dto/course";
|
|
import { OneWayTransformer, Transformer } from "@/serialization";
|
|
import { Edition } from "@/data/edition";
|
|
import moment from "moment-timezone";
|
|
import { Subset } from "@/helpers";
|
|
import { InternshipTypeDTO, internshipTypeDtoTransformer } from "@/api/dto/type";
|
|
|
|
export interface ProgramEntryDTO extends Identifiable {
|
|
description: string;
|
|
descriptionEng: string;
|
|
}
|
|
|
|
export interface EditionDTO extends Identifiable {
|
|
editionStart: string,
|
|
editionFinish: string,
|
|
reportingStart: string,
|
|
course: CourseDTO,
|
|
availableSubjects: ProgramEntryDTO[],
|
|
availableInternshipTypes: InternshipTypeDTO[],
|
|
}
|
|
|
|
export interface EditionTeaserDTO extends Identifiable {
|
|
editionStart: string,
|
|
editionFinish: string,
|
|
courseName: string,
|
|
}
|
|
|
|
export const editionTeaserDtoTransformer: OneWayTransformer<EditionTeaserDTO, Subset<Edition>> = {
|
|
transform(subject: EditionTeaserDTO, context?: undefined): Subset<Edition> {
|
|
return subject && {
|
|
id: subject.id,
|
|
startDate: moment(subject.editionStart),
|
|
endDate: moment(subject.editionFinish),
|
|
course: {
|
|
name: subject.courseName,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export const editionDtoTransformer: Transformer<EditionDTO, Edition> = {
|
|
reverseTransform(subject: Edition, context: undefined): EditionDTO {
|
|
return {
|
|
id: subject.id,
|
|
editionFinish: subject.endDate.toISOString(),
|
|
editionStart: subject.startDate.toISOString(),
|
|
course: courseDtoTransformer.reverseTransform(subject.course),
|
|
reportingStart: subject.reportingStart.toISOString(),
|
|
availableSubjects: subject.program.map(entry => programEntryDtoTransformer.reverseTransform(entry)),
|
|
availableInternshipTypes: subject.types.map(entry => internshipTypeDtoTransformer.reverseTransform(entry))
|
|
};
|
|
},
|
|
transform(subject: EditionDTO, context: undefined): Edition {
|
|
return {
|
|
id: subject.id,
|
|
course: courseDtoTransformer.transform(subject.course),
|
|
startDate: moment(subject.editionStart),
|
|
endDate: moment(subject.editionFinish),
|
|
minimumInternshipHours: 40,
|
|
maximumInternshipHours: 160,
|
|
proposalDeadline: moment(subject.reportingStart),
|
|
reportingStart: moment(subject.reportingStart),
|
|
reportingEnd: moment(subject.reportingStart).add(1, 'month'),
|
|
program: (subject.availableSubjects || []).map(entry => programEntryDtoTransformer.transform(entry)),
|
|
types: (subject.availableInternshipTypes || []).map(entry => internshipTypeDtoTransformer.transform(entry))
|
|
};
|
|
}
|
|
}
|
|
|
|
export const programEntryDtoTransformer: Transformer<ProgramEntryDTO, InternshipProgramEntry> = {
|
|
transform(subject: ProgramEntryDTO, context: never): InternshipProgramEntry {
|
|
return {
|
|
id: subject.id,
|
|
description: subject.description,
|
|
}
|
|
},
|
|
reverseTransform(subject: InternshipProgramEntry, context: never): ProgramEntryDTO {
|
|
return {
|
|
id: subject.id,
|
|
description: subject.description,
|
|
descriptionEng: "",
|
|
}
|
|
},
|
|
}
|