feat: add monthly card periods and apparatus lesson feedback
This commit is contained in:
20
packages/shared/src/lesson-feedback.ts
Normal file
20
packages/shared/src/lesson-feedback.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export const LESSON_APPARATUS = ['M', 'R', 'TT', 'Chair', 'ARC', 'SC', 'LB'] as const
|
||||
export type LessonApparatus = typeof LESSON_APPARATUS[number]
|
||||
export type ApparatusNotes = Partial<Record<LessonApparatus, string>>
|
||||
export const LESSON_NOTE_MAX_LENGTH = 1000
|
||||
|
||||
export function isApparatusNotes(value: unknown): value is ApparatusNotes {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return false
|
||||
return Object.entries(value).every(([key, content]) =>
|
||||
LESSON_APPARATUS.includes(key as LessonApparatus) &&
|
||||
typeof content === 'string' && content.length <= LESSON_NOTE_MAX_LENGTH,
|
||||
)
|
||||
}
|
||||
|
||||
// Keep a stable apparatus order and omit fields the coach left blank.
|
||||
export function filledApparatusNotes(notes?: ApparatusNotes | null) {
|
||||
return LESSON_APPARATUS.flatMap(apparatus => {
|
||||
const content = notes?.[apparatus]?.trim()
|
||||
return content ? [{ apparatus, content }] : []
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user