fix(news): restore publication flow and deduplicate dashboard friends
This commit is contained in:
1 parent
ef94646d60
commit
9b0ea2fb16
22 files changed
+638
-195
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { and, eq, or, sql } from "drizzle-orm";
|
||||
import { apiJson } from "@/lib/api";
|
||||
import { db, WebsiteArticles } from "@/lib/db";
|
||||
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
|
||||
import { cacheNews } from "@/lib/services/news-cache";
|
||||
|
||||
/**
|
||||
* GET /api/articles/:slug — single website_article by slug, including the
|
||||
@@ -14,9 +16,9 @@ export async function GET(
|
||||
const { slug } = await params;
|
||||
|
||||
try {
|
||||
const data = await redisCache(
|
||||
const data = await cacheNews(
|
||||
apiCacheKey(`articles:${slug}`),
|
||||
60,
|
||||
60_000,
|
||||
async () => {
|
||||
const [article] = await db
|
||||
.select({
|
||||
@@ -55,7 +57,8 @@ export async function GET(
|
||||
}
|
||||
|
||||
return apiJson(data);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.error("Public news query failed", { module: "news", error });
|
||||
// DB unavailable — treat as not found rather than a 500.
|
||||
return apiJson({ error: "Article not found" }, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { and, count, desc, eq, or, sql } from "drizzle-orm";
|
||||
import { apiJson, pagination } from "@/lib/api";
|
||||
import { db, WebsiteArticles } from "@/lib/db";
|
||||
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
|
||||
import { cacheNews } from "@/lib/services/news-cache";
|
||||
|
||||
/**
|
||||
* GET /api/articles — paginated list of website_articles, newest first.
|
||||
@@ -13,9 +15,9 @@ export async function GET(req: Request) {
|
||||
const { page, perPage, skip, take } = pagination(sp);
|
||||
|
||||
try {
|
||||
const data = await redisCache(
|
||||
const data = await cacheNews(
|
||||
apiCacheKey(`articles:${page}:${perPage}`),
|
||||
60,
|
||||
60_000,
|
||||
async () => {
|
||||
const publishedFilter = and(
|
||||
eq(WebsiteArticles.status, "published"),
|
||||
@@ -60,7 +62,8 @@ export async function GET(req: Request) {
|
||||
);
|
||||
|
||||
return apiJson(data);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.error("Public news query failed", { module: "news", error });
|
||||
// DB unavailable — return an empty payload instead of a 500.
|
||||
return apiJson(
|
||||
{ data: [], meta: { page, perPage, total: 0, lastPage: 1 } },
|
||||
|
||||
@@ -3,7 +3,9 @@ import { env } from "@/env";
|
||||
import { apiJson } from "@/lib/api";
|
||||
import { db, User, WebsiteArticles } from "@/lib/db";
|
||||
import { resolveHotelName } from "@/lib/hotel-name";
|
||||
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
|
||||
import { cacheNews } from "@/lib/services/news-cache";
|
||||
|
||||
/**
|
||||
* GET /api/home — combined landing payload: the latest 4 website_articles and
|
||||
@@ -12,7 +14,7 @@ import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
|
||||
*/
|
||||
export async function GET(_req: Request) {
|
||||
try {
|
||||
const data = await redisCache(apiCacheKey("home"), 15, async () => {
|
||||
const data = await cacheNews(apiCacheKey("home"), 15_000, async () => {
|
||||
const [articles, onlineRows, hotelName] = await Promise.all([
|
||||
db
|
||||
.select({
|
||||
@@ -45,7 +47,8 @@ export async function GET(_req: Request) {
|
||||
});
|
||||
});
|
||||
return apiJson(data);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.error("Public news query failed", { module: "news", error });
|
||||
return apiJson(
|
||||
{ articles: [], online: 0, hotelName: env.HOTEL_NAME },
|
||||
{ status: 200 },
|
||||
|
||||
Reference in new issue
Block a user