Skip to content

Commit

Permalink
#238 [Backend] Hotfix Media and Server Student and CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
fdhhhdjd committed Mar 29, 2023
1 parent 12bf5fe commit 77ef47f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 47 deletions.
4 changes: 2 additions & 2 deletions backend-manager-student/src/admin_api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ app.use(
saveUninitialized: CONSTANTS.DELETED_ENABLE,
cookie: {
secure:
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ?
CONSTANTS.DELETED_ENABLE
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT
? CONSTANTS.DELETED_ENABLE
: CONSTANTS.DELETED_DISABLE,
httpOnly: CONSTANTS.DELETED_ENABLE,
maxAge: CONSTANTS._1_HOURS_S,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,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 @@ -270,8 +270,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 @@ -442,12 +442,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 @@ -25,8 +25,8 @@ const bookController = {
* @return {Object:{Number,String}}
*/
createBook: async (req, res) => {
const { name, author_id, image_uri, description, page_number, bookshelf, language, quantity, public_id_image }
= req.body.input.book_input;
const { name, author_id, image_uri, description, page_number, bookshelf, language, quantity, public_id_image } =
req.body.input.book_input;

// Check input
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ const StudentController = {
*/
updateStudent: async (req, res) => {
// Input body
const { student_id, name, avatar_uri, public_id_avatar, address, dob, gender }
= req.body.input.update_student_input;
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)) {
Expand Down
24 changes: 12 additions & 12 deletions backend-manager-student/src/share/middleware/handle_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/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
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ const BorrowBookController = {
if (data_borrow_book.length > 0 && data_borrow_book[0].status !== CONSTANTS.STATUS_BORROW.DONE) {
let result_borrow;
switch (data_borrow_book[0].status) {
case CONSTANTS.STATUS_BORROW.PENDING:
result_borrow = MESSAGES.GENERAL.ALREADY_BOOK_BORROW;
break;
case CONSTANTS.STATUS_BORROW.BORROWING:
result_borrow = MESSAGES.GENERAL.PLEASE_REFUND_BOOK;
break;
default:
result_borrow = MESSAGES.GENERAL.BORROW_FAIL;
break;
case CONSTANTS.STATUS_BORROW.PENDING:
result_borrow = MESSAGES.GENERAL.ALREADY_BOOK_BORROW;
break;
case CONSTANTS.STATUS_BORROW.BORROWING:
result_borrow = MESSAGES.GENERAL.PLEASE_REFUND_BOOK;
break;
default:
result_borrow = MESSAGES.GENERAL.BORROW_FAIL;
break;
}
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 @@ -184,8 +184,8 @@ const userController = {
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 @@ -422,8 +422,8 @@ const userController = {
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

0 comments on commit 77ef47f

Please sign in to comment.