3ca4a11ca3
* 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
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { db } from '@/db/knex'
|
|
import { type UserNotificationRecord } from '@/modules/notifications/helpers/types'
|
|
import { NotificationType } from '@speckle/shared/notifications'
|
|
import { storeUserNotificationsFactory } from '@/modules/notifications/repositories/userNotification'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
import { assign } from 'lodash-es'
|
|
|
|
export const buildTestNotification = (
|
|
overrides?: Partial<UserNotificationRecord>
|
|
): UserNotificationRecord =>
|
|
assign(
|
|
{
|
|
id: cryptoRandomString({ length: 10 }),
|
|
userId: cryptoRandomString({ length: 10 }),
|
|
type: NotificationType.MentionedInComment,
|
|
version: '1',
|
|
read: false,
|
|
payload: {},
|
|
sendEmailAt: null,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
},
|
|
overrides
|
|
)
|
|
|
|
export const createTestNotification = async (
|
|
notification?: UserNotificationRecord
|
|
): Promise<UserNotificationRecord> => {
|
|
const storeUserNotifications = storeUserNotificationsFactory({ db })
|
|
|
|
const storeNotification = notification || buildTestNotification()
|
|
await storeUserNotifications([storeNotification])
|
|
|
|
return storeNotification
|
|
}
|