Skip to content

Commit

Permalink
Merge pull request #223 from fdhhhdjd/developer
Browse files Browse the repository at this point in the history
#220 Performance code and clearn code
  • Loading branch information
fdhhhdjd authored Mar 23, 2023
2 parents 7fe9560 + 1a83cab commit 364d6a1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
8 changes: 6 additions & 2 deletions backend-manager-student/src/admin_api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ app.use(
session({
store: new RedisStore({ client: REDIS_MASTER }),
secret: CONFIGS.KEY_SESSION,
resave: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? CONSTANTS.DELETED_ENABLE : CONSTANTS.DELETED_DISABLE,
resave:
CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? CONSTANTS.DELETED_ENABLE : CONSTANTS.DELETED_DISABLE,
saveUninitialized: CONSTANTS.DELETED_ENABLE,
cookie: {
secure: CONFIGS.NODE_ENV === CONSTANTS.ENVIRONMENT_PRODUCT ? CONSTANTS.DELETED_ENABLE : CONSTANTS.DELETED_DISABLE,
secure:
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 Expand Up @@ -614,9 +614,7 @@ const adminController = {
const { id } = req.auth_user;

// Input body
const {
name, avatar_uri, public_id_avatar, address, dob, gender,
} = req.body.input.admin_update_profile_input;
const { name, avatar_uri, public_id_avatar, address, dob, gender } = req.body.input.admin_update_profile_input;

// Check id admin
if (!id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,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 @@ -79,9 +77,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 (!author_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,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 @@ -22,9 +22,7 @@ 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) {
Expand Down
1 change: 0 additions & 1 deletion backend-manager-student/src/share/configs/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = {
NOT_EXIT_ACCOUNT: 'Account admin not exit!',
},
GENERAL: {

// ? INVALID INPUT HEADER,..
INVALID_INPUT: 'Invalid input!',
INVALID_HEADER: 'Invalid Header!',
Expand Down
4 changes: 3 additions & 1 deletion backend-manager-student/src/share/middleware/handle_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ module.exports = {
* @param { code }
* @return { String }
*/
returnReasons: (code) => CONSTANTS.reasonPhraseCodeProNewMap().get(code.toString()) || CONSTANTS.reasonPhraseCodeProNewMap().get(CONSTANTS.HTTP.NO_STATUS_DEFAULT),
returnReasons: (code) =>
CONSTANTS.reasonPhraseCodeProNewMap().get(code.toString())
|| CONSTANTS.reasonPhraseCodeProNewMap().get(CONSTANTS.HTTP.NO_STATUS_DEFAULT),
};

0 comments on commit 364d6a1

Please sign in to comment.