Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions actions/(announcements)/announcements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function sendAnnouncement(
const announcement = await prisma.announcements.findUnique({
where: { id: announcementId },
include: {
teams: {
team: {
include: {
team_members: {
include: {
Expand All @@ -51,7 +51,7 @@ export async function sendAnnouncement(
}

// Verify user is team leader
if (announcement.teams.leader_id !== leaderId) {
if (announcement.team.leader_id !== leaderId) {
return { success: false, error: "Unauthorized: Not team leader" };
}

Expand Down Expand Up @@ -85,7 +85,7 @@ export async function sendAnnouncement(
}

// Fetch team members
const recipients = announcement.teams.team_members.map((tm) => ({
const recipients = announcement.team.team_members.map((tm) => ({
email: tm.members.email,
name: tm.members.full_name || undefined,
}));
Expand All @@ -109,7 +109,7 @@ export async function sendAnnouncement(
recipients,
title: announcement.title,
content: announcement.content,
teamName: announcement.teams.name,
teamName: announcement.team.name,
});

// Store batch IDs (as JSON array if multiple batches)
Expand Down Expand Up @@ -177,15 +177,15 @@ export async function getAnnouncementStatus(announcementId: bigint) {
const announcement = await prisma.announcements.findUnique({
where: { id: announcementId },
include: {
teams: true,
team: true,
},
});

if (!announcement) {
return { success: false, error: "Announcement not found" };
}

if (announcement.teams.leader_id !== leaderId) {
if (announcement.team.leader_id !== leaderId) {
return { success: false, error: "Unauthorized" };
}

Expand Down
4 changes: 2 additions & 2 deletions actions/(announcements)/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ export async function deleteAnnouncement(announcementId: bigint) {
// Fetch announcement with team
const announcement = await prisma.announcements.findUnique({
where: { id: announcementId },
include: { teams: true },
include: { team: true },
});

if (!announcement) {
return { success: false, error: "Announcement not found" };
}

// Verify team ownership
if (announcement.teams.leader_id !== leaderId) {
if (announcement.team.leader_id !== leaderId) {
return { success: false, error: "Unauthorized: Not team leader" };
}

Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ model announcements {
error_message String?
recipient_count Int @default(0) @db.SmallInt
delivered_count Int @default(0) @db.SmallInt
teams teams @relation(fields: [team_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "announcements_team_id_fkey1")
team teams @relation(fields: [team_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "announcements_team_id_fkey1")

@@schema("public")
}
Expand Down
Loading