Skip to content

Commit

Permalink
fix #262 (#266)
Browse files Browse the repository at this point in the history
* fix: lock elysia-oauth2 version

* fix: #262 (#263)
  • Loading branch information
OXeu authored Oct 6, 2024
1 parent 404c4a9 commit 6cea860
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions server/src/services/tag.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { eq } from "drizzle-orm";
import { and, eq } from "drizzle-orm";
import Elysia from "elysia";
import type { DB } from "../_worker";
import { feedHashtags, hashtags } from "../db/schema";
import { getDB } from "../utils/di";
import { setup } from "../setup";

export function TagService() {
const db: DB = getDB();
return new Elysia({ aot: false })
.use(setup())
.group('/tag', (group) =>
group
.get('/', async () => {
Expand All @@ -24,15 +26,19 @@ export function TagService() {
}
})
})
.get('/:name', async ({ set, params: { name } }) => {
.get('/:name', async ({ admin, set, params: { name } }) => {
const nameDecoded = decodeURI(name)
const tag = await db.query.hashtags.findFirst({
where: eq(hashtags.name, nameDecoded),
with: {
feeds: {
with: {
feed: {
columns: { id: true, title: true, summary: true, content: true, createdAt: true, updatedAt: true },
columns: {
id: true, title: true, summary: true, content: true, createdAt: true, updatedAt: true,
draft: false,
listed: false
},
with: {
user: {
columns: { id: true, username: true, avatar: true }
Expand All @@ -45,18 +51,22 @@ export function TagService() {
}
}
}
}
}
},
where: (feeds: any) => admin ? undefined : and(eq(feeds.draft, 0), eq(feeds.listed, 1)),
} as any
}
}
}
});
const tagFeeds = tag?.feeds.map((tag) => {
const tagFeeds = tag?.feeds.map((tag: any) => {
if (!tag.feed) {
return null;
}
return {
...tag.feed,
hashtags: tag.feed.hashtags.map((tag) => tag.hashtag)
hashtags: tag.feed.hashtags.map((tag: any) => tag.hashtag)
}
})
}).filter((feed: any) => feed !== null);
if (!tag) {
set.status = 404;
return 'Not found';
Expand Down

0 comments on commit 6cea860

Please sign in to comment.