Files
superlist/apps/api/src/modules/lists/create/use-case.ts
Jose Selesan b9c6ab92e3 feat(lists): pin lists with an icon and a live pending badge
Each member can pin up to four lists and pick an icon for them (per-user
settings on shopping_list_members, PATCH /api/lists/:listId/preferences).
Pinned lists stay visible with their pending count, kept live over each
list's SSE stream: a chip bar above the bottom nav on mobile and a "Fijadas"
group in the sidebar on desktop. GET /api/lists now returns pendingCount,
isPinned and icon.

The page padding, install prompt and dictation button now read
--bottom-nav-height, which grows with the pinned bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 09:24:13 -03:00

60 lines
1.5 KiB
TypeScript

import { Ok, type ProblemDetails, type Result, type ShoppingListSummary } from '@superlist/shared'
import type { Database } from '@/lib/prisma'
import { summaryCountInclude, toSummary } from '../serialize'
/** Creates a shopping list owned by the user. The first list becomes primary. */
export class CreateShoppingList {
constructor(private readonly db: Database) {}
async execute(input: {
name: string
userId: string
}): Promise<Result<ShoppingListSummary, ProblemDetails>> {
const existingCount = await this.db.shoppingListMember.count({
where: { userId: input.userId },
})
const list = await this.db.shoppingList.create({
data: {
name: input.name,
ownerId: input.userId,
members: {
create: {
userId: input.userId,
role: 'owner',
isPrimary: existingCount === 0,
},
},
},
include: {
...summaryCountInclude,
members: { where: { userId: input.userId } },
},
})
const membership = list.members[0]
if (!membership) {
throw new Error('Membership was not created for the new list')
}
return Ok(
toSummary({
role: membership.role,
isPrimary: membership.isPrimary,
isPinned: membership.isPinned,
icon: membership.icon,
list: {
id: list.id,
name: list.name,
createdAt: list.createdAt,
updatedAt: list.updatedAt,
_count: list._count,
},
}),
)
}
}