Skip to content

Commit

Permalink
feat: add serializers for planner
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan020313 committed Jan 20, 2024
1 parent 4acb1a3 commit 0d2d340
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/common/interfaces/serializer/planner.serializer.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};
61 changes: 61 additions & 0 deletions src/common/interfaces/serializer/track.serializer.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};

0 comments on commit 0d2d340

Please sign in to comment.