From fd0a6b8f7a715a9c088368de8453313a5ffb42aa 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: Fri, 14 Apr 2023 21:25:38 +0700 Subject: [PATCH] #259 [Backend] change spec borrow_book and book --- .../admin.controllers/admin.controller.js | 10 ++--- .../book.controllers/book.controller.js | 38 +++++++++---------- .../borrow_book.controller.js | 8 ++-- .../src/share/middleware/handle_error.js | 28 +++++++------- .../src/share/models/author.model.js | 3 +- .../src/share/models/book.model.js | 3 +- .../src/share/models/phone.model.js | 3 +- .../src/share/models/rating.model.js | 3 +- .../src/share/models/user.model.js | 3 +- .../src/share/utils/redis_pub_sub_helper.js | 30 +++++++-------- .../user.controllers/user.controller.js | 20 +++++----- 11 files changed, 72 insertions(+), 77 deletions(-) diff --git a/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js b/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js index 4178d58..5cff459 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js @@ -629,11 +629,11 @@ const adminController = { // Check Input is empty if ( - (name !== undefined && name.trim() === '') || - (avatar_uri !== undefined && avatar_uri.trim() === '') || - (public_id_avatar !== undefined && public_id_avatar.trim() === '') || - (address !== undefined && address.trim() === '') || - (dob !== undefined && dob.trim() === '') + (name !== undefined && name.trim() === '') + || (avatar_uri !== undefined && avatar_uri.trim() === '') + || (public_id_avatar !== undefined && public_id_avatar.trim() === '') + || (address !== undefined && address.trim() === '') + || (dob !== undefined && dob.trim() === '') ) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: 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 7cc972d..4949d5e 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 @@ -41,16 +41,16 @@ const bookController = { // Check input if ( - !name || - !author_id || - !image_uri || - !description || - !bookshelf || - !language || - !quantity || - !public_id_image || - !page_number || - !real_quantity + !name + || !author_id + || !image_uri + || !description + || !bookshelf + || !language + || !quantity + || !public_id_image + || !page_number + || !real_quantity ) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, @@ -145,15 +145,15 @@ const bookController = { // Check Input is empty if ( - (name !== undefined && name.trim() === '') || - (author_id !== undefined && author_id.trim() === '') || - (image_uri !== undefined && image_uri.trim() === '') || - (description !== undefined && description.trim() === '') || - (bookshelf !== undefined && bookshelf.trim() === '') || - (language !== undefined && language.trim() === '') || - (quantity !== undefined && quantity.trim() === '') || - (public_id_image !== undefined && public_id_image.trim() === '') || - (page_number !== undefined && page_number.trim() === '') + (name !== undefined && name.trim() === '') + || (author_id !== undefined && author_id.trim() === '') + || (image_uri !== undefined && image_uri.trim() === '') + || (description !== undefined && description.trim() === '') + || (bookshelf !== undefined && bookshelf.trim() === '') + || (language !== undefined && language.trim() === '') + || (quantity !== undefined && quantity.trim() === '') + || (public_id_image !== undefined && public_id_image.trim() === '') + || (page_number !== undefined && page_number.trim() === '') ) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST, 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 e595822..c558934 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 @@ -242,8 +242,8 @@ const BorrowBookController = { let err; let result; if ( - Number(status) === CONSTANTS.STATUS_BORROW.BORROWING || - Number(status) === CONSTANTS.STATUS_BORROW.EXPIRED + Number(status) === CONSTANTS.STATUS_BORROW.BORROWING + || Number(status) === CONSTANTS.STATUS_BORROW.EXPIRED ) { // update book database [err, result] = await HELPER.handleRequest( @@ -269,8 +269,8 @@ const BorrowBookController = { }); } } else if ( - Number(status) === CONSTANTS.STATUS_BORROW.DONE || - Number(status) === CONSTANTS.STATUS_BORROW.LOST_BOOK_PROCESSED + Number(status) === CONSTANTS.STATUS_BORROW.DONE + || Number(status) === CONSTANTS.STATUS_BORROW.LOST_BOOK_PROCESSED ) { // Check data book exits const data_book = await book_model.getBookById( diff --git a/backend-manager-student/src/share/middleware/handle_error.js b/backend-manager-student/src/share/middleware/handle_error.js index 6f8b204..d0e3cc4 100644 --- a/backend-manager-student/src/share/middleware/handle_error.js +++ b/backend-manager-student/src/share/middleware/handle_error.js @@ -13,8 +13,8 @@ module.exports = { * @return { String } */ returnReasons: (code) => - CONSTANTS.reasonPhraseCodeProNewMap().get(code.toString()) || - CONSTANTS.reasonPhraseCodeProNewMap().get(CONSTANTS.HTTP.NO_STATUS_DEFAULT), + CONSTANTS.reasonPhraseCodeProNewMap().get(code.toString()) + || CONSTANTS.reasonPhraseCodeProNewMap().get(CONSTANTS.HTTP.NO_STATUS_DEFAULT), /** * @author Nguyễn Tiến Tài @@ -28,18 +28,18 @@ module.exports = { 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; + 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/author.model.js b/backend-manager-student/src/share/models/author.model.js index 6d8e652..776a75c 100644 --- a/backend-manager-student/src/share/models/author.model.js +++ b/backend-manager-student/src/share/models/author.model.js @@ -10,8 +10,7 @@ module.exports = { createAuthor: (data) => new Promise((resolve, reject) => { try { - const result = knex('authors').insert(data).onConflict('author_id').merge() - .returning(['author_id']); + const result = knex('authors').insert(data).onConflict('author_id').merge().returning(['author_id']); resolve(result); } catch (error) { reject(error); diff --git a/backend-manager-student/src/share/models/book.model.js b/backend-manager-student/src/share/models/book.model.js index 725f405..17562d5 100644 --- a/backend-manager-student/src/share/models/book.model.js +++ b/backend-manager-student/src/share/models/book.model.js @@ -13,8 +13,7 @@ module.exports = { createBook: (data) => new Promise((resolve, reject) => { try { - const result = knex('books').insert(data).onConflict('book_id').merge() - .returning(['book_id']); + const result = knex('books').insert(data).onConflict('book_id').merge().returning(['book_id']); resolve(result); } catch (error) { reject(error); diff --git a/backend-manager-student/src/share/models/phone.model.js b/backend-manager-student/src/share/models/phone.model.js index 4fe56e1..c46c101 100644 --- a/backend-manager-student/src/share/models/phone.model.js +++ b/backend-manager-student/src/share/models/phone.model.js @@ -10,8 +10,7 @@ module.exports = { createPhone: (data) => new Promise((resolve, reject) => { try { - const result = knex('phone').insert(data).onConflict('phone_id').merge() - .returning(['phone_id']); + const result = knex('phone').insert(data).onConflict('phone_id').merge().returning(['phone_id']); resolve(result); } catch (error) { reject(error); diff --git a/backend-manager-student/src/share/models/rating.model.js b/backend-manager-student/src/share/models/rating.model.js index dfcac46..b1e0fa1 100644 --- a/backend-manager-student/src/share/models/rating.model.js +++ b/backend-manager-student/src/share/models/rating.model.js @@ -10,8 +10,7 @@ module.exports = { createRatings: (data) => new Promise((resolve, reject) => { try { - const result = knex('book_rates').insert(data).onConflict('rate_id').merge() - .returning(['rate_id']); + const result = knex('book_rates').insert(data).onConflict('rate_id').merge().returning(['rate_id']); resolve(result); } catch (error) { reject(error); diff --git a/backend-manager-student/src/share/models/user.model.js b/backend-manager-student/src/share/models/user.model.js index 1d81747..af10110 100644 --- a/backend-manager-student/src/share/models/user.model.js +++ b/backend-manager-student/src/share/models/user.model.js @@ -119,8 +119,7 @@ module.exports = { createStudent: (data) => new Promise((resolve, reject) => { try { - const result_student = knex('user').insert(data).onConflict('user_id').merge() - .returning(['user_id']); + 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/redis_pub_sub_helper.js b/backend-manager-student/src/share/utils/redis_pub_sub_helper.js index 898fef3..c16693e 100644 --- a/backend-manager-student/src/share/utils/redis_pub_sub_helper.js +++ b/backend-manager-student/src/share/utils/redis_pub_sub_helper.js @@ -74,21 +74,21 @@ const handleException = (err, name, port) => { }); let message_queue; switch (name) { - case CONSTANTS.NAME_SERVER.STUDENT: - message_queue = CONSTANTS.QUEUE.REDIS_SERVER_STUDENT; - break; - case CONSTANTS.NAME_SERVER.ADMIN: - message_queue = CONSTANTS.QUEUE.REDIS_SERVER_ADMIN; - break; - case CONSTANTS.NAME_SERVER.CRON: - message_queue = CONSTANTS.QUEUE.REDIS_SERVER_CRON; - break; - case CONSTANTS.NAME_SERVER.DB: - message_queue = CONSTANTS.QUEUE.REDIS_DB; - break; - default: - message_queue = CONSTANTS.QUEUE.REDIS_SERVER_CRON; - break; + case CONSTANTS.NAME_SERVER.STUDENT: + message_queue = CONSTANTS.QUEUE.REDIS_SERVER_STUDENT; + break; + case CONSTANTS.NAME_SERVER.ADMIN: + message_queue = CONSTANTS.QUEUE.REDIS_SERVER_ADMIN; + break; + case CONSTANTS.NAME_SERVER.CRON: + message_queue = CONSTANTS.QUEUE.REDIS_SERVER_CRON; + break; + case CONSTANTS.NAME_SERVER.DB: + message_queue = CONSTANTS.QUEUE.REDIS_DB; + break; + default: + message_queue = CONSTANTS.QUEUE.REDIS_SERVER_CRON; + break; } // Publish data queue Redis return queueMessageTelegram(message_queue, { 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 c62e27d..86872bd 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 @@ -276,16 +276,16 @@ const userController = { // Check input register if ( - !mssv || - !password || - !HELPER.isNumeric(mssv) || - !name || - !phone_number || - !email || - !dob || - !address || - !gender || - !class_room + !mssv + || !password + || !HELPER.isNumeric(mssv) + || !name + || !phone_number + || !email + || !dob + || !address + || !gender + || !class_room ) { return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({ status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST,