Skip to content

Commit

Permalink
Merge pull request #183 from fdhhhdjd/developer
Browse files Browse the repository at this point in the history
#180 [Backend] Feature Borrow Book
  • Loading branch information
fdhhhdjd authored Mar 9, 2023
2 parents 6a653dd + e13aacc commit 08b8002
Show file tree
Hide file tree
Showing 19 changed files with 343 additions and 325 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ const adminController = {
sameSite: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? true : false,
secure: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? true : false,
domain:
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ?
req.headers[CONSTANTS.HEADER_HEADER_FORWARDED_HOST]?.split(':')[0]
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT
? req.headers[CONSTANTS.HEADER_HEADER_FORWARDED_HOST]?.split(':')[0]
: CONSTANTS.HEADER_DOMAIN,
maxAge: CONSTANTS._1_MONTH,
});
Expand Down Expand Up @@ -261,8 +261,8 @@ const adminController = {
sameSite: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? true : false,
secure: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? true : false,
domain:
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ?
req.headers[CONSTANTS.HEADER_HEADER_FORWARDED_HOST]?.split(':')[0]
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT
? req.headers[CONSTANTS.HEADER_HEADER_FORWARDED_HOST]?.split(':')[0]
: CONSTANTS.HEADER_DOMAIN,
maxAge: CONSTANTS._1_MONTH,
});
Expand Down Expand Up @@ -432,12 +432,12 @@ const adminController = {
class: student.class,
email: student.email,
gender:
student.gender.toLowerCase() === CONSTANTS.GENDER_MALE_STRING ?
CONSTANTS.GENDER_MALE
student.gender.toLowerCase() === CONSTANTS.GENDER_MALE_STRING
? CONSTANTS.GENDER_MALE
: CONSTANTS.GENDER_FEMALE,
avatar_uri:
student.gender.toLowerCase() === CONSTANTS.GENDER_MALE_STRING ?
CONSTANTS.GENDER_IMAGE_MALE
student.gender.toLowerCase() === CONSTANTS.GENDER_MALE_STRING
? CONSTANTS.GENDER_IMAGE_MALE
: CONSTANTS.GENDER_IMAGE_FEMALE,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const authorController = {
* @return {Object:{Number,String}
*/
createAuthor: async (req, res) => {
const {
name, avatar_uri, dob, gender,
} = req.body.input.author_input;
const { name, avatar_uri, dob, gender } = req.body.input.author_input;

// Check input
if (!name || !avatar_uri || !dob || !gender) {
Expand Down Expand Up @@ -74,9 +72,7 @@ const authorController = {
* @return {Object:{Number,String}
*/
updateAuthor: async (req, res) => {
const {
author_id, name, avatar_uri, dob, gender,
} = req.body.input.author_input;
const { author_id, name, avatar_uri, dob, gender } = req.body.input.author_input;

// Check input
if (!name || !avatar_uri || !dob || !gender || !author_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ const bookController = {
* @return {Object:{Number,String}
*/
createBook: async (req, res) => {
const {
name, author_id, image_uri, description, bookshelf, language, quantity, public_id_image,
}
= req.body.input.author_input;
const { name, author_id, image_uri, description, bookshelf, language, quantity, public_id_image } =
req.body.input.author_input;

// Check input
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,10 @@ 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
) {
if (!book_id || !user_id || !start_date || !due_date || !status) {
return res.status(400).json({
status: 400,
message: returnReasons('400'),
Expand Down Expand Up @@ -76,7 +64,11 @@ const BorrowBookController = {
if (status === CONSTANTS.STATUS_BORROW.BORROWING) {
// update book database
[err, result] = await HELPER.handleRequest(
borrow_book_model.updateBorrowBook(data_update, { book_id, user_id }, { borrowed_book_id: 'borrowed_book_id' }),
borrow_book_model.updateBorrowBook(
data_update,
{ book_id, user_id },
{ borrowed_book_id: 'borrowed_book_id' },
),
);
if (result) {
return res.status(200).json({
Expand Down Expand Up @@ -150,12 +142,12 @@ const BorrowBookController = {
}
},
/**
* @author Nguyễn Tiến Tài
* @created_at 09/03/2022
* @description Get All Borrowed Book
* @function borrowBook
* @return {Object:{Number,String}
*/
* @author Nguyễn Tiến Tài
* @created_at 09/03/2022
* @description Get All Borrowed Book
* @function borrowBook
* @return {Object:{Number,String}
*/
getAllBorrowBook: async (req, res) => {
try {
// Take data db
Expand All @@ -181,12 +173,12 @@ const BorrowBookController = {
}
},
/**
* @author Nguyễn Tiến Tài
* @created_at 09/03/2022
* @description Get All Borrowed Book
* @function borrowBook
* @return {Object:{Number,String}
*/
* @author Nguyễn Tiến Tài
* @created_at 09/03/2022
* @description Get All Borrowed Book
* @function borrowBook
* @return {Object:{Number,String}
*/
getDetailBorrowBook: async (req, res) => {
const borrowed_book_id = req.params.borrowed_book_id;

Expand Down
3 changes: 2 additions & 1 deletion backend-manager-student/src/share/middleware/handle_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
* @param { code }
* @return { String }
*/
returnReasons: (code) => CONSTANTS.reasonPhraseCodeProNewMap().get(code) || CONSTANTS.reasonPhraseCodeProNewMap().get('default'),
returnReasons: (code) =>
CONSTANTS.reasonPhraseCodeProNewMap().get(code) || CONSTANTS.reasonPhraseCodeProNewMap().get('default'),
};
35 changes: 18 additions & 17 deletions backend-manager-student/src/share/models/author.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
* @created_at 03/01/2023
* @description create Author
*/
createAuthor: (data) => new Promise((resolve, reject) => {
try {
const result = knex('authors').insert(data).onConflict('author_id').merge()
.returning(['author_id']);
resolve(result);
} catch (error) {
reject(error);
}
}),
createAuthor: (data) =>
new Promise((resolve, reject) => {
try {
const result = knex('authors').insert(data).onConflict('author_id').merge().returning(['author_id']);
resolve(result);
} catch (error) {
reject(error);
}
}),

/**
* @author Nguyễn Tiến Tài
Expand All @@ -31,14 +31,15 @@ module.exports = {
* @created_at 03/01/2023
* @description Update Author
*/
updateAuthor: async (data, student_query, return_data) => new Promise((resolve, reject) => {
try {
const result = knex('authors').update(data).where(student_query).returning(return_data);
resolve(result);
} catch (error) {
reject(error);
}
}),
updateAuthor: async (data, student_query, return_data) =>
new Promise((resolve, reject) => {
try {
const result = knex('authors').update(data).where(student_query).returning(return_data);
resolve(result);
} catch (error) {
reject(error);
}
}),
/**
* @author Nguyễn Tiến Tài
* @created_at 01/03/2023
Expand Down
35 changes: 18 additions & 17 deletions backend-manager-student/src/share/models/book.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
* @created_at 03/01/2023
* @description create book
*/
createBook: (data) => new Promise((resolve, reject) => {
try {
const result = knex('books').insert(data).onConflict('book_id').merge()
.returning(['book_id']);
resolve(result);
} catch (error) {
reject(error);
}
}),
createBook: (data) =>
new Promise((resolve, reject) => {
try {
const result = knex('books').insert(data).onConflict('book_id').merge().returning(['book_id']);
resolve(result);
} catch (error) {
reject(error);
}
}),

/**
* @author Nguyễn Tiến Tài
Expand All @@ -31,14 +31,15 @@ module.exports = {
* @created_at 03/01/2023
* @description Update book
*/
updateBook: async (data, student_query, return_data) => new Promise((resolve, reject) => {
try {
const result = knex('books').update(data).where(student_query).returning(return_data);
resolve(result);
} catch (error) {
reject(error);
}
}),
updateBook: async (data, student_query, return_data) =>
new Promise((resolve, reject) => {
try {
const result = knex('books').update(data).where(student_query).returning(return_data);
resolve(result);
} catch (error) {
reject(error);
}
}),
/**
* @author Nguyễn Tiến Tài
* @created_at 03/01/2023
Expand Down
Loading

0 comments on commit 08b8002

Please sign in to comment.