feat(commission) : add push notifications and unread ticket titles
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { after } from "next/server";
|
||||
import { getDb } from "@/db";
|
||||
import { commissionMessages, commissionTickets } from "@/db/schema";
|
||||
import type { CommissionMessageEvent } from "@/lib/commission/message-event";
|
||||
import { sendCommissionMessagePush } from "@/lib/commission/push";
|
||||
import { notifyCommission } from "@/lib/commission/server";
|
||||
import { authorizeTicket } from "@/lib/commission/tickets";
|
||||
import { getMediaStorage } from "@/lib/media/storage";
|
||||
@@ -48,7 +51,15 @@ export async function POST(request: Request, context: RouteContext<"/api/commiss
|
||||
if (imageObjectKey) await (await getMediaStorage()).delete(imageObjectKey).catch(() => undefined);
|
||||
throw cause;
|
||||
}
|
||||
await notifyCommission(id, ticket.userId);
|
||||
const message: CommissionMessageEvent = { messageId, ticketId: id,
|
||||
ticketTitle: ticket.title || `Ticket #${id.slice(0, 8)}`,
|
||||
authorId: user.id, authorName: user.name, text: body || null };
|
||||
await notifyCommission(id, ticket.userId, `message:${JSON.stringify(message)}`);
|
||||
after(() => sendCommissionMessagePush({ id: messageId, ticketId: id,
|
||||
ticketTitle: message.ticketTitle, customerId: ticket.userId, authorId: user.id,
|
||||
authorName: user.name, text: body || null }).catch(() => {
|
||||
console.error("Commission push delivery failed");
|
||||
}));
|
||||
return Response.json({ ok: true, messageId }, { status: 201 });
|
||||
});
|
||||
} catch (cause) { return errorResponse(cause); }
|
||||
|
||||
Reference in New Issue
Block a user