feat(ui): add collection and share link pages and management actions

This commit is contained in:
yiling
2026-06-06 12:02:51 +08:00
parent 0d76ddfc34
commit 6ebeb3f804
22 changed files with 2052 additions and 69 deletions
+9 -1
View File
@@ -52,6 +52,8 @@ describe('Collection API', () => {
projectId,
createdAt: new Date(),
updatedAt: new Date(),
creator: null,
creatorId: null,
})
const res = await app.request(`/projects/${projectId}/collections`, {
@@ -67,7 +69,7 @@ describe('Collection API', () => {
})
expect(res.status).toBe(200)
expect(mockCreate).toHaveBeenCalledWith(projectId, expect.any(Object))
expect(mockCreate).toHaveBeenCalledWith(projectId, expect.any(Object), 'user-1')
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: expect.any(Object),
permission: Permission.Edit,
@@ -90,6 +92,8 @@ describe('Collection API', () => {
projectId,
createdAt: new Date(),
updatedAt: new Date(),
creator: null,
creatorId: null,
},
],
pageInfo: { total: 1 },
@@ -121,6 +125,8 @@ describe('Collection API', () => {
projectId,
createdAt: new Date(),
updatedAt: new Date(),
creator: null,
creatorId: null,
})
const res = await app.request(`/collections/${collectionId}`)
@@ -147,6 +153,8 @@ describe('Collection API', () => {
projectId,
createdAt: new Date(),
updatedAt: new Date(),
creator: null,
creatorId: null,
})
const res = await app.request(`/collections/${collectionId}`, {
+7 -2
View File
@@ -13,7 +13,9 @@ import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>>
function toCollectionInfo(c: Prisma.CollectionGetPayload<Record<string, never>>): CollectionInfo {
function toCollectionInfo(
c: Prisma.CollectionGetPayload<{ include: { creator: true } }>,
): CollectionInfo {
return {
id: c.id,
name: c.name,
@@ -21,6 +23,9 @@ function toCollectionInfo(c: Prisma.CollectionGetPayload<Record<string, never>>)
projectId: c.projectId,
createdAt: c.createdAt.toISOString(),
updatedAt: c.updatedAt.toISOString(),
creator: c.creator
? { id: c.creator.id, name: c.creator.name, image: c.creator.image ?? undefined }
: null,
}
}
@@ -40,7 +45,7 @@ const route = new Hono<{ Variables: { user: User } }>()
id: projectId,
})
const collection = await collectionService.createCollection(projectId, req)
const collection = await collectionService.createCollection(projectId, req, user.id)
return c.json(toCollectionInfo(collection))
},
)
+1 -1
View File
@@ -139,7 +139,7 @@ describe('Share API', () => {
permission: Permission.Edit,
}),
)
expect(shareService.createShareLink).toHaveBeenCalledWith('project1', { name: 'My Share' })
expect(shareService.createShareLink).toHaveBeenCalledWith('project1', { name: 'My Share' }, 'user1')
})
})
+1 -1
View File
@@ -28,7 +28,7 @@ const route = new Hono<{ Variables: { user: User } }>()
id: projectId,
})
const shareLink = await shareService.createShareLink(projectId, req)
const shareLink = await shareService.createShareLink(projectId, req, user.id)
return c.json(shareLink)
},
)