Skip to content

Commit

Permalink
#247 [Backend] Library Feedback 01/04/2023
Browse files Browse the repository at this point in the history
  • Loading branch information
fdhhhdjd committed Apr 6, 2023
1 parent 610a583 commit c3b6b70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const BorrowBookController = {
/**
* @author Nguyễn Tiến Tài
* @created_at 04/04/2023
* @updated_at 06/04/2022
* @description create BorrowBook
* @function updateBorrowBook
* @return {Object:{Number,String}}
Expand All @@ -36,7 +37,7 @@ const BorrowBookController = {
},
});
}
if (quantity > 2 || quantity === 0) {
if (quantity > CONSTANTS.LIMIT_BORROW || quantity === CONSTANTS.BORROW_ZERO) {
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),
Expand All @@ -61,7 +62,7 @@ const BorrowBookController = {
return acc;
}, 0);
const newTotalQuantity = Number(totalQuantity) + +quantity;
if (!checkLostProcessing(check_borrow_book) || newTotalQuantity > 2) {
if (!checkLostProcessing(check_borrow_book) || newTotalQuantity > CONSTANTS.LIMIT_BORROW) {
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),
Expand All @@ -71,7 +72,7 @@ const BorrowBookController = {
});
}
// Check count total
if (check_borrow_book.length >= 2) {
if (check_borrow_book.length >= CONSTANTS.LIMIT_BORROW) {
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),
Expand All @@ -87,9 +88,9 @@ const BorrowBookController = {
);
// Condition refund book
const check_refund_book =
data_borrow_book.length > 0
&& data_borrow_book[0].status !== CONSTANTS.STATUS_BORROW.DONE
&& data_borrow_book[0].status === CONSTANTS.STATUS_BORROW.BORROWING;
data_borrow_book.length > 0 &&
data_borrow_book[0].status !== CONSTANTS.STATUS_BORROW.DONE &&
data_borrow_book[0].status === CONSTANTS.STATUS_BORROW.BORROWING;
if (check_refund_book) {
return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({
status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST,
Expand Down Expand Up @@ -241,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(
Expand All @@ -268,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(
Expand Down
8 changes: 8 additions & 0 deletions backend-manager-student/src/share/configs/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ module.exports = {
LOST_BOOK_PROCESSING: 60, // Mất sách chưa được sử lý.
LOST_BOOK_PROCESSED: 70, // Mất sách đã được sử lý.
},
/**
* @author Nguyễn Tiến Tài
* @created_at 06/04/2023
* @description limit borrow book
* @param { Number }
*/
LIMIT_BORROW: 2,
BORROW_ZERO: 0,
/**
* @author Nguyễn Tiến Tài
* @created_at 06/04/2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const BorrowBookController = {
/**
* @author Nguyễn Tiến Tài
* @created_at 08/03/2022
* @updated_at 06/04/2022
* @description Borrowed Book
* @function borrowBook
* @return {Object}
Expand All @@ -38,7 +39,7 @@ const BorrowBookController = {
},
});
}
if (quantity > 2 || quantity === 0) {
if (quantity > CONSTANTS.LIMIT_BORROW || quantity === CONSTANTS.BORROW_ZERO) {
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),
Expand All @@ -63,7 +64,7 @@ const BorrowBookController = {
return acc;
}, 0);
const newTotalQuantity = Number(totalQuantity) + +quantity;
if (!checkLostProcessing(check_borrow_book) || newTotalQuantity > 2) {
if (!checkLostProcessing(check_borrow_book) || newTotalQuantity > CONSTANTS.LIMIT_BORROW) {
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),
Expand All @@ -73,7 +74,7 @@ const BorrowBookController = {
});
}
// Check count total
if (check_borrow_book.length >= 2) {
if (check_borrow_book.length >= CONSTANTS.LIMIT_BORROW) {
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),
Expand All @@ -88,9 +89,9 @@ const BorrowBookController = {
'*',
);
const refund_book =
data_borrow_book.length > 0
&& data_borrow_book[0].status !== CONSTANTS.STATUS_BORROW.DONE
&& data_borrow_book[0].status;
data_borrow_book.length > 0 &&
data_borrow_book[0].status !== CONSTANTS.STATUS_BORROW.DONE &&
data_borrow_book[0].status;
if (refund_book) {
return res.status(CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST).json({
status: CONSTANTS.HTTP.STATUS_4XX_BAD_REQUEST,
Expand Down

0 comments on commit c3b6b70

Please sign in to comment.