diff options
Diffstat (limited to 'packages/trpc/models/lists.ts')
| -rw-r--r-- | packages/trpc/models/lists.ts | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/packages/trpc/models/lists.ts b/packages/trpc/models/lists.ts index 2631ca7e..39d78ac1 100644 --- a/packages/trpc/models/lists.ts +++ b/packages/trpc/models/lists.ts @@ -63,15 +63,10 @@ export abstract class List implements PrivacyAware { } } - static async getPublicListContents( + private static async getPublicList( ctx: Context, listId: string, token: string | null, - pagination: { - limit: number; - order: Exclude<ZSortOrder, "relevance">; - cursor: ZCursor | null | undefined; - }, ) { const listdb = await ctx.db.query.bookmarkLists.findFirst({ where: and( @@ -81,6 +76,13 @@ export abstract class List implements PrivacyAware { token !== null ? eq(bookmarkLists.rssToken, token) : undefined, ), ), + with: { + user: { + columns: { + name: true, + }, + }, + }, }); if (!listdb) { throw new TRPCError({ @@ -88,6 +90,35 @@ export abstract class List implements PrivacyAware { message: "List not found", }); } + return listdb; + } + + static async getPublicListMetadata( + ctx: Context, + listId: string, + token: string | null, + ) { + const listdb = await this.getPublicList(ctx, listId, token); + return { + userId: listdb.userId, + name: listdb.name, + description: listdb.description, + icon: listdb.icon, + ownerName: listdb.user.name, + }; + } + + static async getPublicListContents( + ctx: Context, + listId: string, + token: string | null, + pagination: { + limit: number; + order: Exclude<ZSortOrder, "relevance">; + cursor: ZCursor | null | undefined; + }, + ) { + const listdb = await this.getPublicList(ctx, listId, token); // The token here acts as an authed context, so we can create // an impersonating context for the list owner as long as @@ -109,6 +140,7 @@ export abstract class List implements PrivacyAware { icon: list.list.icon, name: list.list.name, description: list.list.description, + ownerName: listdb.user.name, numItems: bookmarkIds.length, }, bookmarks: bookmarks.bookmarks.map((b) => b.asPublicBookmark()), |
