Skip to content

Commit

Permalink
Add: enroll notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bartosz-skejcik committed Jan 5, 2024
1 parent 7525b2b commit c4177dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/api/enroll/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export async function POST(request: Request) {
studentId: body.studentId,
};

const student = await prisma.student.findUnique({
where: {
userId: appointment.studentId,
},
include: {
user: true,
},
});

// studentId Int
// appointmentId String
// subject String
Expand Down Expand Up @@ -89,6 +98,16 @@ export async function POST(request: Request) {
},
});

if (student) {
await prisma.notification.create({
data: {
message: `${student.user.firstName} ${student.user.lastName} zapisał się na korepetycje z przedmiotu ${appointment.subject}`,
type: "appointment_enroll",
userId: appointment.teacherId,
},
});
}

return new NextResponse(
JSON.stringify({
message: "Pomyślnie zapisano na korepetycje",
Expand All @@ -110,6 +129,16 @@ export async function POST(request: Request) {
},
});

if (student) {
await prisma.notification.create({
data: {
message: `${student.user.firstName} ${student.user.lastName} zapisał się na korepetycje z przedmiotu ${appointment.subject}`,
type: "appointment_enroll",
userId: appointment.teacherId,
},
});
}

return new NextResponse(
JSON.stringify({
message: "Pomyślnie zapisano na korepetycje",
Expand Down
7 changes: 7 additions & 0 deletions components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Cog6ToothIcon,
TrashIcon,
UserMinusIcon,
UserPlusIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import Logo from "./Logo";
Expand Down Expand Up @@ -348,6 +349,12 @@ export function Sidebar({
className="h-8 w-8 text-neutral-500"
aria-hidden="true"
/>
) : notification.type ==
"appointment_enroll" ? (
<UserPlusIcon
className="h-8 w-8 text-neutral-500"
aria-hidden="true"
/>
) : (
<BellIcon
className="h-8 w-8 text-green-500"
Expand Down

0 comments on commit c4177dd

Please sign in to comment.