server/database/entities/Notification.ts
2024-04-11 01:39:07 -10:00

27 lines
960 B
TypeScript

import type { APINotification } from "~types/entities/notification";
import { type StatusWithRelations, statusToAPI } from "./Status";
import { type UserWithRelations, userToAPI } from "./User";
import type { InferSelectModel } from "drizzle-orm";
import type { notification } from "~drizzle/schema";
export type Notification = InferSelectModel<typeof notification>;
export type NotificationWithRelations = Notification & {
status: StatusWithRelations | null;
account: UserWithRelations;
};
export const notificationToAPI = async (
notification: NotificationWithRelations,
): Promise<APINotification> => {
return {
account: userToAPI(notification.account),
created_at: new Date(notification.createdAt).toISOString(),
id: notification.id,
type: notification.type,
status: notification.status
? await statusToAPI(notification.status, notification.account)
: undefined,
};
};