diff --git a/backend-manager-student/src/admin_api/v1/Swagger/admin_api/categories.swagger.yaml b/backend-manager-student/src/admin_api/v1/Swagger/admin_api/categories.swagger.yaml index 73e71eb..f23872e 100644 --- a/backend-manager-student/src/admin_api/v1/Swagger/admin_api/categories.swagger.yaml +++ b/backend-manager-student/src/admin_api/v1/Swagger/admin_api/categories.swagger.yaml @@ -107,7 +107,7 @@ paths: post: summary: Create categories tags: [Create categories] - operationId: createcategories + operationId: createCategories parameters: - $ref: '#/components/parameters/COOKIE-CLIENT' - $ref: '#/components/parameters/X-DEVICE-ID' diff --git a/backend-manager-student/src/admin_api/v1/Swagger/admin_api/student.swagger.yaml b/backend-manager-student/src/admin_api/v1/Swagger/admin_api/student.swagger.yaml new file mode 100644 index 0000000..379374e --- /dev/null +++ b/backend-manager-student/src/admin_api/v1/Swagger/admin_api/student.swagger.yaml @@ -0,0 +1,450 @@ +#!@author Nguyễn Tiến Tài +#!created_at 08/02/2023 +#!description: General +# Info Swagger Admin APi +info: + title: Document Admin + description: CURD Student + version: 1.0.0 +servers: + - url: http://localhost:5000 + description: Local development server admin api +# General +components: + # Parameter + parameters: + X-DEVICE-ID: + in: header + name: X-DEVICE-ID + required: true + schema: + type: string + X-OS-TYPE: + in: header + name: X-OS-TYPE + required: true + schema: + type: string + X-OS-VERSION: + in: header + name: X-OS-VERSION + required: true + schema: + type: string + X-APP-VERSION: + in: header + name: X-APP-VERSION + required: true + schema: + type: string + X-DEVICE-NAME: + in: header + name: X-DEVICE-NAME + required: true + schema: + type: string + TOKEN: + in: header + name: Authorization + type: string + description: Bearer Token + required: true + schema: + type: bearerToken + # Unauthorized + responses: + UnauthorizedError: + description: Access token is missing or invalid, or the user does not have access to perform the action,or or Device Invalid + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: 'Unauthorized' + # Fail CURD Fail + ServerCURDFail: + description: CURD Fail !!! + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Service Unavailable + element: + type: object + example: Internal Server Error + ServerFail: + description: Service die + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 503 + message: + type: string + example: Service Unavailable + element: + type: object + example: Out Of Service + #!@author Nguyễn Tiến Tài + #!created_at 25/03/2023 + #!description: create student +paths: + /v1/admin/private/student/create: + post: + summary: Create Student + tags: [Create Student] + operationId: createStudent + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + create_student_input: + type: object + properties: + name: + type: string + example: Tai + mssv: + type: number + example: 60136782 + phone_number: + type: string + example: 0798805764 + class_room: + type: string + example: 60-CNTT2 + email: + type: string + example: 60-CNTT2 + dob: + type: number + example: 20000101 + gender: + type: number + example: 1 + required: + - name + - mssv + - email + - gender + - dob + - class_room + - phone_number + responses: + 200: + description: Create success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 500: + description: Add database fail + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Duplicate and Error unknown + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 25/03/2023 + #!description: update student + /v1/admin/private/student/update: + post: + summary: Update Student + tags: [Update Student] + operationId: updateStudent + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + update_student_input: + type: object + properties: + student_id: + type: number + example: 12312312414 + name: + type: string + example: Tai + mssv: + type: number + example: 60136782 + phone_number: + type: string + example: 0798805764 + class_room: + type: string + example: 60-CNTT2 + email: + type: string + example: 60-CNTT2 + dob: + type: number + example: 20000101 + gender: + type: number + example: 1 + required: + - student_id + - name + - mssv + - email + - gender + - dob + - class_room + - phone_number + responses: + 200: + description: update success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 500: + description: Add database fail + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Duplicate and Error unknown + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 25/03/2023 + #!description: delete student + /v1/admin/private/student/delete: + post: + summary: Delete Student + tags: [Delete Student] + operationId: deleteStudent + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + input: + type: object + properties: + student_id: + type: object + properties: + student_id: + type: string + example: 1474830717476143106 + required: + - student_id + responses: + 200: + description: Delete success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 400: + description: Invalid input + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 400 + message: + type: string + example: Bad Request + 500: + description: Add database fail + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 500 + message: + type: string + example: Duplicate and Error unknown + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 25/03/2023 + #!description: detail student + /v1/admin/private/student/detail/:student_id: + get: + summary: Detail Student + tags: [Detail Student] + operationId: detailStudent + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + responses: + 200: + description: Detail success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' + + #!@author Nguyễn Tiến Tài + #!created_at 25/03/2023 + #!description: all student + /v1/admin/private/student/all: + get: + summary: Get all Student + tags: [Get all Student] + operationId: getAllStudent + parameters: + - $ref: '#/components/parameters/COOKIE-CLIENT' + - $ref: '#/components/parameters/X-DEVICE-ID' + - $ref: '#/components/parameters/X-OS-TYPE' + - $ref: '#/components/parameters/X-OS-VERSION' + - $ref: '#/components/parameters/X-APP-VERSION' + - $ref: '#/components/parameters/X-DEVICE-NAME' + - $ref: '#/components/parameters/TOKEN' + responses: + 200: + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: integer + example: 200 + message: + type: string + example: Success + 503: + $ref: '#/components/responses/ServerFail' diff --git a/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js b/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js index c867c37..e7c31d5 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js @@ -80,7 +80,7 @@ const authorController = { const { author_id, name, avatar_uri, dob, gender } = req.body.input.author_input; // Check input - if (!author_id) { + if (!author_id || !HELPER.validateBigInt(author_id)) { 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), diff --git a/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js b/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js index 5b74feb..777385a 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js @@ -117,7 +117,7 @@ const bookController = { } = req.body.input.book_input; // Check input - if (!book_id) { + if (!book_id || !HELPER.validateBigInt(book_id)) { 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), @@ -163,7 +163,11 @@ const bookController = { let err; let result; [err, result] = await HELPER.handleRequest( - book_model.updateBook(data_update, { book_id }, { book_id: 'book_id' }), + book_model.updateBook( + data_update, + { book_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + { book_id: 'book_id' }, + ), ); if (result) { // Create key Cache diff --git a/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js b/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js index e507ce8..8184638 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js @@ -22,9 +22,7 @@ const BorrowBookController = { * @return {Object:{Number,String} */ updateBorrowBook: async (req, res) => { - const { - book_id, user_id, start_date, due_date, status, - } = req.body.input.borrow_book_input; + const { book_id, user_id, start_date, due_date, status } = req.body.input.borrow_book_input; // Check input if (!book_id || !user_id || !start_date || !due_date || !status) { diff --git a/backend-manager-student/src/admin_api/v1/controllers/categories.controllers/categories.controller.js b/backend-manager-student/src/admin_api/v1/controllers/categories.controllers/categories.controller.js index b36fcd3..ed60d58 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/categories.controllers/categories.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/categories.controllers/categories.controller.js @@ -77,7 +77,7 @@ const categoriesController = { const { category_id, name } = req.body.input.categories_input; // Check input - if (!category_id) { + if (!category_id || !HELPER.validateBigInt(category_id)) { 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), 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 new file mode 100644 index 0000000..83e372b --- /dev/null +++ b/backend-manager-student/src/admin_api/v1/controllers/student.controllers/student.controller.js @@ -0,0 +1,396 @@ +//! SHARE +const HELPER = require('../../../../share/utils/helper'); +const CONSTANTS = require('../../../../share/configs/constants'); +const MESSAGES = require('../../../../share/configs/message'); +const RANDOMS = require('../../../../share/utils/random'); +const PASSWORD = require('../../../../share/utils/password'); + +//! MIDDLEWARE +const { returnReasons, returnDuplicate } = require('../../../../share/middleware/handle_error'); + +//! UTILS +const MEMORY_CACHE = require('../../../../share/utils/limited_redis'); + +//! MODEL +const student_model = require('../../../../share/models/user.model'); + +//! SERVICE + +const StudentController = { + /** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2022 + * @description create Student + * @function createStudent + * @return {Object} + */ + createStudent: async (req, res) => { + const { name, mssv, phone_number, dob, class_room, email, gender } = req.body.input.create_student_input; + // Check input + if (!name || !mssv || !phone_number || !dob || !class_room || !email || !gender) { + 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_INPUT, + }, + }); + } + + const check_email = HELPER.validateEmail(email); + + const check_phone = HELPER.validatePhone(phone_number); + + if (!check_email || !check_phone) { + 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_EMAIL_PHONE, + }, + }); + } + + const phone_hide = HELPER.maskLastPhoneNumber(phone_number); + const password = HELPER.handleRemoveHyphen(dob); + + const password_student = await PASSWORD.encodePassword(password); + try { + // create Category database + let err; + let result; + [err, result] = await HELPER.handleRequest( + student_model.createStudent({ + user_id: RANDOMS.createID(), + name, + mssv, + phone_number, + password: password_student, + phone_hidden: phone_hide, + dob, + class: class_room, + email, + gender, + avatar_uri: + gender === CONSTANTS.GENDER_MALE ? CONSTANTS.GENDER_IMAGE_MALE : CONSTANTS.GENDER_IMAGE_FEMALE, + }), + ); + if (result) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result[0].user_id, + }, + }); + } + if (err) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR).json({ + status: CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR), + element: { + result: returnDuplicate(err), + }, + }); + } + } catch (error) { + console.error(error); + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2022 + * @description update Student + * @function updateStudent + * @return {Object} + */ + updateStudent: async (req, res) => { + // Input body + const { student_id, name, avatar_uri, public_id_avatar, address, dob, gender } = + req.body.input.update_student_input; + + // Check input + if (!student_id || !HELPER.validateBigInt(student_id)) { + 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_INPUT, + }, + }); + } + if ( + [name, avatar_uri, public_id_avatar, address, dob, gender].some( + (field) => field !== undefined && field.trim() === '', + ) + ) { + 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_MUTILP_FIELD, + }, + }); + } + const data_update = { + name, + avatar_uri, + public_id_avatar, + address, + dob, + gender, + }; + try { + // Check data book exits + const result_student = await student_model.getStudentById( + { user_id: student_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + { user_id: 'user_id' }, + ); + + if (!result_student || !result_student.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.STUDENT.NOT_EXIT_ACCOUNT, + }, + }); + } + + let err; + let result; + // Update student database + [err, result] = await HELPER.handleRequest( + student_model.updateStudent( + data_update, + { user_id: student_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + { user_id: 'user_id' }, + ), + ); + if (result) { + // Create key redis profile + const key_student_id = HELPER.getURIFromTemplate(CONSTANTS.KEY_PROFILE_STUDENT, { + user_id: student_id, + }); + // Delete cache profile student + MEMORY_CACHE.delKeyCache(key_student_id); + + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: MESSAGES.GENERAL.SUCCESS_UPDATE_STUDENT, + }, + }); + } + if (err) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR).json({ + status: CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR), + }); + } + } catch (error) { + console.error(error); + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 25/03/2022 + * @description deleteStudent + * @function deleteStudent + * @return {Object} + */ + deleteStudent: async (req, res) => { + const { student_id } = req.body.input.student_id; + + // Check input + if (!student_id || !req.body) { + 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_INPUT, + }, + }); + } + try { + // Check account already delete + const result_student_detail = await student_model.getStudentById( + { user_id: student_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + { user_id: 'user_id' }, + ); + if (!result_student_detail.length || !result_student_detail) { + 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.STUDENT.NOT_EXIT_ACCOUNT, + }, + }); + } + // Delete author database + let err; + let result; + [err, result] = await HELPER.handleRequest( + student_model.updateStudent( + { + isdeleted: CONSTANTS.DELETED_ENABLE, + }, + { user_id: student_id, isdeleted: CONSTANTS.DELETED_DISABLE }, + { user_id: 'user_id' }, + ), + ); + if (result) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result[0].user_id, + }, + }); + } + if (err) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR).json({ + status: CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_INTERNAL_SERVER_ERROR), + element: { + result: returnDuplicate(err), + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Get All student + * @function getAllStudent + * @return {Object} + */ + getAllStudent: async (req, res) => { + try { + // Check student exit database + let data_return = { + user_id: 'user.user_id', + role: 'user.role', + mssv: 'user.mssv', + name: 'user.name', + avatar_uri: 'user.avatar_uri', + email: 'user.email', + address: 'user.address', + dob: 'user.dob', + gender: 'user.gender', + class: 'user.class', + phone_hidden: 'user.phone_hidden', + }; + // Take data db + const result_student = await student_model.getAllStudentJoinPhone( + { isdeleted: CONSTANTS.DELETED_DISABLE }, + data_return, + ); + + if (result_student) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result_student, + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 09/03/2022 + * @description Detail Borrowed Book + * @function borrowBook + * @return {Object:{Number,String} + */ + getDetailStudent: async (req, res) => { + const student_id = req.params.student_id; + + // Check input + if (!student_id) { + 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_INPUT, + }, + }); + } + try { + // Check student exit database + let data_return = { + user_id: 'user.user_id', + role: 'user.role', + mssv: 'user.mssv', + name: 'user.name', + avatar_uri: 'user.avatar_uri', + email: 'user.email', + address: 'user.address', + dob: 'user.dob', + gender: 'user.gender', + class: 'user.class', + phone_hidden: 'user.phone_hidden', + }; + + let data_query = { + user_id: student_id, + isdeleted: CONSTANTS.DELETED_DISABLE, + }; + // Take data db + const result_student_detail = await student_model.getStudentJoinPhoneById(data_query, data_return); + + if (result_student_detail) { + return res.status(CONSTANTS.HTTP.STATUS_2XX_OK).json({ + status: CONSTANTS.HTTP.STATUS_2XX_OK, + message: returnReasons(CONSTANTS.HTTP.STATUS_2XX_OK), + element: { + result: result_student_detail, + }, + }); + } + } catch (error) { + return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ + status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, + message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE), + element: { + result: MESSAGES.GENERAL.SERVER_OUT_OF_SERVICE, + }, + }); + } + }, +}; +module.exports = StudentController; diff --git a/backend-manager-student/src/admin_api/v1/routes/admin.routes/admin.route.js b/backend-manager-student/src/admin_api/v1/routes/admin.routes/admin.route.js index 11dfcad..5613e29 100644 --- a/backend-manager-student/src/admin_api/v1/routes/admin.routes/admin.route.js +++ b/backend-manager-student/src/admin_api/v1/routes/admin.routes/admin.route.js @@ -5,6 +5,7 @@ const adminController = require('../../controllers/admin.controllers/admin.contr * @created_at 17/12/2022 * @update_at 11/01/2023 * @description Route login admin + * @param {('POST')} [method='POST'] The request's method */ router.post('/login', adminController.LoginAdmin); diff --git a/backend-manager-student/src/admin_api/v1/routes/author.routes/author.private.route.js b/backend-manager-student/src/admin_api/v1/routes/author.routes/author.private.route.js index 31c67da..a2e4277 100644 --- a/backend-manager-student/src/admin_api/v1/routes/author.routes/author.private.route.js +++ b/backend-manager-student/src/admin_api/v1/routes/author.routes/author.private.route.js @@ -32,7 +32,7 @@ router.post('/delete', authorController.deleteAuthor); * @author Nguyễn Tiến Tài * @created_at 03/01/2023 * @description Route get detail author - * @param {('POST')} [method='POST'] The request's method + * @param {('GET')} [method='GET'] The request's method */ router.get('/detail/:author_id', authorController.getDetailAuthor); @@ -40,7 +40,7 @@ router.get('/detail/:author_id', authorController.getDetailAuthor); * @author Nguyễn Tiến Tài * @created_at 03/01/2023 * @description Route get all author - * @param {('POST')} [method='POST'] The request's method + * @param {('GET')} [method='GET'] The request's method */ router.get('/all', authorController.getAllAuthor); diff --git a/backend-manager-student/src/admin_api/v1/routes/book.routes/book.private.route.js b/backend-manager-student/src/admin_api/v1/routes/book.routes/book.private.route.js index 1e68dd3..a92cb14 100644 --- a/backend-manager-student/src/admin_api/v1/routes/book.routes/book.private.route.js +++ b/backend-manager-student/src/admin_api/v1/routes/book.routes/book.private.route.js @@ -32,7 +32,7 @@ router.post('/delete', bookController.deleteBook); * @author Nguyễn Tiến Tài * @created_at 03/01/2023 * @description Route get detail book - * @param {('POST')} [method='POST'] The request's method + * @param {('GET')} [method='GET'] The request's method */ router.get('/detail/:book_id', bookController.getDetailBook); @@ -40,7 +40,7 @@ router.get('/detail/:book_id', bookController.getDetailBook); * @author Nguyễn Tiến Tài * @created_at 03/01/2023 * @description Route get all book - * @param {('POST')} [method='POST'] The request's method + * @param {('GET')} [method='GET'] The request's method */ router.get('/all', bookController.getAllBook); diff --git a/backend-manager-student/src/admin_api/v1/routes/categories.routes/categories.private.route.js b/backend-manager-student/src/admin_api/v1/routes/categories.routes/categories.private.route.js index 8f00e19..3838102 100644 --- a/backend-manager-student/src/admin_api/v1/routes/categories.routes/categories.private.route.js +++ b/backend-manager-student/src/admin_api/v1/routes/categories.routes/categories.private.route.js @@ -32,7 +32,7 @@ router.post('/delete', categoriesController.deleteCategories); * @author Nguyễn Tiến Tài * @created_at 03/01/2023 * @description Route get detail categories - * @param {('POST')} [method='POST'] The request's method + * @param {('GET')} [method='GET'] The request's method */ router.get('/detail/:category_id', categoriesController.getDetailCategories); @@ -40,7 +40,7 @@ router.get('/detail/:category_id', categoriesController.getDetailCategories); * @author Nguyễn Tiến Tài * @created_at 03/01/2023 * @description Route get all categories - * @param {('POST')} [method='POST'] The request's method + * @param {('GET')} [method='GET'] The request's method */ router.get('/all', categoriesController.getAllCategories); diff --git a/backend-manager-student/src/admin_api/v1/routes/private.routes.js b/backend-manager-student/src/admin_api/v1/routes/private.routes.js index 56a8d3f..cd9d74e 100644 --- a/backend-manager-student/src/admin_api/v1/routes/private.routes.js +++ b/backend-manager-student/src/admin_api/v1/routes/private.routes.js @@ -7,6 +7,7 @@ const bookPrivateRouter = require('./book.routes/book.private.route'); const authorPrivateRouter = require('./author.routes/author.private.route'); const categoriesPrivateRouter = require('./categories.routes/categories.private.route'); const borrowBookPrivateRouter = require('./borrow_book_routes/borrow_book_private.route'); +const studentPrivateRouter = require('./student.routes/student.private.route'); /** * @author Nguyễn Tiến Tài @@ -44,4 +45,11 @@ router_private.use('/categories', categoriesPrivateRouter); */ router_private.use('/borrow_book', borrowBookPrivateRouter); +/** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Route borrow book + */ +router_private.use('/student', studentPrivateRouter); + module.exports = router_private; diff --git a/backend-manager-student/src/admin_api/v1/routes/student.routes/student.private.route.js b/backend-manager-student/src/admin_api/v1/routes/student.routes/student.private.route.js new file mode 100644 index 0000000..7a00b8e --- /dev/null +++ b/backend-manager-student/src/admin_api/v1/routes/student.routes/student.private.route.js @@ -0,0 +1,47 @@ +//! LIBARY +const router = require('express').Router(); + +//! CONTROLLER USER +const studentController = require('../../controllers/student.controllers/student.controller'); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Route create student + * @param {('POST')} [method='POST'] The request's method + */ +router.post('/create', studentController.createStudent); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Route Update student + * @param {('POST')} [method='POST'] The request's method + */ +router.post('/update', studentController.updateStudent); + +/** + * @author Nguyễn Tiến Tài + * @created_at 25/03/2023 + * @description Route delete student + * @param {('POST')} [method='POST'] The request's method + */ +router.post('/delete', studentController.deleteStudent); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Route get detail student + * @param {('GET')} [method='GET'] The request's method + */ +router.get('/detail/:student_id', studentController.getDetailStudent); + +/** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Route get all student + * @param {('GET')} [method='GET'] The request's method + */ +router.get('/all', studentController.getAllStudent); + +module.exports = router; diff --git a/backend-manager-student/src/share/configs/key_duplicate.js b/backend-manager-student/src/share/configs/key_duplicate.js new file mode 100644 index 0000000..92cb0e5 --- /dev/null +++ b/backend-manager-student/src/share/configs/key_duplicate.js @@ -0,0 +1,10 @@ +module.exports = { + /** + * @author Nguyễn Tiến Tài + * @created_at 25/03/2022 + * @description KEY_DUPLICATE + */ + DUPLICATE_KEY_EMAIL: 'email_unique', + DUPLICATE_KEY_PHONE: 'phone_number_unique', + DUPLICATE_KEY_MSSV: 'mssv_unique', +}; diff --git a/backend-manager-student/src/share/configs/message.js b/backend-manager-student/src/share/configs/message.js index b6c9237..00dc906 100644 --- a/backend-manager-student/src/share/configs/message.js +++ b/backend-manager-student/src/share/configs/message.js @@ -45,6 +45,9 @@ module.exports = { EXITS_DELETE_CATEGORIES: 'Categories already delete !', EXITS_UPDATE_BORROW: 'Already update borrow book !', EXITS_CAN_ONLY_TOW_BORROW: 'You can only borrow tow book!', + EXITS_EMAIL: 'Email not exit!', + EXITS_PHONE: 'Phone not exit!', + EXITS_MSSV: 'mssv not exit!', // ? ALREADY ALREADY_BOOK_BORROW: 'Book already borrow !!', @@ -57,6 +60,7 @@ module.exports = { // ? FAIL BORROW_FAIL: 'Borrow Fail!', RESET_PASSWORD_FAIL: 'Reset Password Fail', + ERROR_UNKNOWN: 'Error unknown', // ? CONFLICT OR DUPLICATE CONFLICT_ADD_STUDENT: 'Nothing changes to update!', @@ -86,6 +90,7 @@ module.exports = { // ? SUCCESS SUCCESS_CHANGE_PASSWORD: 'Change Password Success!', SUCCESS_UPDATE_BORROW: 'Update Student borrow book success !', + SUCCESS_UPDATE_STUDENT: 'Update Student success !', SUCCESS_UPDATE_BORROW_STUDENT_REFUND: 'Update Student refund book success !', SUCCESS_BORROW_BOOK_SUCCESS: 'Invite you go to Library confirm,Thank', }, diff --git a/backend-manager-student/src/share/middleware/handle_error.js b/backend-manager-student/src/share/middleware/handle_error.js index dcc2d6f..d0e3cc4 100644 --- a/backend-manager-student/src/share/middleware/handle_error.js +++ b/backend-manager-student/src/share/middleware/handle_error.js @@ -1,5 +1,7 @@ //! SHARE const CONSTANTS = require('../configs/constants'); +const KEY_DUPLICATE = require('../configs/key_duplicate'); +const MESSAGES = require('../configs/message'); module.exports = { /** @@ -13,4 +15,32 @@ module.exports = { returnReasons: (code) => CONSTANTS.reasonPhraseCodeProNewMap().get(code.toString()) || CONSTANTS.reasonPhraseCodeProNewMap().get(CONSTANTS.HTTP.NO_STATUS_DEFAULT), + + /** + * @author Nguyễn Tiến Tài + * @created_at 25/03/2023 + * @description returnDuplicate + * @function returnDuplicate + * @param { error } + * @return { String } + */ + returnDuplicate: (error) => { + const constraint = error.constraint; + let message; + switch (constraint) { + case KEY_DUPLICATE.DUPLICATE_KEY_EMAIL: + message = MESSAGES.GENERAL.EXITS_EMAIL; + break; + case KEY_DUPLICATE.DUPLICATE_KEY_PHONE: + message = MESSAGES.GENERAL.EXITS_PHONE; + break; + case KEY_DUPLICATE.DUPLICATE_KEY_MSSV: + message = MESSAGES.GENERAL.EXITS_MSSV; + break; + default: + message = MESSAGES.GENERAL.ERROR_UNKNOWN; + break; + } + return message; + }, }; diff --git a/backend-manager-student/src/share/models/book.model.js b/backend-manager-student/src/share/models/book.model.js index 776e383..026fa6f 100644 --- a/backend-manager-student/src/share/models/book.model.js +++ b/backend-manager-student/src/share/models/book.model.js @@ -1,6 +1,9 @@ //! DATABASE const knex = require('../db/postgresql'); +//! SHARE +const CONSTANTS = require('../configs/constants'); + module.exports = { /** * @author Nguyễn Tiến Tài @@ -22,8 +25,22 @@ module.exports = { * @created_at 03/01/2023 * @description get book id */ - getBookById: async (student_query, return_data) => { - const result = await knex('books').select(return_data).where(student_query); + getBookById: async (student_query) => { + const result = await knex('books') + .join('authors', 'books.author_id', '=', 'authors.author_id') + .where({ + 'books.isdeleted': student_query.isdeleted, + 'books.book_id': student_query.book_id, + }) + .select( + { + name_author: 'authors.name', + dob_author: 'authors.dob', + gender_author: 'authors.gender', + image_author: 'authors.avatar_uri', + }, + 'books.*', + ); return result; }, /** @@ -46,8 +63,20 @@ module.exports = { * @updated_at 07/02/2023 * @description Get all book */ - getAllBook: async (student_query, return_data) => { - const result = await knex('books').select(return_data).where(student_query).orderBy('updated_at', 'desc'); + getAllBook: async () => { + const result = await knex('books') + .join('authors', 'books.author_id', '=', 'authors.author_id') + .where('books.isdeleted', '=', CONSTANTS.DELETED_DISABLE) + .select( + { + name_author: 'authors.name', + dob_author: 'authors.dob', + gender_author: 'authors.gender', + image_author: 'authors.avatar_uri', + }, + 'books.*', + ) + .orderBy('books.updated_at', 'desc'); return result; }, }; diff --git a/backend-manager-student/src/share/models/book_borrowed.model.js b/backend-manager-student/src/share/models/book_borrowed.model.js index 0c56fe9..c5f6ca3 100644 --- a/backend-manager-student/src/share/models/book_borrowed.model.js +++ b/backend-manager-student/src/share/models/book_borrowed.model.js @@ -10,18 +10,19 @@ module.exports = { * @created_at 07/03/2023 * @description create BorrowBook */ - createBorrowBook: (data) => new Promise((resolve, reject) => { - try { - const result = knex('borrowed_book') - .insert(data) - .onConflict('borrowed_book_id') - .merge() - .returning(['borrowed_book_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + createBorrowBook: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('borrowed_book') + .insert(data) + .onConflict('borrowed_book_id') + .merge() + .returning(['borrowed_book_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài @@ -37,14 +38,15 @@ module.exports = { * @created_at 07/03/2023 * @description Update BorrowBook */ - updateBorrowBook: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('borrowed_book').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateBorrowBook: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('borrowed_book').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 07/03/2023 @@ -67,15 +69,12 @@ module.exports = { queryBuilder.where('user_id', user_id); } }) - .select( - 'books.name', - 'books.image_uri', - 'books.description', - 'books.page_number', - 'borrowed_book.*', - 'authors.name', - 'authors.avatar_uri', - ) + .select('books.name', 'books.image_uri', 'books.description', 'books.page_number', 'borrowed_book.*', { + name_author: 'authors.name', + dob_author: 'authors.dob', + gender_author: 'authors.gender', + image_author: 'authors.avatar_uri', + }) .orderBy('borrowed_book.updated_at', 'desc'); return result; }, @@ -84,60 +83,62 @@ module.exports = { * @created_at 07/03/2023 * @description Transaction Update Borrow Book */ - transactionUpdateBorrowBook: async (data_update_book, data_update_borrow) => new Promise(async (resolve, reject) => { - // start transaction - const trx = await knex.transaction(); - try { - // Query 1: createBorrowBook - const borrowBookId = await trx('borrowed_book') - .update({ status: data_update_borrow.status }) - .where({ book_id: data_update_borrow.book_id, user_id: data_update_borrow.user_id }) - .returning(['borrowed_book_id']); + transactionUpdateBorrowBook: async (data_update_book, data_update_borrow) => + new Promise(async (resolve, reject) => { + // start transaction + const trx = await knex.transaction(); + try { + // Query 1: createBorrowBook + const borrowBookId = await trx('borrowed_book') + .update({ status: data_update_borrow.status }) + .where({ book_id: data_update_borrow.book_id, user_id: data_update_borrow.user_id }) + .returning(['borrowed_book_id']); - // Query 2: updateBorrowBook - const updatedData = await trx('books') - .update({ quantity: data_update_book.quantity }) - .where({ book_id: data_update_book.book_id }) - .returning(['book_id']); + // Query 2: updateBorrowBook + const updatedData = await trx('books') + .update({ quantity: data_update_book.quantity }) + .where({ book_id: data_update_book.book_id }) + .returning(['book_id']); - // Commit transaction - await trx.commit(); - return resolve(borrowBookId, updatedData); - } catch (error) { - trx.rollback(); - reject(error); - } - }), + // Commit transaction + await trx.commit(); + return resolve(borrowBookId, updatedData); + } catch (error) { + trx.rollback(); + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 08/03/2023 * @description Transaction Borrow Book */ - transactionBorrowBook: async (data_insert, data_update) => new Promise(async (resolve, reject) => { - // start transaction - const trx = await knex.transaction(); - try { - // Query 1: createBorrowBook - const borrowBookId = await trx('borrowed_book') - .insert(data_insert) - .onConflict('borrowed_book_id') - .merge() - .returning(['borrowed_book_id']); + transactionBorrowBook: async (data_insert, data_update) => + new Promise(async (resolve, reject) => { + // start transaction + const trx = await knex.transaction(); + try { + // Query 1: createBorrowBook + const borrowBookId = await trx('borrowed_book') + .insert(data_insert) + .onConflict('borrowed_book_id') + .merge() + .returning(['borrowed_book_id']); - // Query 2: updateBorrowBook - const updatedData = await trx('books') - .update(data_update) - .where({ book_id: data_insert.book_id }) - .returning(['book_id']); + // Query 2: updateBorrowBook + const updatedData = await trx('books') + .update(data_update) + .where({ book_id: data_insert.book_id }) + .returning(['book_id']); - // Commit transaction - await trx.commit(); - return resolve(borrowBookId, updatedData); - } catch (error) { - trx.rollback(); - reject(error); - } - }), + // Commit transaction + await trx.commit(); + return resolve(borrowBookId, updatedData); + } catch (error) { + trx.rollback(); + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 09/03/2023 diff --git a/backend-manager-student/src/share/models/user.model.js b/backend-manager-student/src/share/models/user.model.js index 8217b5e..a0155aa 100644 --- a/backend-manager-student/src/share/models/user.model.js +++ b/backend-manager-student/src/share/models/user.model.js @@ -34,6 +34,28 @@ module.exports = { const student = await knex('user').select(return_data).where(student_query); return student; }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/01/2023 + * @description Get student info by ID + */ + getStudentJoinPhoneById: async (student_query, return_data) => { + const student = await knex('user') + .leftJoin('phone', 'user.phone_id', '=', 'phone.phone_id') + .where({ + 'user.isdeleted': student_query.isdeleted, + 'user.user_id': student_query.user_id, + }) + .select( + { + phone_mobile_country_code: 'phone.mobile_country_code', + phone_mobile_network_code: 'phone.mobile_network_code', + phone_mobile_network_name: 'phone.mobile_network_name', + }, + return_data, + ); + return student; + }, /** * @author Nguyễn Tiến Tài * @created_at 13/02/2023 @@ -60,4 +82,44 @@ module.exports = { .whereNot('role', CONSTANTS.ROLE.ROLE_STUDENT); return admins; }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description Get All Student Join Phone + */ + getAllStudentJoinPhone: async (student_query, return_data) => { + const student = await knex('user') + .leftJoin('phone', 'user.phone_id', '=', 'phone.phone_id') + .where({ + 'user.isdeleted': student_query.isdeleted, + }) + .modify((queryBuilder) => { + if (student_query.user_id) { + queryBuilder.where('user_id', student_query.user_id); + } + }) + .select( + { + phone_mobile_country_code: 'phone.mobile_country_code', + phone_mobile_network_code: 'phone.mobile_network_code', + phone_mobile_network_name: 'phone.mobile_network_name', + }, + return_data, + ); + return student; + }, + /** + * @author Nguyễn Tiến Tài + * @created_at 24/03/2023 + * @description create Student + */ + createStudent: (data) => + new Promise((resolve, reject) => { + try { + const result_student = knex('user').insert(data).onConflict('user_id').merge().returning(['user_id']); + resolve(result_student); + } catch (error) { + reject(error); + } + }), }; diff --git a/backend-manager-student/src/share/utils/helper.js b/backend-manager-student/src/share/utils/helper.js index e4b92a6..e78ecc6 100644 --- a/backend-manager-student/src/share/utils/helper.js +++ b/backend-manager-student/src/share/utils/helper.js @@ -62,10 +62,6 @@ module.exports = { * @returns {boolean} */ validatePhone(phone) { - // var phoneRegex = /^+?([0-9]{2})\)?([0-9]{9})$/; - // var phoneRegex = /^(\+91-|\+91|0)?\d{11}$/; - // var vnf_regex = /((09|03|07|08|05|01)+([0-9]{9|8})\b)/g; - // const phoneRegex = /^[0-9\+]{10,15}$/g; const phoneVietNam = REGEX.REGEX_PHONE; return phoneVietNam.test(phone); }, @@ -300,6 +296,14 @@ module.exports = { const formattedDateTime = `${day}-${month}-${year} ${hours}:${minutes}:${seconds}`; return formattedDateTime; }, + /** + * Method Convert phone + * @author Nguyen Tien Tai + * @created_at 15/01/2023 + * @function isExpired + * @param {time_expire_reset} + * @returns {Boolean} + */ isExpired(time_expire_reset) { const now = Date.now(); const diff = time_expire_reset - now; @@ -310,4 +314,24 @@ module.exports = { // Expired return true; }, + /** + * Method Convert phone + * @author Nguyen Tien Tai + * @created_at 24/03/2023 + * @function isValidBigInt + * @param {id} + * @returns {Boolean} + */ + validateBigInt(id) { + try { + const bigIntValue = BigInt(id); + if (bigIntValue.toString() !== id) { + return false; + } + // input is a valid bigint + return true; + } catch (error) { + return false; + } + }, }; diff --git a/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js b/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js index b25e7ae..c3f6242 100644 --- a/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js +++ b/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js @@ -586,17 +586,17 @@ const userController = { try { // Check student exit database let data_return = { - user_id: 'user_id', - role: 'role', - mssv: 'mssv', - name: 'name', - avatar_uri: 'avatar_uri', - email: 'email', - address: 'address', - dob: 'dob', - gender: 'gender', - class: 'class', - phone_hidden: 'phone_hidden', + user_id: 'user.user_id', + role: 'user.role', + mssv: 'user.mssv', + name: 'user.name', + avatar_uri: 'user.avatar_uri', + email: 'user.email', + address: 'user.address', + dob: 'user.dob', + gender: 'user.gender', + class: 'user.class', + phone_hidden: 'user.phone_hidden', }; let data_query = { user_id, @@ -622,7 +622,7 @@ const userController = { } // Take data database - let users = await user_model.getStudentById(data_query, data_return); + let users = await user_model.getStudentJoinPhoneById(data_query, data_return); // Check account exits const user = users[0]; @@ -650,6 +650,7 @@ const userController = { }, }); } catch (err) { + console.error(err); return res.status(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE).json({ status: CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE, message: returnReasons(CONSTANTS.HTTP.STATUS_5XX_SERVICE_UNAVAILABLE),