diff --git a/db/init.sql b/db/init.sql index 8e314ad..b0922e9 100644 --- a/db/init.sql +++ b/db/init.sql @@ -182,6 +182,8 @@ CREATE TABLE IF NOT EXISTS users ( created_at TIMESTAMPTZ DEFAULT now() ); +ALTER TABLE groups ADD COLUMN IF NOT EXISTS tutor_id INT REFERENCES users(id) ON DELETE SET NULL; + CREATE TABLE IF NOT EXISTS user_branches ( user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE, branch_id INT NOT NULL REFERENCES branches(id) ON DELETE CASCADE, diff --git a/db/migration.sql b/db/migration.sql index 289f707..5a31d58 100644 --- a/db/migration.sql +++ b/db/migration.sql @@ -154,6 +154,8 @@ CREATE TABLE IF NOT EXISTS user_branches ( PRIMARY KEY (user_id, branch_id) ); +ALTER TABLE groups ADD COLUMN IF NOT EXISTS tutor_id INT REFERENCES users(id) ON DELETE SET NULL; + CREATE TABLE IF NOT EXISTS sessions ( id SERIAL PRIMARY KEY, user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE, diff --git a/public/groups.html b/public/groups.html index 0871e6e..d97f77d 100644 --- a/public/groups.html +++ b/public/groups.html @@ -14,6 +14,7 @@
+
diff --git a/public/js/groups.js b/public/js/groups.js index cc96be1..11e4c24 100644 --- a/public/js/groups.js +++ b/public/js/groups.js @@ -1,5 +1,6 @@ const DAYS = ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб']; let branchesCache = []; +let tutorsCache = []; let allGroups = []; let currentCover = null; @@ -8,6 +9,16 @@ async function loadBranchesCache() { if (res.ok) branchesCache = await res.json(); } +async function loadTutorsCache() { + const res = await fetch(`${API}/api/users/tutors`, { headers: hdr() }); + if (res.ok) tutorsCache = await res.json(); +} + +function tutorSelectHTML(selectedId) { + const opts = tutorsCache.map(t => ``).join(''); + return `
`; +} + function branchSelectHTML(selectedId) { const opts = branchesCache.map(b => ``).join(''); return `
`; @@ -15,6 +26,7 @@ function branchSelectHTML(selectedId) { async function loadGroups() { await loadBranchesCache(); + await loadTutorsCache(); const res = await fetch(`${API}/api/groups`, { headers: hdr() }); const groups = await res.json(); allGroups = groups; @@ -33,6 +45,7 @@ async function loadGroups() {
${branchSelectHTML(g.branch_id)} + ${tutorSelectHTML(g.tutor_id)}