Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#180 [Backend] Feature Borrwed Book #181

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +17,9 @@ 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 @@ -72,7 +74,9 @@ 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,8 +19,10 @@ 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 @@ -64,28 +64,28 @@ const accessStudentMiddleware = async (req, res, next) => {
// Convert pem
const publicKey = PASSWORD.decodePemPubKey(data_device[0].public_key);

// Take info from token
let auth_user_decode = TOKENS.verifyAccessToken(accessToken, publicKey);

// Check is Student
if (auth_user_decode?.role !== 0) {
// Check time Expired token
let check_access_token = HELPER.isAccessTokenValid(accessToken, publicKey);
if (!check_access_token) {
return res.status(401).json({
status: 401,
message: returnReasons('401'),
element: {
result: 'You not is student!',
result: 'Expired Token',
},
});
}

// Check time Expired token
let check_access_token = HELPER.isAccessTokenValid(accessToken, publicKey);
if (!check_access_token) {
// Take info from token
let auth_user_decode = TOKENS.verifyAccessToken(accessToken, publicKey);

// Check is Student
if (auth_user_decode?.role !== 0) {
return res.status(401).json({
status: 401,
message: returnReasons('401'),
element: {
result: 'Expired Token',
result: 'You not is student!',
},
});
}
Expand Down
3 changes: 1 addition & 2 deletions backend-manager-student/src/share/middleware/handle_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ 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: 17 additions & 18 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,15 +31,14 @@ 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: 17 additions & 18 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,15 +31,14 @@ 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
42 changes: 20 additions & 22 deletions backend-manager-student/src/share/models/categories.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ 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
Expand All @@ -35,15 +34,14 @@ 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
Expand Down
42 changes: 20 additions & 22 deletions backend-manager-student/src/share/models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ 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
Expand All @@ -39,15 +38,14 @@ 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
Expand Down
Loading