feat(platform): checkpoint current implementation state
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user