refactor: compute favorite links in backend

This commit is contained in:
Sonny
2025-08-19 23:44:48 +02:00
parent 81d02d3d80
commit 1d1e182523
2 changed files with 20 additions and 5 deletions

View File

@@ -50,6 +50,14 @@ export class LinkService {
.update({ favorite });
}
async getFavoriteLinksForAuthenticatedUser() {
const context = this.getAuthContext();
return await Link.query()
.where('author_id', context.auth.user!.id)
.where('favorite', true)
.orderBy('created_at');
}
getAuthContext() {
const context = HttpContext.getOrFail();
if (!context.auth.user || !context.auth.user.id) {