API: seznam dnevnih receptov
This commit is contained in:
parent
b92c39d9f0
commit
3c429a3aa1
@ -1,6 +1,6 @@
|
||||
import { db } from "./db";
|
||||
import { dailyRecipes } from "@shared/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { eq, desc } from "drizzle-orm";
|
||||
|
||||
function todayStr(): string {
|
||||
const d = new Date();
|
||||
@ -37,3 +37,7 @@ export async function upsertRecipe(data: {
|
||||
const [row] = await db.insert(dailyRecipes).values(values).returning();
|
||||
return row;
|
||||
}
|
||||
|
||||
export async function listRecipes(limit = 200): Promise<any[]> {
|
||||
return await db.select().from(dailyRecipes).orderBy(desc(dailyRecipes.dateStr)).limit(limit);
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import { storage } from "./storage";
|
||||
import { insertArticleSchema } from "@shared/schema";
|
||||
import { seedDatabase } from "./seed";
|
||||
import { generateDailyHoroscopes, getHoroscopesForToday, getOrGenerateHoroscope, setHoroscopeImages } from "./horoscope-generator";
|
||||
import { getRecipeForToday, upsertRecipe } from "./daily-recipe";
|
||||
import { getRecipeForToday, upsertRecipe, listRecipes } from "./daily-recipe";
|
||||
import { startDailyScheduler } from "./scheduler";
|
||||
import { analyzeAllArticleImages, getCachedFocalPoints } from "./focal-point";
|
||||
import { optimizeImage } from "./image-optimizer";
|
||||
@ -755,6 +755,14 @@ export async function registerRoutes(
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/api/recipes", async (_req, res) => {
|
||||
try {
|
||||
res.json(await listRecipes());
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ message: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/api/recipes/today", async (_req, res) => {
|
||||
try {
|
||||
const recipe = await getRecipeForToday();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user