feat(platform): checkpoint current implementation state

This commit is contained in:
2026-04-01 07:42:03 +02:00
parent 3e53471f05
commit 8c5be51251
125 changed files with 10269 additions and 17808 deletions
@@ -84,7 +84,10 @@ export function getNotificationErrorCandidates(error: unknown): Array<{
return candidates;
}
export function rethrowNotificationReferenceError(error: unknown): never {
export function rethrowNotificationReferenceError(
error: unknown,
recipientContext: "notification" | "task" | "broadcast" = "notification",
): never {
for (const candidate of getNotificationErrorCandidates(error)) {
const fieldName = typeof candidate.meta?.field_name === "string"
? candidate.meta.field_name.toLowerCase()
@@ -122,9 +125,14 @@ export function rethrowNotificationReferenceError(error: unknown): never {
&& (candidate.code === "P2003" || candidate.code === "P2025")
&& fieldName.includes("userid")
) {
const message = recipientContext === "broadcast"
? "Broadcast recipient user not found"
: recipientContext === "task"
? "Task recipient user not found"
: "Notification recipient user not found";
throw new TRPCError({
code: "NOT_FOUND",
message: "Broadcast recipient user not found",
message,
cause: error,
});
}
@@ -347,25 +355,32 @@ export async function createManagedNotification(
input: z.infer<typeof CreateManagedNotificationInputSchema>,
) {
const currentUserId = requireNotificationDbUser(ctx).id;
const isTaskLikeCategory = input.category === "TASK" || input.category === "APPROVAL";
const taskStatus = input.taskStatus ?? (isTaskLikeCategory ? "OPEN" : undefined);
const notificationId = await createNotification({
db: ctx.db,
userId: input.userId,
type: input.type,
title: input.title,
body: input.body,
entityId: input.entityId,
entityType: input.entityType,
category: input.category,
priority: input.priority,
link: input.link,
taskStatus: input.taskStatus,
taskAction: input.taskAction,
assigneeId: input.assigneeId,
dueDate: input.dueDate,
channel: input.channel,
senderId: input.senderId ?? currentUserId,
});
let notificationId: string;
try {
notificationId = await createNotification({
db: ctx.db,
userId: input.userId,
type: input.type,
title: input.title,
body: input.body,
entityId: input.entityId,
entityType: input.entityType,
category: input.category,
priority: input.priority,
link: input.link,
taskStatus,
taskAction: input.taskAction,
assigneeId: input.assigneeId,
dueDate: input.dueDate,
channel: input.channel,
senderId: input.senderId ?? currentUserId,
});
} catch (error) {
rethrowNotificationReferenceError(error, "notification");
}
if (input.category === "TASK" || input.category === "APPROVAL") {
emitTaskAssigned(input.userId, notificationId);