* feat(cohorts): rename Programs to Cohorts with data migration - Add cohort database tables and Drizzle migration alongside legacy program tables - Introduce migrate-programs-to-cohorts script to copy existing program data safely - Rename API routes (/cohort), services, queries, validation, and error codes - Rename dashboard feature module, routes (/cohorts), navigation, and translations - Update docs, emails, and internal compliance cron endpoints for cohort terminology - Keep legacy program tables in place for rollback until explicitly removed Co-authored-by: Rotimi Best <[email protected]> * fix(db): restore migrate:answer-data script alongside cohort migration Co-authored-by: Rotimi Best <[email protected]> * fix(db): cast program enums when migrating data to cohort tables Co-authored-by: Rotimi Best <[email protected]> * fix(db): truncate cohort tables before program-to-cohort copy Co-authored-by: Rotimi Best <[email protected]> * fix(db): report accurate row counts in programs-to-cohorts migration Co-authored-by: Rotimi Best <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Rotimi Best <[email protected]>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
function parseInviteIds(metadata: unknown, keys: string[]): string[] {
|
|
let obj: Record<string, unknown> | null = null;
|
|
if (metadata == null) {
|
|
return [];
|
|
}
|
|
if (typeof metadata === 'string') {
|
|
try {
|
|
const parsed = JSON.parse(metadata) as unknown;
|
|
obj = typeof parsed === 'object' && parsed !== null ? (parsed as Record<string, unknown>) : null;
|
|
} catch {
|
|
return [];
|
|
}
|
|
} else if (typeof metadata === 'object') {
|
|
obj = metadata as Record<string, unknown>;
|
|
}
|
|
if (!obj) {
|
|
return [];
|
|
}
|
|
|
|
const raw = keys.map((key) => obj[key]).find((value) => value !== undefined);
|
|
if (!Array.isArray(raw)) {
|
|
return [];
|
|
}
|
|
|
|
return raw.filter((id): id is string => typeof id === 'string' && id.length > 0);
|
|
}
|
|
|
|
/** Normalize JSONB organization-invite metadata for course ids (matches importAudienceMembers storage). */
|
|
export function parseCourseIdsFromInviteMetadata(metadata: unknown): string[] {
|
|
return parseInviteIds(metadata, ['courseIds', 'course_ids']);
|
|
}
|
|
|
|
/** Normalize JSONB organization-invite metadata for cohort ids (legacy `programIds` supported). */
|
|
export function parseCohortIdsFromInviteMetadata(metadata: unknown): string[] {
|
|
return parseInviteIds(metadata, ['cohortIds', 'cohort_ids', 'programIds', 'program_ids']);
|
|
}
|