Add: Post Count API

This commit is contained in:
Donatas Kirda 2024-05-17 09:04:21 +03:00
parent d8b25b59dc
commit 22c841396a
Signed by: bloodwiing
GPG Key ID: 63020D8D3F4A164F

View File

@ -47,6 +47,29 @@ function parsePostFromRow(author, category, row, withMetrics = false) {
};
}
/**
* @param {{
* category?: import('$types/base').Category | undefined
* }} opts
* @returns {Promise<number>}
*/
export async function getPostCount(opts = {}) {
const {
category = undefined
} = opts;
const filter = category ? sql`WHERE category_id = ${ category.id }` : sql``;
const query = sql`
SELECT COUNT(*)
FROM doki8902.message_post
${ filter };`;
const count = await query;
return count[0]['count'];
}
/**
* @param {{
* category?: import('$types/base').Category | undefined,