Skip to content

Commit

Permalink
asdasdsad
Browse files Browse the repository at this point in the history
  • Loading branch information
bartosz-skejcik committed Dec 6, 2023
1 parent 3583170 commit 61bd630
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
67 changes: 41 additions & 26 deletions app/api/appointments/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,53 @@ function calculateRecurringDates(
}

export async function GET() {
const appointments = await prisma.appointment.findMany({
include: {
subject: true,
teacher: {
select: {
user: true,
try {
const appointments = await prisma.appointment.findMany({
include: {
subject: true,
teacher: {
select: {
user: true,
},
},
},
location: true,
studentAppointments: {
select: {
student: {
select: {
user: true,
location: true,
studentAppointments: {
select: {
student: {
select: {
user: true,
},
},
},
},
},
},
});
});

return new NextResponse(
JSON.stringify({
appointments,
}),
{
status: 200,
headers: {
"Content-Type": "application/json",
},
}
);
return new NextResponse(
JSON.stringify({
appointments,
}),
{
status: 200,
headers: {
"Content-Type": "application/json",
},
}
);
} catch (e: any) {
return new NextResponse(
JSON.stringify({
message: e.message,
error: e,
}),
{
status: 400,
headers: {
"Content-Type": "application/json",
},
}
);
}
}

export async function POST(request: Request) {
Expand Down
18 changes: 11 additions & 7 deletions app/api/locations/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { prisma } from "@/prisma/client";
import { NextResponse } from "next/server";

export async function GET(request: Request) {
const locations = await prisma.location.findMany();
try {
const locations = await prisma.location.findMany();

return new NextResponse(JSON.stringify(locations), {
status: 200,
headers: {
"content-type": "application/json",
},
});
return new NextResponse(JSON.stringify(locations), {
status: 200,
headers: {
"content-type": "application/json",
},
});
} catch (error) {
console.log(error);
}
}

0 comments on commit 61bd630

Please sign in to comment.