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:
38
apps/api/src/modules/invitations/list-pending/use-case.ts
Normal file
38
apps/api/src/modules/invitations/list-pending/use-case.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Ok, type PendingInvitation, type ProblemDetails, type Result } from '@superlist/shared'
|
||||
|
||||
import type { Database } from '@/lib/prisma'
|
||||
|
||||
/** Lists the still-pending invitations addressed to the signed-in user's email. */
|
||||
export class ListPendingInvitations {
|
||||
constructor(
|
||||
private readonly db: Database,
|
||||
private readonly now: () => Date = () => new Date(),
|
||||
) {}
|
||||
|
||||
async execute(input: { email: string }): Promise<Result<PendingInvitation[], ProblemDetails>> {
|
||||
const invitations = await this.db.shoppingListInvitation.findMany({
|
||||
where: {
|
||||
email: input.email.trim().toLowerCase(),
|
||||
status: 'pending',
|
||||
expiresAt: { gt: this.now() },
|
||||
},
|
||||
include: {
|
||||
list: { select: { id: true, name: true } },
|
||||
invitedBy: { select: { id: true, name: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
|
||||
return Ok(
|
||||
invitations.map((invitation) => ({
|
||||
id: invitation.id,
|
||||
email: invitation.email,
|
||||
status: invitation.status,
|
||||
expiresAt: invitation.expiresAt.toISOString(),
|
||||
createdAt: invitation.createdAt.toISOString(),
|
||||
list: { id: invitation.list.id, name: invitation.list.name },
|
||||
invitedBy: { id: invitation.invitedBy.id, name: invitation.invitedBy.name },
|
||||
})),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user