feat: register student for admin and teacher (nisn and name only)
This commit is contained in:
parent
c290873bd5
commit
12d24466a8
|
|
@ -607,32 +607,19 @@ export const registerTeacherForAdmin = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerStudentForAdmin = async (req, res) => {
|
export const registerStudentForAdminAndTeacher = async (req, res) => {
|
||||||
const { NAME_USERS, EMAIL, NISN, PASSWORD, CONFIRM_PASSWORD } = req.body;
|
const { NAME_USERS, NISN } = req.body;
|
||||||
|
|
||||||
if (!NAME_USERS) {
|
if (!NAME_USERS) {
|
||||||
return response(400, null, "Name is required!", res);
|
return response(400, null, "Name is required!", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EMAIL) {
|
|
||||||
return response(400, null, "Email is required!", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!NISN) {
|
if (!NISN) {
|
||||||
return response(400, null, "NISN is required for students!", res);
|
return response(400, null, "NISN is required for students!", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PASSWORD) {
|
const EMAIL = `${NISN}@gmail.com`;
|
||||||
return response(400, null, "Password is required!", res);
|
const PASSWORD = "12345678";
|
||||||
}
|
|
||||||
|
|
||||||
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 transaction = await models.db.transaction();
|
const transaction = await models.db.transaction();
|
||||||
|
|
||||||
|
|
@ -668,11 +655,13 @@ export const registerStudentForAdmin = async (req, res) => {
|
||||||
NISN: NISN,
|
NISN: NISN,
|
||||||
ROLE: newUser.ROLE,
|
ROLE: newUser.ROLE,
|
||||||
IS_VALIDATED: newUser.IS_VALIDATED,
|
IS_VALIDATED: newUser.IS_VALIDATED,
|
||||||
|
PASSWORD: "12345678",
|
||||||
};
|
};
|
||||||
|
|
||||||
response(200, studentResponse, "Student registration successful", res);
|
response(200, studentResponse, "Student registration successful", res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
||||||
await transaction.rollback();
|
await transaction.rollback();
|
||||||
|
|
||||||
if (error.name === "SequelizeUniqueConstraintError") {
|
if (error.name === "SequelizeUniqueConstraintError") {
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,7 @@ export const getExerciseByLevelId = async (req, res) => {
|
||||||
{ model: models.MatchingPairs, as: "matchingPairs" },
|
{ model: models.MatchingPairs, as: "matchingPairs" },
|
||||||
{ model: models.TrueFalse, as: "trueFalse" },
|
{ model: models.TrueFalse, as: "trueFalse" },
|
||||||
],
|
],
|
||||||
|
order: [["TIME_ADMIN_EXC", "ASC"]],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!exercises || exercises.length === 0) {
|
if (!exercises || exercises.length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ export const getTopicBySectionId = async (req, res) => {
|
||||||
const topics = await models.Topic.findAll({
|
const topics = await models.Topic.findAll({
|
||||||
where: { ID_SECTION: sectionId, IS_DELETED: 0 },
|
where: { ID_SECTION: sectionId, IS_DELETED: 0 },
|
||||||
attributes: ["ID_TOPIC", "NAME_TOPIC", "DESCRIPTION_TOPIC"],
|
attributes: ["ID_TOPIC", "NAME_TOPIC", "DESCRIPTION_TOPIC"],
|
||||||
|
order: [["TIME_TOPIC", "ASC"]],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!topics || topics.length === 0) {
|
if (!topics || topics.length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import express from "express";
|
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";
|
import { verifyLoginUser, adminOnly } from "../../middlewares/User/authUser.js";
|
||||||
|
|
||||||
const router = express.Router();
|
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/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);
|
router.post("/register/admin", verifyLoginUser, adminOnly, registerAdmin);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user