Skip to content

Commit

Permalink
#259 [Backend] change spec borrow_book and book
Browse files Browse the repository at this point in the history
  • Loading branch information
fdhhhdjd committed Apr 14, 2023
1 parent 662b512 commit fd0a6b8
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
28 changes: 14 additions & 14 deletions backend-manager-student/src/share/middleware/handle_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
},
Expand Down
3 changes: 1 addition & 2 deletions backend-manager-student/src/share/models/author.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions backend-manager-student/src/share/models/book.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions backend-manager-student/src/share/models/phone.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions backend-manager-student/src/share/models/rating.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions backend-manager-student/src/share/models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions backend-manager-student/src/share/utils/redis_pub_sub_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fd0a6b8

Please sign in to comment.