From 0d2d340c375e777bf4beea94983f30cca0aedd67 Mon Sep 17 00:00:00 2001 From: Dongjae Lee <58449555+duncan020313@users.noreply.github.com> Date: Wed, 17 Jan 2024 23:23:51 +0900 Subject: [PATCH] feat: add serializers for planner --- .../serializer/planner.serializer.ts | 25 ++++++++ .../interfaces/serializer/track.serializer.ts | 61 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/common/interfaces/serializer/planner.serializer.ts create mode 100644 src/common/interfaces/serializer/track.serializer.ts diff --git a/src/common/interfaces/serializer/planner.serializer.ts b/src/common/interfaces/serializer/planner.serializer.ts new file mode 100644 index 00000000..1beb5bea --- /dev/null +++ b/src/common/interfaces/serializer/planner.serializer.ts @@ -0,0 +1,25 @@ +import { PlannerDetails } from 'src/common/schemaTypes/types'; +import { PlannerResponseDto } from '../dto/planner/planner.response.dto'; +import { + toJsonAdditionalTrack, + toJsonGeneralTrack, + toJsonMajorTrack, +} from './track.serializer'; + +export const toJsonPlanner = (planner: PlannerDetails): PlannerResponseDto => { + return { + id: planner.id, + start_year: planner.start_year, + end_year: planner.end_year, + general_track: toJsonGeneralTrack(planner.graduation_generaltrack), + major_track: toJsonMajorTrack(planner.graduation_majortrack), + additional_tracks: planner.planner_planner_additional_tracks.map( + (additional_track) => + toJsonAdditionalTrack(additional_track.graduation_additionaltrack), + ), + taken_items: toJsonTakenItem(planner.taken_items), + future_items: toJsonFutureItem(planner.future_items), + arbitrary_items: toJsonArbitraryItem(planner.arbitrary_items), + arrange_order: planner.arrange_order, + }; +}; diff --git a/src/common/interfaces/serializer/track.serializer.ts b/src/common/interfaces/serializer/track.serializer.ts new file mode 100644 index 00000000..d5278dd9 --- /dev/null +++ b/src/common/interfaces/serializer/track.serializer.ts @@ -0,0 +1,61 @@ +import { + AdditionalTrackDetails, + GeneralTrackBasic, + MajorTrackDetails, +} from 'src/common/schemaTypes/types'; +import { AdditionalTrackResponseDto } from '../dto/track/additional.response.dto'; +import { GeneralTrackResponseDto } from '../dto/track/general.response.dto'; +import { MajorTrackResponseDto } from '../dto/track/major.response.dto'; +import { toJsonDepartment } from './department.serializer'; + +export const toJsonGeneralTrack = ( + generalTrack: GeneralTrackBasic, +): GeneralTrackResponseDto => { + return { + id: generalTrack.id, + start_year: generalTrack.start_year, + end_year: generalTrack.end_year, + is_foreign: generalTrack.is_foreign, + total_credit: generalTrack.total_credit, + total_au: generalTrack.total_au, + basic_required: generalTrack.basic_required, + basic_elective: generalTrack.basic_elective, + thesis_study: generalTrack.thesis_study, + thesis_study_doublemajor: generalTrack.thesis_study_doublemajor, + general_required_credit: generalTrack.general_required_credit, + general_required_au: generalTrack.general_required_au, + humanities: generalTrack.humanities, + humanities_doublemajor: generalTrack.humanities_doublemajor, + }; +}; + +export const toJsonMajorTrack = ( + majorTrack: MajorTrackDetails, +): MajorTrackResponseDto => { + return { + id: majorTrack.id, + start_year: majorTrack.start_year, + end_year: majorTrack.end_year, + department: toJsonDepartment(majorTrack.subject_department), + basic_elective_doublemajor: majorTrack.basic_elective_doublemajor, + major_required: majorTrack.major_required, + major_elective: majorTrack.major_elective, + }; +}; + +export const toJsonAdditionalTrack = ( + additionalTrack: AdditionalTrackDetails, +): AdditionalTrackResponseDto => { + return { + id: additionalTrack.id, + start_year: additionalTrack.start_year, + end_year: additionalTrack.end_year, + type: additionalTrack.type, + department: + additionalTrack.subject_department === null + ? null + : toJsonDepartment(additionalTrack.subject_department), + major_required: additionalTrack.major_required, + major_elective: additionalTrack.major_elective, + }; +};