Styling basics
This commit is contained in:
@@ -31,7 +31,7 @@ const updateCategoryCache = cacheUpdater(cache);
|
||||
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {number[]} user_ids
|
||||
* @param {number[] | undefined} user_ids
|
||||
* @returns {Promise<Result<Category>>}
|
||||
*/
|
||||
export const getCategoriesCached = cachedMethod(cache, getCategories);
|
||||
@@ -40,16 +40,18 @@ export const getCategoriesCachedByRef = refExtendCachedMethod(getCategoriesCache
|
||||
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {number[]} category_ids
|
||||
* @param {number[] | undefined} category_ids
|
||||
* @returns {Promise<Result<Category>>}
|
||||
*/
|
||||
export async function getCategories(sql, category_ids) {
|
||||
if (category_ids.length == 0) return new Map();
|
||||
export async function getCategories(sql, category_ids = undefined) {
|
||||
if (category_ids !== undefined && category_ids.length == 0) return new Map();
|
||||
|
||||
const filter = category_ids ? sql`WHERE id IN ${ sql(category_ids) }` : sql``;
|
||||
|
||||
const query = sql`
|
||||
SELECT id, name
|
||||
FROM doki8902.post_category
|
||||
WHERE id IN ${ sql(category_ids) };`;
|
||||
${ filter };`;
|
||||
|
||||
let categories = await query;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user