Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Nov 12, 2024
1 parent 8ebcf35 commit efd33d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions fake-snippets-api/lib/db/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,22 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
getTrendingSnippets: (limit: number, since: string): Snippet[] => {
const state = get()
const sinceDate = new Date(since).getTime()

// Get star counts within time period
const recentStars = new Map<string, number>()
state.accountSnippets.forEach((as) => {
if (as.has_starred && new Date(as.created_at).getTime() >= sinceDate) {
recentStars.set(
as.snippet_id,
(recentStars.get(as.snippet_id) || 0) + 1
as.snippet_id,
(recentStars.get(as.snippet_id) || 0) + 1,
)
}
})

return [...state.snippets]
.map((snippet) => ({
...snippet,
star_count: recentStars.get(snippet.snippet_id) || 0
star_count: recentStars.get(snippet.snippet_id) || 0,
}))
.sort((a, b) => b.star_count - a.star_count)
.slice(0, limit)
Expand Down
5 changes: 4 additions & 1 deletion fake-snippets-api/routes/api/snippets/list_trending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default withRouteSpec({
const sevenDaysAgo = new Date()
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7)

const trendingSnippets = ctx.db.getTrendingSnippets(20, sevenDaysAgo.toISOString())
const trendingSnippets = ctx.db.getTrendingSnippets(
20,
sevenDaysAgo.toISOString(),
)
return ctx.json({ snippets: trendingSnippets })
})
10 changes: 5 additions & 5 deletions fake-snippets-api/tests/routes/snippets/list_trending.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ test("list trending snippets", async () => {
owner_name: "User1",
code: "Content1",
created_at: "2023-01-01T00:00:00Z",
updated_at: "2023-01-01T00:00:00Z",
updated_at: "2023-01-01T00:00:00Z",
name: "User1/Snippet1",
snippet_type: "board",
},
{
unscoped_name: "Snippet2",
unscoped_name: "Snippet2",
owner_name: "User2",
code: "Content2",
created_at: "2023-01-02T00:00:00Z",
updated_at: "2023-01-02T00:00:00Z",
name: "User2/Snippet2",
name: "User2/Snippet2",
snippet_type: "package",
},
{
unscoped_name: "Snippet3",
owner_name: "User3",
owner_name: "User3",
code: "Content3",
created_at: "2023-01-03T00:00:00Z",
updated_at: "2023-01-03T00:00:00Z",
name: "User3/Snippet3",
snippet_type: "model",
}
},
]

for (const snippet of snippets) {
Expand Down

0 comments on commit efd33d3

Please sign in to comment.