feat(students): add active/paused/left status with hidden filter
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
const STUDENT_STATUSES = ['active', 'paused', 'left'];
|
||||
|
||||
function normalizeStudentStatus(value) {
|
||||
if (value === undefined) return undefined;
|
||||
const status = String(value ?? '').trim();
|
||||
return STUDENT_STATUSES.includes(status) ? status : null;
|
||||
}
|
||||
|
||||
async function ensureStudentsTable(pool) {
|
||||
await pool.query(`ALTER TABLE students ADD COLUMN IF NOT EXISTS status VARCHAR(20) NOT NULL DEFAULT 'active'`);
|
||||
const { rows } = await pool.query(`SELECT 1 FROM pg_constraint WHERE conname = 'students_status_check'`);
|
||||
if (rows.length) return;
|
||||
await pool.query(`ALTER TABLE students ADD CONSTRAINT students_status_check CHECK (status IN ('active','paused','left'))`);
|
||||
}
|
||||
|
||||
module.exports = { STUDENT_STATUSES, normalizeStudentStatus, ensureStudentsTable };
|
||||
Reference in New Issue
Block a user