mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
188c6153d5
The assistant tables gave Users three more relations, and a spread of overrides checked against RequiredEntityData now ran tsc past its instantiation depth (TS2589). Every factory passes its overrides as createRow's own argument, the way rows.ts documents it.
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { NotificationChannelPreferences } from '../../../src/db/entities/NotificationChannelPreferences.entity';
|
|
import { Notifications } from '../../../src/db/entities/Notifications.entity';
|
|
import type { FactoryOrm } from './context';
|
|
import { createRow, upsertRow } from './rows';
|
|
import { setAppSetting } from './settings';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type NotificationRow = EntityDTO<Notifications>;
|
|
|
|
/** An unread in-app notification of the simple kind for `recipientId`. */
|
|
export function makeNotification(
|
|
orm: FactoryOrm,
|
|
recipientId: number,
|
|
overrides: EntityData<Notifications> = {},
|
|
): Promise<NotificationRow> {
|
|
return createRow(
|
|
orm,
|
|
Notifications,
|
|
{
|
|
recipient: recipientId,
|
|
type: 'simple',
|
|
scope: 'user',
|
|
target: recipientId,
|
|
title_key: 'notifications.test.title',
|
|
text_key: 'notifications.test.text',
|
|
is_read: 0,
|
|
},
|
|
overrides,
|
|
);
|
|
}
|
|
|
|
/** Sets the instance's active notification channels ('email', 'webhook', 'email,webhook', 'none'). */
|
|
export function setNotificationChannels(orm: FactoryOrm, channels: string): Promise<void> {
|
|
return setAppSetting(orm, 'notification_channels', channels);
|
|
}
|
|
|
|
/** Turns one event on one channel off for the user. */
|
|
export async function disableNotificationPref(
|
|
orm: FactoryOrm,
|
|
userId: number,
|
|
eventType: string,
|
|
channel: string,
|
|
): Promise<void> {
|
|
await upsertRow(orm, NotificationChannelPreferences, { user: userId, event_type: eventType, channel, enabled: 0 });
|
|
}
|