@@ -182,15 +182,51 @@ const moodJournalValidator = (values: { howAreYou: string; stressSignals: stress
182182 }
183183}
184184
185+ const weightJournalValidator = ( values : { date : Date ; time : Date ; weight : number ; height : number ; unit : string ; notes : string } ) => {
186+ const { date, time, weight, height, unit, notes} = values ;
187+ //check if date is valid
188+ if ( ! date || typeof date !== 'string' ) {
189+ Logger . error ( `Invalid date: ${ date } ` ) ;
190+ throw new Error ( `Invalid date: ${ date } ` ) ;
191+ }
192+ //check if time is valid
193+ if ( ! time || typeof time !== 'string' ) {
194+ Logger . error ( `Invalid time: ${ time } ` ) ;
195+ throw new Error ( `Invalid time: ${ time } ` ) ;
196+ }
197+ //check if weight is valid
198+ if ( ! weight || typeof weight !== 'number' ) {
199+ Logger . error ( `Invalid weight: ${ weight } ` ) ;
200+ throw new Error ( `Invalid weight: ${ weight } ` ) ;
201+ }
202+ //check if height is valid
203+ if ( ! height || typeof height !== 'number' ) {
204+ Logger . error ( `Invalid height: ${ height } ` ) ;
205+ throw new Error ( `Invalid height: ${ height } ` ) ;
206+ }
207+ //check if unit is valid
208+ if ( ! unit || / \d / . test ( unit ) || typeof unit !== 'string' ) {
209+ Logger . error ( `Invalid unit: ${ unit } ` ) ;
210+ throw new Error ( `Invalid unit: ${ unit } ` ) ;
211+ }
212+ //check if notes is valid
213+ if ( notes !== undefined && ( / \d / . test ( notes ) || typeof notes !== 'string' ) ) {
214+ Logger . error ( `Invalid notes: ${ notes } ` ) ;
215+ throw new Error ( `Invalid notes: ${ notes } ` ) ;
216+ }
217+ }
218+
185219
186220
187221export {
188222 userValidator ,
189223 speedDialValidator ,
190224 appointmentValidator ,
191225 notificationPreferenceValidator ,
192- medicationValidator ,
193- moodJournalValidator
226+ medicationValidator ,
227+ moodJournalValidator ,
228+ weightJournalValidator
229+
194230
195231
196232}
0 commit comments