Skip to content
Snippets Groups Projects
Commit ed47bfee authored by Aaron Dötsch's avatar Aaron Dötsch
Browse files

Increase type specitifity in notification handler

parent f57464df
No related branches found
No related tags found
No related merge requests found
import { db } from "$lib/server/database"; import { db } from "$lib/server/database";
import { ChannelType } from "./channelTypes"; import { ChannelType } from "./channelTypes";
import type { HandlerReturnType, NotificationChannel, NotificationData, NotificationType, PossibleNotificationType } from "../../notifications/types"; import type { HandlerReturnError, HandlerReturnIgnored, HandlerReturnType, NotificationChannel, NotificationData, NotificationType, PossibleNotificationType } from "../../notifications/types";
export async function sendNotification<T extends PossibleNotificationType>(user: { id: number, notificationChannels: NotificationChannel[] | undefined } | number, type: NotificationType<T>, data: NotificationData<T>): Promise<HandlerReturnType[]>{ export async function sendNotification<T extends PossibleNotificationType>(user: { id: number, notificationChannels: NotificationChannel[] | undefined } | number, type: NotificationType<T>, data: NotificationData<T>): Promise<HandlerReturnType[]>{
let notificationChannels: NotificationChannel[]; let notificationChannels: NotificationChannel[];
...@@ -23,7 +23,7 @@ export async function sendNotification<T extends PossibleNotificationType>(user: ...@@ -23,7 +23,7 @@ export async function sendNotification<T extends PossibleNotificationType>(user:
status: "error", status: "error",
channel, channel,
error: err error: err
} as HandlerReturnType; } as HandlerReturnError;
}); });
} }
case ChannelType.WEBHOOK.key: { case ChannelType.WEBHOOK.key: {
...@@ -33,7 +33,7 @@ export async function sendNotification<T extends PossibleNotificationType>(user: ...@@ -33,7 +33,7 @@ export async function sendNotification<T extends PossibleNotificationType>(user:
status: "error", status: "error",
channel, channel,
error: err error: err
} as HandlerReturnType; } as HandlerReturnError;
}); });
} }
default: { default: {
...@@ -41,7 +41,7 @@ export async function sendNotification<T extends PossibleNotificationType>(user: ...@@ -41,7 +41,7 @@ export async function sendNotification<T extends PossibleNotificationType>(user:
return { return {
status: "ignored", status: "ignored",
channel channel
} as HandlerReturnType; } as HandlerReturnIgnored;
} }
}; };
})); }));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment