import { Injectable } from "@nestjs/common"; import { EducationDto, EducationType } from "@/education/education.types"; import { education } from "@/education/education"; @Injectable() export class EducationService { private readonly education: readonly EducationDto[]; constructor() { this.education = EducationDto.asDto(education).sort((educationA, educationB) => educationA.startDate < educationB.startDate ? 1 : -1 ); } getMany(filter?: Partial>) { const filtersValues = Object.entries(filter ?? {}).map(([key, filterValue]) => [ key, new RegExp(filterValue, "i"), ]) as Array<[keyof Omit, RegExp]>; if (!filter || filtersValues.length === 0) { return this.education; } return this.education.filter((education) => filtersValues.some(([key, filterValue]) => filterValue.test(education[key])) ); } }