Skip to content

Commit 28b22cb

Browse files
committed
Add communityId to Slack notifications and update email sending function
1 parent 177affc commit 28b22cb

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/app/api/upsert/convo/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const sendWithRateLimit = async (
8181
// Helper function to send emails asynchronously without blocking the response
8282
const sendEmailsAsync = async (
8383
event: ServerEvent,
84+
community: { id: string }, // Add community parameter for slack notifications
8485
goingAttendees: (Rsvp & { attendee: User })[] = [],
8586
maybeAttendees: (Rsvp & { attendee: User })[] = [],
8687
isUpdate = false,
@@ -183,6 +184,7 @@ const sendEmailsAsync = async (
183184
eventId: event.id,
184185
host,
185186
type: isUpdate ? "updated" : "new", // "new" | "reminder" | "updated"
187+
communityId: community.id,
186188
});
187189

188190
console.log(
@@ -471,6 +473,7 @@ export async function POST(req: NextRequest) {
471473
// Error handling is now inside the sendEmailsAsync function
472474
void sendEmailsAsync(
473475
updated,
476+
community,
474477
goingAttendees,
475478
maybeAttendees,
476479
true,
@@ -636,9 +639,11 @@ export async function POST(req: NextRequest) {
636639
// Start sending emails asynchronously without awaiting
637640
// Don't await or use catch - start this fully asynchronously to improve response time
638641
// Fire and forget approach
639-
sendEmailsAsync(created, [], [], false, undefined, userId).catch((error) => {
640-
console.error("Background email sending failed:", error);
641-
});
642+
sendEmailsAsync(created, community, [], [], false, undefined, userId).catch(
643+
(error) => {
644+
console.error("Background email sending failed:", error);
645+
}
646+
);
642647

643648
// Queue reminder scheduling in parallel - fully asynchronous
644649
// This significantly improves API response time

src/lib/queue/slack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface SlackJobData {
66
eventId: string;
77
host: string;
88
type: "new" | "reminder" | "updated";
9+
communityId: string;
910
}
1011

1112
// Create the slack notification queue

src/lib/queue/workers/slack.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { slackQueue, type SlackJobData } from "../slack";
22
import { sendMessage } from "src/utils/slack/sendMessage";
33
import { prisma } from "src/utils/db";
4-
import { getCommunityFromSubdomain } from "src/utils/getCommunityFromSubdomain";
54

65
// Process a slack notification job
76
async function processSlackJob(job: { data: SlackJobData }): Promise<void> {
8-
const { eventId, host, type } = job.data;
7+
const { eventId, host, type, communityId } = job.data;
98

109
console.log(
11-
`Processing Slack notification job for event ${eventId} with type ${type}`
10+
`Processing Slack notification job for event ${eventId} with type ${type} in community ${communityId}`
1211
);
1312

1413
try {
15-
// Get the community for community-specific profiles
16-
const community = await getCommunityFromSubdomain();
17-
1814
// Fetch the event with all needed relationships
1915
const event = await prisma.event.findUnique({
2016
where: { id: eventId },
@@ -24,7 +20,7 @@ async function processSlackJob(job: { data: SlackJobData }): Promise<void> {
2420
user: {
2521
include: {
2622
profiles: {
27-
where: { communityId: community.id },
23+
where: { communityId },
2824
take: 1,
2925
},
3026
},
@@ -36,7 +32,7 @@ async function processSlackJob(job: { data: SlackJobData }): Promise<void> {
3632
attendee: {
3733
include: {
3834
profiles: {
39-
where: { communityId: community.id },
35+
where: { communityId },
4036
take: 1,
4137
},
4238
},

0 commit comments

Comments
 (0)