Merge pull request #285 from emrysal/bugfix/throw-404-when-eventType-missing

pull/288/head
Bailey Pumfleet 2021-06-18 23:35:42 +01:00 committed by GitHub
commit 440bee0a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 38 deletions

View File

@ -370,50 +370,52 @@ export default function Type(props) {
}
export async function getServerSideProps(context) {
const user = await prisma.user.findFirst({
where: {
username: context.query.user,
},
select: {
id: true,
username: true,
name: true,
email: true,
bio: true,
avatar: true,
eventTypes: true,
startTime: true,
timeZone: true,
endTime: true,
weekStart: true,
}
});
if (!user) {
return {
notFound: true,
}
const user = await prisma.user.findFirst({
where: {
username: context.query.user,
},
select: {
id: true,
username: true,
name: true,
email: true,
bio: true,
avatar: true,
eventTypes: true,
startTime: true,
timeZone: true,
endTime: true,
weekStart: true,
}
});
if (user) {
const eventType = await prisma.eventType.findFirst({
where: {
userId: user.id,
slug: {
equals: context.query.type,
},
where: {
userId: user.id,
slug: {
equals: context.query.type,
},
select: {
id: true,
title: true,
description: true,
length: true
}
},
select: {
id: true,
title: true,
description: true,
length: true
}
});
}
if (!user || !eventType) {
return {
props: {
user,
eventType,
},
notFound: true,
}
}
return {
props: {
user,
eventType,
},
}
}