Files
superlist/apps/api/src/modules/lists/get/use-case.ts
Jose Selesan 6aa86a3b68
Some checks failed
CI / Verify (push) Has been cancelled
feat: add collaborative shopping lists with items and invitations
API: lists, items and invitations modules (list, create, get, update,
set-primary, items create/list, invitation create/accept/list-pending),
BetterAuth session helper, list membership, mailer and Prisma schema plus
migrations.

Web: lists overview, list detail (items) and list management (settings)
views, item and invitation forms/hooks, sign-up and invitation accept pages.

Shared: shopping list DTOs.

Tooling: ignore the generated TanStack Router cache (apps/web/.tanstack).
2026-10-16 10:12:11 -03:00

47 lines
1.1 KiB
TypeScript

import {
Failure,
Ok,
type ProblemDetails,
problems,
type Result,
type ShoppingListDetail,
} from '@superlist/shared'
import type { Database } from '@/lib/prisma'
import { toDetail } from '../serialize'
/** Returns a list with its members. Only members can read it. */
export class GetShoppingList {
constructor(private readonly db: Database) {}
async execute(input: {
listId: string
userId: string
}): Promise<Result<ShoppingListDetail, ProblemDetails>> {
const membership = await this.db.shoppingListMember.findUnique({
where: { listId_userId: { listId: input.listId, userId: input.userId } },
include: {
list: {
include: {
members: {
include: { user: true },
orderBy: [{ role: 'asc' }, { createdAt: 'asc' }],
},
invitations: {
where: { status: 'pending' },
orderBy: { createdAt: 'desc' },
},
},
},
},
})
if (!membership) {
return Failure(problems.notFound('La lista no existe o no tienes acceso.'))
}
return Ok(toDetail(membership))
}
}