mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
30 lines
934 B
TypeScript
30 lines
934 B
TypeScript
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
|
|
import newsManager from "~/server/internal/news";
|
|
|
|
export default defineClientEventHandler(async (h3) => {
|
|
const query = getQuery(h3);
|
|
|
|
const orderBy = query.order as "asc" | "desc";
|
|
if (orderBy) {
|
|
if (typeof orderBy !== "string" || !["asc", "desc"].includes(orderBy))
|
|
throw createError({ statusCode: 400, message: "Invalid order" });
|
|
}
|
|
|
|
const tags = query.tags as string[] | undefined;
|
|
if (tags) {
|
|
if (typeof tags !== "object" || !Array.isArray(tags))
|
|
throw createError({ statusCode: 400, message: "Invalid tags" });
|
|
}
|
|
|
|
const options = {
|
|
take: parseInt(query.limit as string),
|
|
skip: parseInt(query.skip as string),
|
|
orderBy: orderBy,
|
|
...(tags && { tags: tags.map((e) => e.toString()) }),
|
|
search: query.search as string,
|
|
};
|
|
|
|
const news = await newsManager.fetch(options);
|
|
return news;
|
|
});
|