Created
April 28, 2022 16:46
-
-
Save semiarthanoian/12efeb5886b7c295039e614d33571f62 to your computer and use it in GitHub Desktop.
procedure/Article
This file contains hidden or 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
const readAllRecordIds = require("../sub-procedure/read-all-record-ids--async-throw"); | |
const selectArticleById = require("./select-by-id--async-throw"); | |
const Article = require("../../type/Article"); | |
module.exports = async ( | |
in_categoryId = "", | |
out_selected = [], | |
in_top = Infinity, | |
in_order = "default" /* default | reversed */ | |
) => { | |
/* --- Collect all records' ids */ | |
var allRecordIds = []; | |
await readAllRecordIds(Article.name, allRecordIds); | |
/* --- Order id-list */ | |
if (in_order == "default") | |
{ /* keep default order */; } | |
else | |
allRecordIds.reverse(); | |
/* --- Loop & Select each record to check */ | |
for (var recordId of allRecordIds) { | |
/* --- Limit the result set */ | |
if (out_selected.length == in_top) | |
break /* out of the loop */; | |
else | |
{ /* keep collecting record */; } | |
/* --- Select an Article */ | |
var record = new Article(); | |
await selectArticleById(recordId, record); | |
/* --- Collect the Article if category-id matches */ | |
if (record.get("category-id") != in_categoryId) | |
{ /* record is not matched */; } | |
else | |
out_selected.push(record); | |
} // for | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment