import { Transform, Type } from 'class-transformer' import { parseISO } from 'date-fns' import { isNil } from 'lodash' import { MealGroup } from './meal_group.model' import { MenuRestriction } from './menu_restriction.model' export class Menu { id: string goal_id: string @Transform(value => parseISO(value), { toClassOnly: true }) created_at: Date @Transform(value => parseISO(value), { toClassOnly: true }) updated_at: Date created_by?: string updated_by?: string title: string active: boolean is_autogenerated: boolean reference_food_plan_id: string @Type(() => MealGroup) meal_groups?: Array menu_restrictions?: Array constructor(args: Partial) { Object.assign(this, args) } changeMealGroupTimes(args: { [mealTypeTitle: string]: string }, deleteType = false): void { this.meal_groups = this.meal_groups.map(mealGroup => { const newTime = args[mealGroup.type.title_pt] if (!isNil(newTime)) mealGroup.time = newTime if (deleteType) delete mealGroup.type return mealGroup }) } }