-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_correct_test_data.js
More file actions
59 lines (50 loc) · 1.84 KB
/
create_correct_test_data.js
File metadata and controls
59 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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))