-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#259 [Backend] change spec borrow_book and book
- Loading branch information
Showing
6 changed files
with
168 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
backend-manager-student/src/share/services/admin_service/book_categories.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! SHARE | ||
const RANDOMS = require('../../utils/random'); | ||
const CONSTANTS = require('../../configs/constants'); | ||
|
||
//! MODEL | ||
const book_category_model = require('../../models/book_categories.model'); | ||
|
||
module.exports = { | ||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 17/04/2023 | ||
* @description handle save book categories | ||
* @function handleSetCacheRedis | ||
*/ | ||
handleSaveMultiBookCategories: async (book_id, book_categories_array_parse, book_categories) => { | ||
try { | ||
// Init data filter | ||
let data_filter; | ||
|
||
// if book_categories deference empty | ||
if (book_categories) { | ||
data_filter = book_categories_array_parse.filter( | ||
(item) => !book_categories.some((existingItem) => existingItem.category_id === item.category_id), | ||
); | ||
} else { | ||
// if book_categories null | ||
// eslint-disable-next-line no-unused-vars | ||
data_filter = book_categories_array_parse; | ||
} | ||
// data_filter equal array empty | ||
if (Array.isArray(data_filter) && data_filter.length === CONSTANTS.ARRAY.EMPTY) { | ||
return false; | ||
} else { | ||
// Take data in array save database | ||
for (const data of data_filter) { | ||
// create Category database | ||
book_category_model.createBookCategories({ | ||
book_categories_id: RANDOMS.createID(), | ||
book_id, | ||
category_id: data.category_id, | ||
}); | ||
} | ||
// Save database success | ||
return false; | ||
} | ||
} catch (error) { | ||
// Save database error | ||
return true; | ||
} | ||
}, | ||
}; |