Skip to content

Commit

Permalink
fetch blogs using pinboard id
Browse files Browse the repository at this point in the history
  • Loading branch information
this-pama committed Dec 1, 2024
1 parent a2d9f7e commit d5ccd25
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions controllers/blog/api/get_articles.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
const { DB } = include("db/");

exports.get_articles = async (req, res) => {
const { id, url } = req.query;
const { id, url, pinboard } = req.query;

// Normalize `id` and `url` into arrays
let idList = id ? (Array.isArray(id) ? id : [id]).map(Number) : [];
let urlList = url ? (Array.isArray(url) ? url : [url]) : [];

if (pinboard && +pinboard) {
idList = await DB.general.any(
`
SELECT a.pad FROM pinboard_contributions a
JOIN pinboards b
ON a.pinboard = b.id
WHERE b.id = $1
AND a.db = 5
`,
[pinboard]
);

idList = idList.map((row) => row.pad);
}

// Ensure at least one of `id` or `url` is provided
if (
(!id || (Array.isArray(id) && id.length === 0)) &&
(!url || (Array.isArray(url) && url.length === 0))
(!url || (Array.isArray(url) && url.length === 0)) &&
idList.length === 0 &&
urlList.length === 0
) {
return res
.status(400)
.json({ error: "At least one 'id' or 'url' must be provided." });
}

// Normalize `id` and `url` into arrays
const idList = id ? (Array.isArray(id) ? id : [id]).map(Number) : [];
const urlList = url ? (Array.isArray(url) ? url : [url]) : [];

try {
const results = await DB.blog.any(
`
Expand Down

0 comments on commit d5ccd25

Please sign in to comment.