mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 03:57:58 +00:00
feat(notification): improve notification system with team settings and project-level toggles
This commit is contained in:
@@ -5,7 +5,9 @@ import { authzService, Permission, ResourceType } from '@/services/authz/authz'
|
||||
import {
|
||||
listNotificationsRequestSchema,
|
||||
markNotificationReadRequestSchema,
|
||||
notificationSettingsSchema,
|
||||
} from '@/dtos/notification'
|
||||
import { userMetadataService } from '@/services/user-metadata/user-metadata'
|
||||
import type { Prisma } from '@/generated/prisma/client'
|
||||
|
||||
type User = Prisma.UserGetPayload<Record<string, never>>
|
||||
@@ -62,5 +64,50 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
return new Response(null, { status: 204 })
|
||||
},
|
||||
)
|
||||
.get('/teams/:teamId/notifications/settings', async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const user = c.get('user')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const metadata = await userMetadataService.getMetadata(user.id, teamId, 'notification_settings')
|
||||
const settings = metadata
|
||||
? metadata.value
|
||||
: {
|
||||
comments: true,
|
||||
replies: true,
|
||||
mentions: true,
|
||||
yourUploads: false,
|
||||
otherUploads: true,
|
||||
statusUpdates: true,
|
||||
}
|
||||
|
||||
return c.json(settings)
|
||||
})
|
||||
.post(
|
||||
'/teams/:teamId/notifications/settings',
|
||||
zValidator('json', notificationSettingsSchema),
|
||||
async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const user = c.get('user')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
await userMetadataService.upsertMetadata(user.id, teamId, 'notification_settings', req)
|
||||
|
||||
return c.json({ success: true })
|
||||
},
|
||||
)
|
||||
|
||||
export default route
|
||||
|
||||
Reference in New Issue
Block a user