diff --git a/models/ExamRoom.js b/models/ExamRoom.js index 152ff93b..ec56321e 100644 --- a/models/ExamRoom.js +++ b/models/ExamRoom.js @@ -18,7 +18,7 @@ const ExamRoom = sequelize.define(tableName, { }, roomId: { type: DataTypes.INTEGER, - allowNull: false, + allowNull: true, references: { model: Room, key: 'id' @@ -26,7 +26,7 @@ const ExamRoom = sequelize.define(tableName, { }, lecturerId: { type: DataTypes.INTEGER, - allowNull: false, + allowNull: true, references: { model: Lecturer, key: 'id' diff --git a/routes/examSlot.js b/routes/examSlot.js index 39f05310..7c0d2a26 100644 --- a/routes/examSlot.js +++ b/routes/examSlot.js @@ -9,7 +9,7 @@ import fs from 'fs' const router = express.Router() -router.post('/create', async (req, res) => { +router.post('/', async (req, res) => { const ePId = parseInt(req.body.ePId); const timeSlotId = parseInt(req.body.timeSlotId); const day = req.body.day; @@ -106,28 +106,28 @@ router.get('/', async (req, res) => { let dayCount = 0 let slotCount = 0 - + for (let i = 0; i < course.length; i++) { let daySlot = dayList[dayCount] let slot = slotList[slotCount].id - - if (roomSlot > process.env.NUMBER_OF_ROOM_IN_FLOOR * process.env.NUMBER_OF_ROOM_IN_FLOOR){ + + if (roomSlot > process.env.NUMBER_OF_ROOM_IN_FLOOR * process.env.NUMBER_OF_ROOM_IN_FLOOR) { roomSlot = 0 slotCount++; - - if(slotCount > process.env.NUMBER_OF_SLOT - 1){ + + if (slotCount > process.env.NUMBER_OF_SLOT - 1) { slotCount = 0 dayCount++; } } - - + + const val = course[i]; let roomCourse = Math.ceil(val.numOfStu / process.env.NUMBER_OF_STUDENT_IN_ROOM) fs.appendFileSync("test.txt", roomCourse + "\n"); roomSlot += roomCourse - if(roomSlot <= process.env.NUMBER_OF_STUDENT_IN_ROOM* process.env.NUMBER_OF_ROOM_IN_FLOOR){ + if (roomSlot <= process.env.NUMBER_OF_STUDENT_IN_ROOM * process.env.NUMBER_OF_ROOM_IN_FLOOR) { for (let i = 0; i < roomCourse; i++) { let data = val.id + ".." + daySlot.getDate() + ".." + slot fs.appendFileSync("test.txt", data + "\n"); @@ -136,9 +136,9 @@ router.get('/', async (req, res) => { } else { i-- } - + } - + } res.json('hihi') }) diff --git a/routes/timeSlot.js b/routes/timeSlot.js index 192bdb11..463c5fec 100644 --- a/routes/timeSlot.js +++ b/routes/timeSlot.js @@ -30,18 +30,18 @@ router.get('/getAll', async (req, res) => { //get All timeSlot try { const timeSlots = await TimeSlot.findAll(); - if(!timeSlots){ + if (!timeSlots) { res.json(NotFoundResponse()); - }else{ + } else { res.json(DataResponse(timeSlots)); } } catch (error) { console.log(error); res.json(InternalErrResponse()); - } + } }) -router.get('/getMultipleId', async (req,res) => { +router.get('/getMultipleId', async (req, res) => { //tìm theo id khi người dùng nhập dạng "id" = "1,2,3,4,5,6,7" const id = req.body.id.split(','); console.log(id); @@ -49,7 +49,7 @@ router.get('/getMultipleId', async (req,res) => { const timeSlots = await TimeSlot.findAll({ where: { id: { - [Op.or] : id + [Op.or]: id } } } @@ -127,7 +127,7 @@ router.delete('/deleteAll', async (req, res) => { }) -router.put('/update', async (req, res) => { +router.put('/', async (req, res) => { //update time slot theo id const id = parseInt(req.body.id) const timeSlotData = req.body;