feat: add collaborative shopping lists with items and invitations
Some checks failed
CI / Verify (push) Has been cancelled
Some checks failed
CI / Verify (push) Has been cancelled
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).
This commit is contained in:
26
apps/api/src/modules/lists/get/route.ts
Normal file
26
apps/api/src/modules/lists/get/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Hono } from 'hono'
|
||||
|
||||
import { requireSession } from '@/lib/auth-session'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { resultJson } from '@/lib/result-json'
|
||||
import { validate } from '@/lib/validate'
|
||||
import type { AppEnv } from '@/types'
|
||||
|
||||
import { ListParamsSchema } from '../schema'
|
||||
import { GetShoppingList } from './use-case'
|
||||
|
||||
/** GET /lists/:listId — list detail with its members. */
|
||||
export const getListRoute = new Hono<AppEnv>().get(
|
||||
'/:listId',
|
||||
requireSession,
|
||||
validate.param(ListParamsSchema),
|
||||
async (c) => {
|
||||
const { listId } = c.req.valid('param')
|
||||
const result = await new GetShoppingList(prisma).execute({
|
||||
listId,
|
||||
userId: c.get('user').id,
|
||||
})
|
||||
|
||||
return resultJson(c, result)
|
||||
},
|
||||
)
|
||||
46
apps/api/src/modules/lists/get/use-case.ts
Normal file
46
apps/api/src/modules/lists/get/use-case.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user