From a7813c0d47d57313c4686aecd0f4912be0a87c65 Mon Sep 17 00:00:00 2001 From: takzx456 Date: Fri, 17 Apr 2026 02:45:19 +0700 Subject: [PATCH 1/3] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=20=E0=B8=81=E0=B8=94=E0=B9=80=E0=B8=AA=E0=B8=A3?= =?UTF-8?q?=E0=B9=87=E0=B8=88=E0=B8=AA=E0=B8=B4=E0=B8=99=20=E0=B9=80?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=B0=20=E0=B9=81=E0=B8=81=E0=B9=89=20?= =?UTF-8?q?=E0=B8=A5=E0=B8=9A=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=84=E0=B8=94=E0=B9=89?= =?UTF-8?q?=20=E0=B9=83=E0=B8=99=E0=B8=AB=E0=B8=99=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=AA?= =?UTF-8?q?=E0=B8=AD=E0=B8=99=E0=B8=8A=E0=B8=94=E0=B9=80=E0=B8=8A=E0=B8=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check_db.js | 18 +++++++++ create_correct_test_data.js | 59 +++++++++++++++++++++++++++++ create_test_data.js | 52 +++++++++++++++++++++++++ makeup.db | 0 server/api/makeup-classes/[id].js | 14 +++++-- server/api/makeup-classes/index.js | 2 +- server/data/data.db | Bin 323584 -> 323584 bytes 7 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 check_db.js create mode 100644 create_correct_test_data.js create mode 100644 create_test_data.js create mode 100644 makeup.db diff --git a/check_db.js b/check_db.js new file mode 100644 index 0000000..34bafb9 --- /dev/null +++ b/check_db.js @@ -0,0 +1,18 @@ +import Database from 'better-sqlite3' +const db = new Database('./server/data/data.db') + +console.log('Tables and Row Counts:') +const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all() + +tables.forEach(t => { + const count = db.prepare(`SELECT COUNT(*) as cnt FROM ${t.name}`).get() + console.log(` - ${t.name}: ${count.cnt} rows`) +}) + +console.log('\nMakeup Classes Sample:') +const makeup = db.prepare('SELECT id_makeup, status, teacher_id, section_id FROM makeup_classes LIMIT 5').all() +console.log(JSON.stringify(makeup, null, 2)) + +console.log('\nTeachers Sample:') +const teachers = db.prepare('SELECT id_teacher, prefix, first_name, last_name FROM teachers LIMIT 3').all() +console.log(JSON.stringify(teachers, null, 2)) diff --git a/create_correct_test_data.js b/create_correct_test_data.js new file mode 100644 index 0000000..749f905 --- /dev/null +++ b/create_correct_test_data.js @@ -0,0 +1,59 @@ +import Database from 'better-sqlite3' +const db = new Database('./server/data/data.db') + +// Delete existing test data +console.log('Deleting existing test makeup_classes...') +db.prepare('DELETE FROM makeup_classes WHERE id_makeup >= 10').run() + +// Insert correct test makeup class data +const today = new Date().toISOString().split('T')[0] +const tomorrow = new Date(Date.now() + 86400000).toISOString().split('T')[0] + +console.log('Creating correct test makeup_classes data...') + +const teacher = db.prepare('SELECT id_teacher FROM teachers LIMIT 1').get() +const section = db.prepare('SELECT id_section FROM sections LIMIT 1').get() +const subject = db.prepare('SELECT id_subject FROM Subjects LIMIT 1').get() +const room = db.prepare('SELECT id_room FROM rooms LIMIT 1').get() + +if (!teacher || !section || !subject) { + console.error('Missing required data') + process.exit(1) +} + +const insertStmt = db.prepare(` + INSERT INTO makeup_classes ( + original_date, original_time_slot, makeup_date, + makeup_time_start, makeup_time_end, teacher_id, + section_id, subject_id, room_id, status, notes + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +`) + +// Create test makeup classes with different times +const timeSlots = [ + ['08:00', '09:00'], + ['10:00', '11:00'], + ['13:00', '14:00'] +] + +timeSlots.forEach((slot, i) => { + const result = insertStmt.run( + today, + `${slot[0]}-${slot[1]}`, + tomorrow, + slot[0], + slot[1], + teacher.id_teacher, + section.id_section, + subject.id_subject, + room?.id_room || null, + 'confirmed', + `Test makeup class ${i + 1}` + ) + console.log(` Created makeup_class ID: ${result.lastInsertRowid}, time: ${slot[0]}-${slot[1]}`) +}) + +// Verify +const all = db.prepare('SELECT id_makeup, status, makeup_time_start, makeup_time_end FROM makeup_classes').all() +console.log('\nAll makeup_classes:') +console.log(JSON.stringify(all, null, 2)) diff --git a/create_test_data.js b/create_test_data.js new file mode 100644 index 0000000..ddccaf2 --- /dev/null +++ b/create_test_data.js @@ -0,0 +1,52 @@ +import Database from 'better-sqlite3' +const db = new Database('./server/data/data.db') + +// Insert test makeup class data +const today = new Date().toISOString().split('T')[0] +const tomorrow = new Date(Date.now() + 86400000).toISOString().split('T')[0] + +console.log('Creating test makeup_classes data...') + +const teacher = db.prepare('SELECT id_teacher FROM teachers LIMIT 1').get() +const section = db.prepare('SELECT id_section FROM sections LIMIT 1').get() +const subject = db.prepare('SELECT id_subject FROM Subjects LIMIT 1').get() +const room = db.prepare('SELECT id_room FROM rooms LIMIT 1').get() + +if (!teacher || !section || !subject) { + console.error('Missing required data (teacher, section, or subject)') + process.exit(1) +} + +const insertStmt = db.prepare(` + INSERT INTO makeup_classes ( + original_date, original_time_slot, makeup_date, + makeup_time_start, makeup_time_end, teacher_id, + section_id, subject_id, room_id, status, notes + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +`) + +// Create 3 test makeup classes +for (let i = 1; i <= 3; i++) { + const result = insertStmt.run( + today, + '08:00-09:00', + tomorrow, + '08:00', + `0${8+i}:00`, + teacher.id_teacher, + section.id_section, + subject.id_subject, + room?.id_room || null, + 'confirmed', + `Test makeup class ${i}` + ) + console.log(` Created makeup_class ID: ${result.lastInsertRowid}`) +} + +// Verify +const count = db.prepare('SELECT COUNT(*) as cnt FROM makeup_classes').get() +console.log(`\nTotal makeup_classes: ${count.cnt}`) + +const sample = db.prepare('SELECT id_makeup, status FROM makeup_classes').all() +console.log('Sample:') +console.log(JSON.stringify(sample, null, 2)) diff --git a/makeup.db b/makeup.db new file mode 100644 index 0000000..e69de29 diff --git a/server/api/makeup-classes/[id].js b/server/api/makeup-classes/[id].js index 8db24d3..7a72c0e 100644 --- a/server/api/makeup-classes/[id].js +++ b/server/api/makeup-classes/[id].js @@ -70,20 +70,26 @@ export default defineEventHandler(async (event) => { } } - // 2. Check Room Availability (if room, date, or time is changing) + // 2. Check Room Availability (only if room, date, or time is actually being changed) const newRoomId = body.room_id !== undefined ? body.room_id : oldData.room_id const newStart = body.makeup_time_start !== undefined ? body.makeup_time_start : oldData.makeup_time_start const newEnd = body.makeup_time_end !== undefined ? body.makeup_time_end : oldData.makeup_time_end - if (newRoomId && newRoomId !== 'null' && newDate && newStart && newEnd) { + // Only check room availability if there's an actual change to room, date, or time AND room is assigned + const hasRoomChange = body.room_id !== undefined && body.room_id !== oldData.room_id + const hasDateChange = body.makeup_date !== undefined && body.makeup_date !== oldData.makeup_date + const hasTimeChange = (body.makeup_time_start !== undefined && body.makeup_time_start !== oldData.makeup_time_start) || + (body.makeup_time_end !== undefined && body.makeup_time_end !== oldData.makeup_time_end) + + if ((hasRoomChange || hasDateChange || hasTimeChange) && newRoomId && newRoomId !== 'null' && newStart && newEnd) { // We need term for room check let term = body.term if (!term) { - const teacherSchedule = db.prepare('SELECT term FROM schedules WHERE id_teacher = ? ORDER BY created_at DESC LIMIT 1').get(oldData.teacher_id) + const teacherSchedule = db.prepare('SELECT term FROM schedules WHERE id_teacher = ? ORDER BY id_schedule DESC LIMIT 1').get(oldData.teacher_id) term = teacherSchedule?.term } - if (term) { + if (term && newDate) { const availability = checkRoomAvailability({ room_id: newRoomId, date: newDate, diff --git a/server/api/makeup-classes/index.js b/server/api/makeup-classes/index.js index 52ca25d..8b29a38 100644 --- a/server/api/makeup-classes/index.js +++ b/server/api/makeup-classes/index.js @@ -82,7 +82,7 @@ export default defineEventHandler(async (event) => { // We need term for room check. If not provided, try to find teacher's current term. let term = body.term if (!term) { - const teacherSchedule = db.prepare('SELECT term FROM schedules WHERE id_teacher = ? ORDER BY created_at DESC LIMIT 1').get(body.teacher_id) + const teacherSchedule = db.prepare('SELECT term FROM schedules WHERE id_teacher = ? ORDER BY id_schedule DESC LIMIT 1').get(body.teacher_id) term = teacherSchedule?.term } diff --git a/server/data/data.db b/server/data/data.db index 9d60905b1490646f87e7f859420c77cb409bac9b..80cc069695a1919322c3800f7451c05eb6d47851 100644 GIT binary patch delta 1551 zcma)6&1=(O9Db8nT;|rdTi15&)F#MuGOPJ$Gn(#Xk$KofD0&#qmM)6ebz_}^2W`7a zbrVDh(mBh<5I;afTz5$E;>C+z1dkqk=^x+_riUHGH|f%^%}pB8zE6I6p6B<~46?cVz|#nQw9uii#tF7P*1?@{)&^CP{qkvHN12v zU-(7Q`3HX}TKyavYV@U>YVyTnU&nA_-Fqh%hzQLD7}5ziM#~~?6=~0q_7Z9DX0CWJ zoqMZJ;fg!&3H9nW}nsf%ZI}xD&tJkE~u@wkaq-~5098W`#6j8BYDCX{JqETW{Q zneo^)<@zKOPsCCwCThpL?FKJFcyZIsuHbL8l~USRc7u&-?d*zABrji`8dt{5h+Wq> z>eyQ$U@V=W|D_lLv1D9HB&q^w-*2MJ4%G-<7tq$!6Tx5LH_ z=zRn>P??^uxQ8EMsIk@d#-pS0Xbi%x1X3eGpphU@BiO{V^aDFUl__es8#CiD=Es>s OL=KTTM7==!Y<~eIPNuQ| delta 1422 zcma)6O-~a+7@lP)l$@Q5CTnGA`y##dhq})2?ji% z*+W(EgP5p^Aq47Sz3Ii17ZXpO2DocPVxnH0-Im>Lslv`4X5M{2p67Yr*;yKxrGa}P zuJ``QUaogz_sxCd0)b@*~8gr8#_Ss)zn<%DhJ+USj zAU7CJs=cDx8>+3cq(WPMwYyfxFZ_UE8+p=CNCkOjiZJp5Vw_(Z@rx{85zP4ZfeJBV z7TLjgg&1;7iAJpNx;};p0PYINIZEgUj)cBXu)0S2ar_`~m9B`@aQ97AHqeeac0|nC z78e4yMKR3A3pfFgWhQlXxz+5`GcICHl=|yQ%LV>`4zlHeOVY@g2kgUg)YcWu6FpbiBo-Y*4F_~@+}f%#|aTyVxlTrw_~q+c)S@uB2I zW^`=oS~_JyGI&?NG6^RFqDKq{Ij)9lWpZ0V=8hQiOCl^k9|Cv%dV!fL75+VkAbDsF zLo}lhe+(=dHU3wk+4!&QH#8bCwcSSB=rhyx1Cy*w{_+zWEr3jhxc<<1sVtt9#}g}l h5AC6Eto|1A7yGJrRQImq>*pyqPiy8Wd_ik{e*v!^gOvaP From 98e2eb9f28e93b631abcfd3509f56cbb39cdbd84 Mon Sep 17 00:00:00 2001 From: takzx456 Date: Fri, 17 Apr 2026 07:59:33 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B8=A1?= =?UTF-8?q?=E0=B8=9B=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B9=80=E0=B8=A5=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B9=83=E0=B8=99=E0=B8=AB=E0=B8=99?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=95=E0=B8=B2=E0=B8=A3=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=AB=E0=B9=89=E0=B8=AD=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/pages/rooms.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/pages/rooms.vue b/app/pages/rooms.vue index 9359090..3a5c2f6 100644 --- a/app/pages/rooms.vue +++ b/app/pages/rooms.vue @@ -107,8 +107,8 @@ -
- +
+
{ From 9dc0cf62a13f5760551a1425335b93c75c59845f Mon Sep 17 00:00:00 2001 From: Nav0za Date: Fri, 17 Apr 2026 09:26:52 +0700 Subject: [PATCH 3/3] delete edit btn makeup --- app/pages/makeup-classes.vue | 10 +--------- server/data/data.db | Bin 323584 -> 323584 bytes 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/app/pages/makeup-classes.vue b/app/pages/makeup-classes.vue index 7183008..30286bc 100644 --- a/app/pages/makeup-classes.vue +++ b/app/pages/makeup-classes.vue @@ -180,15 +180,7 @@
- + YX;GTgJUhboASb#9e8W`!#1W7mz! z@I?uuP&ye1zKC=Zg!-fp!+$^@L`34A1VIo)s4seNnzYL{rR9Xsb2<0({hpK4q8TWf zfrm1?{%B;9U4N1Nb!tcs@Z3puZgwe`pPwzvHS2*h>35# zLP?5<%<=_IJ1)!YT|HVG)2BA#`j2x*!sAFmIIbk(2xru@X+^i-VMh-UL%2&rE83`^DdlWK&^DB+e0#uM0%%;1RRe=Jv@e?u#b*wz~u?&DY%M67q~H)Re0O7H^N`1$&<=@UK*_kOi*g>T2}+?T z;NxMB6w>W>WuneT35U+mf&m@~y>qTwoGEP0Tt(DR?;Ia7#E1+7-@$G8k_Oq1CvaNe zVx5gpWOpjL(-1*~olk+3VUog58vKXEWfugyC9qopyCtw&0(T_7!>@415Vk%*3CPy2 ZN!FX*9{}{47X-^DTQ))2R~a-}J=9ggKeD8Iu!pQu9(0i{ewuQu9iRr8ej2FGyhH zmFJA(jN7az;KRw^EFmh$(Bx`ttSSxEUpbj?meS;y`D%=5gltP$2vUuerBKYh+uX3pt-|Cl)^pSE^aL~)IQl>rFB%!D|Q zai)S8^Mf7BAMDuDEFpp0V@O7sh8Uq61r#!z3^WStR}P?I8=KOl1SjvDJzv}u7z}6@ z1BJ|hsx2pL+i*>uFjr&ptvRw9M(F-Gu`)1$xfL2DAfe5j^I8~LPw~&SoX z7GshUO3u$M$Vn|pO$kXYE>Xx$%uX#WP)N>6EG||^5awr??y#Ow$sXhlum)x>A(7<# zytK@s+|(4bK){|Z5=0?}C^(sdW5)<&7TB1?yyVoJ91LTOtqhIOOg6SMHb@YIn&V>% zjyFRypgByOOnh(;plQM$P3By{&}0x`VBr7A|A_zcX2AzX`Q`YS6(P|9iUk8