From 5135a2edc7570208a18339d50e74af09fcd05349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ti=E1=BA=BFn=20T=C3=A0i?= <63393170+fdhhhdjd@users.noreply.github.com> Date: Tue, 14 Mar 2023 18:00:13 +0700 Subject: [PATCH] #180 hotfix book tai dev 20230314 --- .../admin.controllers/admin.controller.js | 16 +-- .../author.controllers/author.controller.js | 8 +- .../book.controllers/book.controller.js | 12 +- .../borrow_book.controller.js | 4 +- .../src/share/middleware/handle_error.js | 3 +- .../src/share/models/author.model.js | 35 ++--- .../src/share/models/book.model.js | 35 ++--- .../src/share/models/book_borrowed.model.js | 134 +++++++++--------- .../src/share/models/categories.model.js | 42 +++--- .../src/share/models/phone.model.js | 35 ++--- .../src/share/models/user.model.js | 42 +++--- .../src/share/models/user_device.model.js | 69 ++++----- .../share/models/user_reset_password.model.js | 65 +++++---- .../share/models/user_verification.model.js | 69 ++++----- .../src/share/utils/helper.js | 3 +- .../src/share/utils/limited_redis.js | 23 +-- .../src/share/utils/redis_cluster_helper.js | 19 +-- .../borrow_book.controller.js | 18 +-- .../user.controllers/user.controller.js | 12 +- .../src/user_api/v1/routes/index.router.js | 9 +- 20 files changed, 336 insertions(+), 317 deletions(-) diff --git a/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js b/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js index f01cb2a..c7d56a3 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/admin.controllers/admin.controller.js @@ -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, }); @@ -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, }); @@ -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, }); } diff --git a/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js b/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js index e301e16..fab4069 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/author.controllers/author.controller.js @@ -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) { @@ -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 (!author_id) { diff --git a/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js b/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js index d3ce725..e8779a3 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/book.controllers/book.controller.js @@ -23,10 +23,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 ( @@ -355,7 +353,11 @@ const bookController = { if (result_book_detail) { const redisTTLWithRandom = RANDOMS.getRedisTTLWithRandom(CONSTANTS._1_MONTH); // Add data redis - book_admin_service.handleSetCacheRedis(CONSTANTS.KEY_REDIS.ALL_BOOK, result_book_detail, redisTTLWithRandom); + book_admin_service.handleSetCacheRedis( + CONSTANTS.KEY_REDIS.ALL_BOOK, + result_book_detail, + redisTTLWithRandom, + ); return res.status(200).json({ status: 200, diff --git a/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js b/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js index 10b9597..b200150 100644 --- a/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js +++ b/backend-manager-student/src/admin_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js @@ -21,9 +21,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) { diff --git a/backend-manager-student/src/share/middleware/handle_error.js b/backend-manager-student/src/share/middleware/handle_error.js index 13e03e3..b2ff6c3 100644 --- a/backend-manager-student/src/share/middleware/handle_error.js +++ b/backend-manager-student/src/share/middleware/handle_error.js @@ -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'), }; diff --git a/backend-manager-student/src/share/models/author.model.js b/backend-manager-student/src/share/models/author.model.js index eae7424..776a75c 100644 --- a/backend-manager-student/src/share/models/author.model.js +++ b/backend-manager-student/src/share/models/author.model.js @@ -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 @@ -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 diff --git a/backend-manager-student/src/share/models/book.model.js b/backend-manager-student/src/share/models/book.model.js index a404835..776e383 100644 --- a/backend-manager-student/src/share/models/book.model.js +++ b/backend-manager-student/src/share/models/book.model.js @@ -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 @@ -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 diff --git a/backend-manager-student/src/share/models/book_borrowed.model.js b/backend-manager-student/src/share/models/book_borrowed.model.js index 6c54ad7..ceb06e7 100644 --- a/backend-manager-student/src/share/models/book_borrowed.model.js +++ b/backend-manager-student/src/share/models/book_borrowed.model.js @@ -10,18 +10,19 @@ module.exports = { * @created_at 07/03/2023 * @description create BorrowBook */ - createBorrowBook: (data) => new Promise((resolve, reject) => { - try { - const result = knex('borrowed_book') - .insert(data) - .onConflict('borrowed_book_id') - .merge() - .returning(['borrowed_book_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + createBorrowBook: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('borrowed_book') + .insert(data) + .onConflict('borrowed_book_id') + .merge() + .returning(['borrowed_book_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài @@ -37,14 +38,15 @@ module.exports = { * @created_at 07/03/2023 * @description Update BorrowBook */ - updateBorrowBook: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('borrowed_book').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateBorrowBook: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('borrowed_book').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 07/03/2023 @@ -77,60 +79,62 @@ module.exports = { * @created_at 07/03/2023 * @description Transaction Update Borrow Book */ - transactionUpdateBorrowBook: async (data_update_book, data_update_borrow) => new Promise(async (resolve, reject) => { - // start transaction - const trx = await knex.transaction(); - try { - // Query 1: createBorrowBook - const borrowBookId = await trx('borrowed_book') - .update({ status: data_update_borrow.status }) - .where({ book_id: data_update_borrow.book_id, user_id: data_update_borrow.user_id }) - .returning(['borrowed_book_id']); + transactionUpdateBorrowBook: async (data_update_book, data_update_borrow) => + new Promise(async (resolve, reject) => { + // start transaction + const trx = await knex.transaction(); + try { + // Query 1: createBorrowBook + const borrowBookId = await trx('borrowed_book') + .update({ status: data_update_borrow.status }) + .where({ book_id: data_update_borrow.book_id, user_id: data_update_borrow.user_id }) + .returning(['borrowed_book_id']); - // Query 2: updateBorrowBook - const updatedData = await trx('books') - .update({ quantity: data_update_book.quantity }) - .where({ book_id: data_update_book.book_id }) - .returning(['book_id']); + // Query 2: updateBorrowBook + const updatedData = await trx('books') + .update({ quantity: data_update_book.quantity }) + .where({ book_id: data_update_book.book_id }) + .returning(['book_id']); - // Commit transaction - await trx.commit(); - return resolve(borrowBookId, updatedData); - } catch (error) { - trx.rollback(); - reject(error); - } - }), + // Commit transaction + await trx.commit(); + return resolve(borrowBookId, updatedData); + } catch (error) { + trx.rollback(); + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 08/03/2023 * @description Transaction Borrow Book */ - transactionBorrowBook: async (data_insert, data_update) => new Promise(async (resolve, reject) => { - // start transaction - const trx = await knex.transaction(); - try { - // Query 1: createBorrowBook - const borrowBookId = await trx('borrowed_book') - .insert(data_insert) - .onConflict('borrowed_book_id') - .merge() - .returning(['borrowed_book_id']); + transactionBorrowBook: async (data_insert, data_update) => + new Promise(async (resolve, reject) => { + // start transaction + const trx = await knex.transaction(); + try { + // Query 1: createBorrowBook + const borrowBookId = await trx('borrowed_book') + .insert(data_insert) + .onConflict('borrowed_book_id') + .merge() + .returning(['borrowed_book_id']); - // Query 2: updateBorrowBook - const updatedData = await trx('books') - .update(data_update) - .where({ book_id: data_insert.book_id }) - .returning(['book_id']); + // Query 2: updateBorrowBook + const updatedData = await trx('books') + .update(data_update) + .where({ book_id: data_insert.book_id }) + .returning(['book_id']); - // Commit transaction - await trx.commit(); - return resolve(borrowBookId, updatedData); - } catch (error) { - trx.rollback(); - reject(error); - } - }), + // Commit transaction + await trx.commit(); + return resolve(borrowBookId, updatedData); + } catch (error) { + trx.rollback(); + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 09/03/2023 diff --git a/backend-manager-student/src/share/models/categories.model.js b/backend-manager-student/src/share/models/categories.model.js index 29ce4ac..8a1ceb8 100644 --- a/backend-manager-student/src/share/models/categories.model.js +++ b/backend-manager-student/src/share/models/categories.model.js @@ -7,18 +7,19 @@ module.exports = { * @created_at 03/02/2023 * @description create Categories */ - createCategories: (data) => new Promise((resolve, reject) => { - try { - const result = knex('categories') - .insert(data) - .onConflict('category_id') - .merge() - .returning(['category_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + createCategories: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('categories') + .insert(data) + .onConflict('category_id') + .merge() + .returning(['category_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài @@ -34,14 +35,15 @@ module.exports = { * @created_at 03/02/2023 * @description Update Categories */ - updateCategories: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('categories').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateCategories: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('categories').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 03/02/2023 diff --git a/backend-manager-student/src/share/models/phone.model.js b/backend-manager-student/src/share/models/phone.model.js index 786d3e2..c46c101 100644 --- a/backend-manager-student/src/share/models/phone.model.js +++ b/backend-manager-student/src/share/models/phone.model.js @@ -7,15 +7,15 @@ module.exports = { * @created_at 09/03/2023 * @description create Phone */ - createPhone: (data) => new Promise((resolve, reject) => { - try { - const result = knex('phone').insert(data).onConflict('phone_id').merge() - .returning(['phone_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + createPhone: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('phone').insert(data).onConflict('phone_id').merge().returning(['phone_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @Phone Nguyễn Tiến Tài @@ -31,12 +31,13 @@ module.exports = { * @created_at 09/03/2023 * @description Update Phone */ - updatePhone: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('phone').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updatePhone: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('phone').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), }; diff --git a/backend-manager-student/src/share/models/user.model.js b/backend-manager-student/src/share/models/user.model.js index db27053..8217b5e 100644 --- a/backend-manager-student/src/share/models/user.model.js +++ b/backend-manager-student/src/share/models/user.model.js @@ -11,18 +11,19 @@ module.exports = { * @update_at 23/01/2022 * @description Add user */ - addUser: (data) => new Promise((resolve, reject) => { - try { - const result = knex('user') - .insert(data) - .onConflict('user_id', 'email', 'phone_number', 'mssv') - .merge() - .returning(['user_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + addUser: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('user') + .insert(data) + .onConflict('user_id', 'email', 'phone_number', 'mssv') + .merge() + .returning(['user_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài @@ -38,14 +39,15 @@ module.exports = { * @created_at 13/02/2023 * @description Update student */ - updateStudent: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('user').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateStudent: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('user').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 28/02/2023 diff --git a/backend-manager-student/src/share/models/user_device.model.js b/backend-manager-student/src/share/models/user_device.model.js index 8b304b0..1323935 100644 --- a/backend-manager-student/src/share/models/user_device.model.js +++ b/backend-manager-student/src/share/models/user_device.model.js @@ -10,49 +10,52 @@ module.exports = { * @created_at 03/02/2023 * @description insertDevice */ - insertDevice: (data) => new Promise((resolve, reject) => { - try { - const result = knex('user_device') - .insert(data) - .onConflict('device_uuid') - .merge() - .returning(['device_uuid']); - resolve(result); - } catch (error) { - reject(error); - } - }), + insertDevice: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('user_device') + .insert(data) + .onConflict('device_uuid') + .merge() + .returning(['device_uuid']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 03/02/2023 * @description insertDevice */ - checkUserByToken: (refresh_token, device_uuid) => new Promise((resolve, reject) => { - try { - let user = knex('user_device') - .join('user', 'user.user_id', 'user_device.user_id') - .where('user.isdeleted', '=', CONSTANTS.DELETED_DISABLE) - .andWhere('user_device.refresh_token', refresh_token) - .andWhere('user_device.device_uuid', device_uuid) - .select('user.user_id', 'user.role', 'user.name', 'user.email', 'user.role'); - resolve(user); - } catch (error) { - reject(error); - } - }), + checkUserByToken: (refresh_token, device_uuid) => + new Promise((resolve, reject) => { + try { + let user = knex('user_device') + .join('user', 'user.user_id', 'user_device.user_id') + .where('user.isdeleted', '=', CONSTANTS.DELETED_DISABLE) + .andWhere('user_device.refresh_token', refresh_token) + .andWhere('user_device.device_uuid', device_uuid) + .select('user.user_id', 'user.role', 'user.name', 'user.email', 'user.role'); + resolve(user); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 05/02/2023 * @description updateDevice */ - updateDevice: (data, user) => new Promise((resolve, reject) => { - try { - const result = knex('user_device').where('user_id', user).update(data).returning(['device_uuid']); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateDevice: (data, user) => + new Promise((resolve, reject) => { + try { + const result = knex('user_device').where('user_id', user).update(data).returning(['device_uuid']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 15/02/2023 diff --git a/backend-manager-student/src/share/models/user_reset_password.model.js b/backend-manager-student/src/share/models/user_reset_password.model.js index 5e80afb..98f7647 100644 --- a/backend-manager-student/src/share/models/user_reset_password.model.js +++ b/backend-manager-student/src/share/models/user_reset_password.model.js @@ -10,18 +10,19 @@ module.exports = { * @created_at 23/02/2023 * @description Insert reset password student */ - insertResetPassword: (data) => new Promise((resolve, reject) => { - try { - const result = knex('reset_password') - .insert(data) - .onConflict('id') - .merge() - .returning(['id', 'user_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + insertResetPassword: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('reset_password') + .insert(data) + .onConflict('id') + .merge() + .returning(['id', 'user_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 24/02/2023 @@ -36,29 +37,31 @@ module.exports = { * @created_at 24/02/2023 * @description Update reset Password */ - updateResetPassword: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('reset_password').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateResetPassword: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('reset_password').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 28/02/2023 * @description List all reset password */ - getResetPasswordList: async () => new Promise((resolve, reject) => { - knex('reset_password') - .where('isdeleted', CONSTANTS.DELETED_DISABLE) - .orderBy('created_at', 'asc') - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }), + getResetPasswordList: async () => + new Promise((resolve, reject) => { + knex('reset_password') + .where('isdeleted', CONSTANTS.DELETED_DISABLE) + .orderBy('created_at', 'asc') + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }), }; diff --git a/backend-manager-student/src/share/models/user_verification.model.js b/backend-manager-student/src/share/models/user_verification.model.js index e59edc4..aadf783 100644 --- a/backend-manager-student/src/share/models/user_verification.model.js +++ b/backend-manager-student/src/share/models/user_verification.model.js @@ -10,18 +10,19 @@ module.exports = { * @created_at 25/02/2023 * @description Insert reset verification student */ - insertVerificationEmail: (data) => new Promise((resolve, reject) => { - try { - const result = knex('verification') - .insert(data) - .onConflict('verify_id') - .merge() - .returning(['verify_id']); - resolve(result); - } catch (error) { - reject(error); - } - }), + insertVerificationEmail: (data) => + new Promise((resolve, reject) => { + try { + const result = knex('verification') + .insert(data) + .onConflict('verify_id') + .merge() + .returning(['verify_id']); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài @@ -37,30 +38,32 @@ module.exports = { * @created_at 26/02/2023 * @description Update verification */ - updateVerification: async (data, student_query, return_data) => new Promise((resolve, reject) => { - try { - const result = knex('verification').update(data).where(student_query).returning(return_data); - resolve(result); - } catch (error) { - reject(error); - } - }), + updateVerification: async (data, student_query, return_data) => + new Promise((resolve, reject) => { + try { + const result = knex('verification').update(data).where(student_query).returning(return_data); + resolve(result); + } catch (error) { + reject(error); + } + }), /** * @author Nguyễn Tiến Tài * @created_at 26/02/2023 * @description Update verification */ - getVerificationList: async () => new Promise((resolve, reject) => { - knex('verification') - .where('isdeleted', CONSTANTS.DELETED_DISABLE) - .where('verified', CONSTANTS.DELETED_DISABLE) - .where('check_login', CONSTANTS.DELETED_DISABLE) - .orderBy('created_at', 'asc') - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }), + getVerificationList: async () => + new Promise((resolve, reject) => { + knex('verification') + .where('isdeleted', CONSTANTS.DELETED_DISABLE) + .where('verified', CONSTANTS.DELETED_DISABLE) + .where('check_login', CONSTANTS.DELETED_DISABLE) + .orderBy('created_at', 'asc') + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }), }; diff --git a/backend-manager-student/src/share/utils/helper.js b/backend-manager-student/src/share/utils/helper.js index c70a261..0dfa175 100644 --- a/backend-manager-student/src/share/utils/helper.js +++ b/backend-manager-student/src/share/utils/helper.js @@ -159,7 +159,8 @@ module.exports = { * @description Mobile network * @returns {String} */ - returnMobileNetWork: (code) => CONSTANTS.mobileCodeProNewMap().get(code) || CONSTANTS.mobileCodeProNewMap().get('default'), + returnMobileNetWork: (code) => + CONSTANTS.mobileCodeProNewMap().get(code) || CONSTANTS.mobileCodeProNewMap().get('default'), /** * @author Nguyễn Tiến Tài * @created_at 20/01/2023 diff --git a/backend-manager-student/src/share/utils/limited_redis.js b/backend-manager-student/src/share/utils/limited_redis.js index 8c2072f..f1d7978 100644 --- a/backend-manager-student/src/share/utils/limited_redis.js +++ b/backend-manager-student/src/share/utils/limited_redis.js @@ -39,17 +39,18 @@ const getRangeCache = (key, start, end) => REDIS_MASTER.lrange(key, start, end); * @description Set multi * @returns {Array} */ -const setBlackListCache = (key, user_id, accept_token, refresh_token, ttl) => REDIS_MASTER.multi() - .lpush(key, accept_token, refresh_token) - .del(user_id) - .expire(key, ttl) - .exec((err, replies) => { - if (err) { - console.error(err); - } else { - console.info(replies); - } - }); +const setBlackListCache = (key, user_id, accept_token, refresh_token, ttl) => + REDIS_MASTER.multi() + .lpush(key, accept_token, refresh_token) + .del(user_id) + .expire(key, ttl) + .exec((err, replies) => { + if (err) { + console.error(err); + } else { + console.info(replies); + } + }); /** * @author Nguyễn Tiến Tài * @param {key} diff --git a/backend-manager-student/src/share/utils/redis_cluster_helper.js b/backend-manager-student/src/share/utils/redis_cluster_helper.js index 4e278f2..fbb19a3 100644 --- a/backend-manager-student/src/share/utils/redis_cluster_helper.js +++ b/backend-manager-student/src/share/utils/redis_cluster_helper.js @@ -7,16 +7,17 @@ const { REDIS_MASTER, REDIS_SLAVE } = require('../db/init_multiple_redis'); * @param {REDIS_MASTER OR REDIS_SLAVE,String} * @return {resolve or reject} */ -const getDataWithTimeout = async (redisClient, key) => await new Promise((resolve, reject) => { - redisClient.get(key, (error, result) => { - if (error) { - reject(error); - } else { - resolve(result); - } +const getDataWithTimeout = async (redisClient, key) => + await new Promise((resolve, reject) => { + redisClient.get(key, (error, result) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }); + setTimeout(() => reject(new Error('Timeout')), 3000); }); - setTimeout(() => reject(new Error('Timeout')), 3000); -}); /** * @author Nguyễn Tiến Tài diff --git a/backend-manager-student/src/user_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js b/backend-manager-student/src/user_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js index 9779768..fd02ff5 100644 --- a/backend-manager-student/src/user_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js +++ b/backend-manager-student/src/user_api/v1/controllers/borrow_book.controllers/borrow_book.controller.js @@ -58,15 +58,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 = 'Book already borrow !!'; - break; - case CONSTANTS.STATUS_BORROW.BORROWING: - result_borrow = 'Please return the book !!'; - break; - default: - result_borrow = 'Fail'; - break; + case CONSTANTS.STATUS_BORROW.PENDING: + result_borrow = 'Book already borrow !!'; + break; + case CONSTANTS.STATUS_BORROW.BORROWING: + result_borrow = 'Please return the book !!'; + break; + default: + result_borrow = 'Fail'; + break; } return res.status(400).json({ status: 400, diff --git a/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js b/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js index 6e78c7a..1c6f993 100644 --- a/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js +++ b/backend-manager-student/src/user_api/v1/controllers/user.controllers/user.controller.js @@ -180,8 +180,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, }); @@ -420,8 +420,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, }); @@ -1477,9 +1477,7 @@ const userController = { const { id } = req.auth_user; // Input body - const { - name, avatar_uri, public_id_avatar, address, dob, gender, - } = req.body.input.user_update_profile_input; + const { name, avatar_uri, public_id_avatar, address, dob, gender } = req.body.input.user_update_profile_input; // Check user_id if (!id) { diff --git a/backend-manager-student/src/user_api/v1/routes/index.router.js b/backend-manager-student/src/user_api/v1/routes/index.router.js index be4c8d9..567f4fd 100644 --- a/backend-manager-student/src/user_api/v1/routes/index.router.js +++ b/backend-manager-student/src/user_api/v1/routes/index.router.js @@ -25,10 +25,11 @@ router.use('/api/v1/user/private', rate_limit_middleware, accessStudentMiddlewar */ router.use('/api/v1/user', rate_limit_middleware, router_general); -router.get('/check-status', (req, res) => res.status(200).json({ - status: 'success', - message: 'OK', -}), +router.get('/check-status', (req, res) => + res.status(200).json({ + status: 'success', + message: 'OK', + }), ); module.exports = router;