mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 15:35:35 +00:00
refactor: compute favorite links in backend
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user