feat: register student for admin and teacher (nisn and name only)

This commit is contained in:
elangptra 2024-11-28 12:57:30 +07:00
parent c290873bd5
commit 12d24466a8
4 changed files with 10 additions and 19 deletions

View File

@ -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") {

View File

@ -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) {

View File

@ -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) {

View File

@ -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);