Files
speckle-server/packages/server/modules/notifications/graph/resolvers/userNotificationPreferences.ts
T
Daniel Gak Anagrov 3ca4a11ca3 feat(notifications): basic listener structure, notification record, delayed mechanism (#5432)
* feat: basic notification listener sturcuture

* feat: clean up generated gql

* chore: edited structure

* feat: added basic repo

* feat: ported comment email to job queue

* feat: ported stream access request accepted

* feat: added notification insertion

* fix: minor typings

* feat: delayed notifications

* updated types

* feat: fixed gql

* notifications are listed

* index on notifications

* feat: while loop skiping for update locked

* delayed notification for access request

* take into account user prefrences

* on comment view, notification is marked as read

* feat: added gql notifications

* feat: avoid raising errors

* fix: error added scopes

* fix: mr comments

* fix: cursor and service method

* feat: added stronger types to notifications and versioning logic

* minor: rows updated
2025-10-06 12:19:12 +01:00

45 lines
1.5 KiB
TypeScript

import { db } from '@/db/knex'
import type { Resolvers } from '@/modules/core/graph/generated/graphql'
import {
getSavedUserNotificationPreferencesFactory,
saveUserNotificationPreferencesFactory
} from '@/modules/notifications/repositories/userNotificationPreferences'
import {
getUserNotificationPreferencesFactory,
updateNotificationPreferencesFactory
} from '@/modules/notifications/services/notificationPreferences'
import { withOperationLogging } from '@/observability/domain/businessLogging'
const getUserNotificationPreferences = getUserNotificationPreferencesFactory({
getSavedUserNotificationPreferences: getSavedUserNotificationPreferencesFactory({
db
})
})
const updateNotificationPreferences = updateNotificationPreferencesFactory({
saveUserNotificationPreferences: saveUserNotificationPreferencesFactory({ db })
})
export default {
User: {
async notificationPreferences(parent) {
const preferences = await getUserNotificationPreferences(parent.id)
return preferences
}
},
Mutation: {
async userNotificationPreferencesUpdate(_parent, args, context) {
const logger = context.log
await withOperationLogging(
async () => updateNotificationPreferences(context.userId!, args.preferences),
{
logger,
operationName: 'userNotificationPreferencesUpdate',
operationDescription: 'Update user notification preferences'
}
)
return true
}
}
} as Resolvers