From 3d10fc562eacc23e2b6b35d325e156374432d80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ti=E1=BA=BFn=20T=C3=A0i?= <63393170+fdhhhdjd@users.noreply.github.com> Date: Mon, 17 Apr 2023 00:10:15 +0700 Subject: [PATCH] #230 [Backend] CURD Student CMS --- .../student.controllers/student.controller.js | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/backend-manager-student/src/admin_api/v1/controllers/student.controllers/student.controller.js b/backend-manager-student/src/admin_api/v1/controllers/student.controllers/student.controller.js index 474be44..d55aee5 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/student.controllers/student.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/student.controllers/student.controller.js @@ -187,48 +187,47 @@ const StudentController = { }, }); } - - if (role) { - const result_detail_role = await student_model.getAdminId( - { - user_id: admin_id, - isdeleted: CONSTANTS.DELETED_DISABLE, - }, - { - role: 'role', - }, - ); - if (!result_detail_role || !result_detail_role.length) { - return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ - status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, - message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), - element: { - result: MESSAGES.ADMIN.NOT_EXIT_ACCOUNT, + try { + if (role) { + const result_detail_role = await student_model.getAdminId( + { + user_id: admin_id, + isdeleted: CONSTANTS.DELETED_DISABLE, }, - }); - } - if (Number(result_detail_role[0]?.role === CONSTANTS.ROLE.ROLE_MANAGER)) { - if (Number(role) !== CONSTANTS.ROLE.ROLE_STUDENT) { + { + role: 'role', + }, + ); + if (!result_detail_role || !result_detail_role.length) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), element: { - result: MESSAGES.GENERAL.INVALID_ROLE, + result: MESSAGES.ADMIN.NOT_EXIT_ACCOUNT, }, }); } + if (Number(result_detail_role[0]?.role === CONSTANTS.ROLE.ROLE_MANAGER)) { + if (Number(role) !== CONSTANTS.ROLE.ROLE_STUDENT) { + return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ + status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, + message: returnReasons(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST), + element: { + result: MESSAGES.GENERAL.INVALID_ROLE, + }, + }); + } + } } - } - const data_update = { - name, - avatar_uri, - public_id_avatar, - address, - dob, - gender, - role, - }; - try { + const data_update = { + name, + avatar_uri, + public_id_avatar, + address, + dob, + gender, + role, + }; // Check data book exits const result_student = await student_model.getStudentById( {