feat: add collaborative shopping lists with items and invitations
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:
Jose Selesan
2026-10-16 10:12:11 -03:00
parent 964a3c7217
commit 6aa86a3b68
81 changed files with 3476 additions and 269 deletions

View File

@@ -0,0 +1,58 @@
import type { Database } from '@/lib/prisma'
/**
* Grants membership for every `pending`, non-expired invitation that matches the
* email and marks those invitations as accepted.
*
* Called right after a BetterAuth user is created, so people who are invited
* before signing up see the shared lists as soon as they register.
*
* @returns how many invitations were accepted
*/
export async function acceptPendingInvitations(
db: Database,
{ userId, email }: { userId: string; email: string },
): Promise<number> {
const pending = await db.shoppingListInvitation.findMany({
where: { email, status: 'pending', expiresAt: { gt: new Date() } },
})
for (const invitation of pending) {
await db.$transaction([
db.shoppingListMember.upsert({
where: { listId_userId: { listId: invitation.listId, userId } },
update: {},
create: { listId: invitation.listId, userId, role: 'collaborator' },
}),
db.shoppingListInvitation.update({
where: { id: invitation.id },
data: { status: 'accepted', acceptedAt: new Date() },
}),
])
}
return pending.length
}
/**
* Guarantees the user has at least one list: when they belong to none, creates a
* "Lista principal" owned by them and marks it as their primary list. Called
* right after a BetterAuth user is created (after pending invitations are
* accepted) so every account has a starting point.
*/
export async function ensurePrimaryList(
db: Database,
{ userId }: { userId: string },
): Promise<void> {
const memberships = await db.shoppingListMember.count({ where: { userId } })
if (memberships > 0) return
await db.shoppingList.create({
data: {
name: 'Lista principal',
ownerId: userId,
members: { create: { userId, role: 'owner', isPrimary: true } },
},
})
}