From 12d24466a8240ddfe9458553d269506fe1b4d690 Mon Sep 17 00:00:00 2001 From: elangptra Date: Thu, 28 Nov 2024 12:57:30 +0700 Subject: [PATCH] feat: register student for admin and teacher (nisn and name only) --- controllers/auth/auth.js | 23 ++++++---------------- controllers/contentControllers/exercise.js | 1 + controllers/contentControllers/topic.js | 1 + routes/auth/auth.js | 4 ++-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/controllers/auth/auth.js b/controllers/auth/auth.js index 9709901..35d2201 100644 --- a/controllers/auth/auth.js +++ b/controllers/auth/auth.js @@ -607,32 +607,19 @@ export const registerTeacherForAdmin = async (req, res) => { } }; -export const registerStudentForAdmin = async (req, res) => { - const { NAME_USERS, EMAIL, NISN, PASSWORD, CONFIRM_PASSWORD } = req.body; +export const registerStudentForAdminAndTeacher = async (req, res) => { + const { NAME_USERS, NISN } = req.body; if (!NAME_USERS) { return response(400, null, "Name is required!", res); } - if (!EMAIL) { - return response(400, null, "Email is required!", res); - } - if (!NISN) { return response(400, null, "NISN is required for students!", res); } - if (!PASSWORD) { - return response(400, null, "Password is required!", res); - } - - if (!CONFIRM_PASSWORD) { - return response(400, null, "Confirm Password is required!", res); - } - - if (PASSWORD !== CONFIRM_PASSWORD) { - return response(400, null, "Passwords do not match!", res); - } + const EMAIL = `${NISN}@gmail.com`; + const PASSWORD = "12345678"; const transaction = await models.db.transaction(); @@ -668,11 +655,13 @@ export const registerStudentForAdmin = async (req, res) => { NISN: NISN, ROLE: newUser.ROLE, IS_VALIDATED: newUser.IS_VALIDATED, + PASSWORD: "12345678", }; response(200, studentResponse, "Student registration successful", res); } catch (error) { console.log(error); + await transaction.rollback(); if (error.name === "SequelizeUniqueConstraintError") { diff --git a/controllers/contentControllers/exercise.js b/controllers/contentControllers/exercise.js index 054edce..2947b4c 100644 --- a/controllers/contentControllers/exercise.js +++ b/controllers/contentControllers/exercise.js @@ -331,6 +331,7 @@ export const getExerciseByLevelId = async (req, res) => { { model: models.MatchingPairs, as: "matchingPairs" }, { model: models.TrueFalse, as: "trueFalse" }, ], + order: [["TIME_ADMIN_EXC", "ASC"]], }); if (!exercises || exercises.length === 0) { diff --git a/controllers/contentControllers/topic.js b/controllers/contentControllers/topic.js index 97c61d0..370b08a 100644 --- a/controllers/contentControllers/topic.js +++ b/controllers/contentControllers/topic.js @@ -45,6 +45,7 @@ export const getTopicBySectionId = async (req, res) => { const topics = await models.Topic.findAll({ where: { ID_SECTION: sectionId, IS_DELETED: 0 }, attributes: ["ID_TOPIC", "NAME_TOPIC", "DESCRIPTION_TOPIC"], + order: [["TIME_TOPIC", "ASC"]], }); if (!topics || topics.length === 0) { diff --git a/routes/auth/auth.js b/routes/auth/auth.js index 6ffea2f..f08cfd1 100644 --- a/routes/auth/auth.js +++ b/routes/auth/auth.js @@ -1,5 +1,5 @@ import express from "express"; -import { registerTeacher, registerStudent, registerStudentForAdmin, registerTeacherForAdmin, registerAdmin, validateEmail, loginUser, refreshToken, logoutUser, forgotPassword, resetPassword } from "../../controllers/auth/auth.js"; +import { registerTeacher, registerStudent, registerStudentForAdminAndTeacher, registerTeacherForAdmin, registerAdmin, validateEmail, loginUser, refreshToken, logoutUser, forgotPassword, resetPassword } from "../../controllers/auth/auth.js"; import { verifyLoginUser, adminOnly } from "../../middlewares/User/authUser.js"; const router = express.Router(); @@ -10,7 +10,7 @@ router.post("/register/student", registerStudent); router.post("/admin/register/teacher", verifyLoginUser, adminOnly, registerTeacherForAdmin); -router.post("/admin/register/student", verifyLoginUser, adminOnly, registerStudentForAdmin); +router.post("/admin/register/student", verifyLoginUser, adminOnly, registerStudentForAdminAndTeacher); router.post("/register/admin", verifyLoginUser, adminOnly, registerAdmin);